Added PA host owner
This commit is contained in:
parent
c13239e9d8
commit
f47c2f10a0
|
@ -127,7 +127,7 @@ function decryptKey(encryptedKey) {
|
|||
return AES.decrypt(encryptedKey, process.env.CRYPT_SECRET).toString(enc.Utf8)
|
||||
}
|
||||
|
||||
async function addHost({ cidr, user, password, description, note }) {
|
||||
async function addHost({ cidr, user, password, description, note, owner }) {
|
||||
if (!CIDR_RE.test(cidr)) throw new Error('Este não é um CIDR válido')
|
||||
|
||||
const ipAddr = cidr.split('/')[0]
|
||||
|
@ -152,7 +152,12 @@ async function addHost({ cidr, user, password, description, note }) {
|
|||
encryptedKey,
|
||||
user,
|
||||
description,
|
||||
note
|
||||
note,
|
||||
owner: {
|
||||
connect: {
|
||||
sAMAccountName: owner.sAMAccountName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const host = id
|
||||
|
|
|
@ -53,7 +53,14 @@ const Mutation = {
|
|||
{ data: { cidr, user, password, description, note } },
|
||||
{ auth }
|
||||
) {
|
||||
const host = await addHost({ cidr, user, password, description, note })
|
||||
const host = await addHost({
|
||||
cidr,
|
||||
user,
|
||||
password,
|
||||
description,
|
||||
note,
|
||||
owner: auth
|
||||
})
|
||||
|
||||
if (host)
|
||||
logSuccess({
|
||||
|
@ -64,7 +71,12 @@ const Mutation = {
|
|||
return host
|
||||
},
|
||||
|
||||
async delPAHost(_, { id }) {
|
||||
async delPAHost(_, { id }, { auth }) {
|
||||
const host = await prisma.pAHost.findUnique({ where: { id } })
|
||||
|
||||
if (host.ownerId != auth.id)
|
||||
throw new Error('Você não pode apagar o host de outro usuário')
|
||||
|
||||
return prisma.pAHost.delete({ where: { id } })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { decryptKey } from '../lib/paloalto'
|
||||
import prisma from '../prisma'
|
||||
|
||||
const PAHost = {
|
||||
key: parent => `${decryptKey(parent.encryptedKey).slice(0, 5)}*****`
|
||||
key: parent => `${decryptKey(parent.encryptedKey).slice(0, 5)}*****`,
|
||||
owner: parent => prisma.user.findUnique({ where: { id: parent.ownerId } })
|
||||
}
|
||||
|
||||
export { PAHost }
|
||||
|
|
|
@ -275,6 +275,8 @@ const typeDefs = gql`
|
|||
note: String
|
||||
"The API key owner"
|
||||
user: String
|
||||
"The user who added the host"
|
||||
owner: User!
|
||||
|
||||
createdAt: String
|
||||
updatedAt: String
|
||||
|
|
|
@ -57,12 +57,17 @@
|
|||
</v-list>
|
||||
<v-card-text>
|
||||
{{ pAHost.note || 'Sem observações' }}
|
||||
<v-divider />
|
||||
<small>Adicionado por: {{ pAHost.owner.displayName }}</small>
|
||||
</v-card-text>
|
||||
|
||||
<v-card-actions>
|
||||
<v-spacer />
|
||||
|
||||
<v-dialog max-width="600">
|
||||
<v-dialog
|
||||
v-if="me.sAMAccountName == pAHost.owner.sAMAccountName"
|
||||
max-width="600"
|
||||
>
|
||||
<template #activator="{ on, attrs }">
|
||||
<v-btn icon v-bind="attrs" v-on="on">
|
||||
<v-icon>mdi-trash-can</v-icon>
|
||||
|
@ -129,6 +134,11 @@ const PAHOSTS_QUERY = gql`
|
|||
user
|
||||
createdAt
|
||||
updatedAt
|
||||
owner {
|
||||
id
|
||||
sAMAccountName
|
||||
displayName
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
@ -159,7 +169,14 @@ export default {
|
|||
addDialog: false
|
||||
}),
|
||||
apollo: {
|
||||
pAHosts: { query: PAHOSTS_QUERY, fetchPolicy: 'network-only' }
|
||||
pAHosts: { query: PAHOSTS_QUERY, fetchPolicy: 'network-only' },
|
||||
me: gql`
|
||||
{
|
||||
me {
|
||||
sAMAccountName
|
||||
}
|
||||
}
|
||||
`
|
||||
},
|
||||
methods: {
|
||||
async delHost(id) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user