Update Prisma. Bugfix: set user correct in non identified devices
This commit is contained in:
parent
412c8f2ae6
commit
31d067f99d
13
pti.code-workspace
Normal file
13
pti.code-workspace
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "web"
|
||||
},
|
||||
{
|
||||
"path": "server"
|
||||
},
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
]
|
||||
}
|
68
server/package-lock.json
generated
68
server/package-lock.json
generated
|
@ -10,7 +10,7 @@
|
|||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@babel/polyfill": "^7.12.1",
|
||||
"@prisma/client": "^2.11.0",
|
||||
"@prisma/client": "^2.12.1",
|
||||
"activedirectory2": "^2.1.0",
|
||||
"apollo-server": "^2.19.0",
|
||||
"apollo-server-plugin-response-cache": "^0.5.6",
|
||||
|
@ -32,7 +32,7 @@
|
|||
"@babel/node": "^7.0.0",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
|
||||
"@babel/preset-env": "^7.0.0",
|
||||
"@prisma/cli": "^2.11.0",
|
||||
"@prisma/cli": "^2.12.1",
|
||||
"nodemon": "^2.0.6"
|
||||
}
|
||||
},
|
||||
|
@ -2286,33 +2286,33 @@
|
|||
"devOptional": true
|
||||
},
|
||||
"node_modules/@prisma/cli": {
|
||||
"version": "2.11.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.11.0.tgz",
|
||||
"integrity": "sha512-RphW+1SPrEKgpuE5RFM0mv3BeVTF8MCRIyBt35Z9Z/E4YI30qgEWfZu6VfsNDarHRsFiJRKC73wx/aMQ2rLp4g==",
|
||||
"version": "2.12.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.12.1.tgz",
|
||||
"integrity": "sha512-obkwK95dEeifCdVehG0rS0BlPQGLsOtc9U1MgbrjNX3MnhXQdwROnvymfPB3DBlNyoLoHGklPgi9UlwBokNXcQ==",
|
||||
"devOptional": true,
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@prisma/bar": "0.0.1",
|
||||
"@prisma/engines": "2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918"
|
||||
"@prisma/bar": "^0.0.1",
|
||||
"@prisma/engines": "2.12.0-18.cf0680a1bfe8d5e743dc659cc7f08009f9587d58"
|
||||
},
|
||||
"bin": {
|
||||
"prisma": "build/index.js",
|
||||
"prisma2": "build/index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
"node": ">=10.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@prisma/client": {
|
||||
"version": "2.11.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.11.0.tgz",
|
||||
"integrity": "sha512-BF7K/yi5fAnrt7MelQqUueJyl06IGmIxf+7f5RxFSvyO6xZMbOYxhW21kV2wt10mOIS0khQbo0xY6w/8jViJuQ==",
|
||||
"version": "2.12.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.12.1.tgz",
|
||||
"integrity": "sha512-HP4/E9sRdxw/FB7XP4EeRa5ri8Lp1U/L7G4VAA95aM8C+8ARioQHMNDpEjC83NrOrOr4EcaZV5pXDDQL1H+F0g==",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@prisma/engines-version": "2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918"
|
||||
"@prisma/engines-version": "2.12.0-18.cf0680a1bfe8d5e743dc659cc7f08009f9587d58"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
"node": ">=10.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@prisma/cli": "*"
|
||||
|
@ -2324,16 +2324,16 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@prisma/engines": {
|
||||
"version": "2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918.tgz",
|
||||
"integrity": "sha512-0WaUybWM7J5zQuG/zYLbV+ZKx9/nzS7Ruu7Y0K2lXJKy3Z9koeVttq+Xt7tVmUX9TLgI1Rwhb9R2e1JMNDWbsw==",
|
||||
"version": "2.12.0-18.cf0680a1bfe8d5e743dc659cc7f08009f9587d58",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-2.12.0-18.cf0680a1bfe8d5e743dc659cc7f08009f9587d58.tgz",
|
||||
"integrity": "sha512-F6RmUZ5JpPWxmGvVDji8c4gepHIGkvYbtuFi0IoDDJVaCVo8yS656stciKFyswI6/BLWXa0X47/MIMbz6nzw7g==",
|
||||
"devOptional": true,
|
||||
"hasInstallScript": true
|
||||
},
|
||||
"node_modules/@prisma/engines-version": {
|
||||
"version": "2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918.tgz",
|
||||
"integrity": "sha512-qlkW4dKoW1dUnperWPuhFriZ/NTHlsKLhBbebxRa8qMuD3o37SvWIDGLjFOQx1N0Eb4H04rI3XxgjkWLFVlZCw=="
|
||||
"version": "2.12.0-18.cf0680a1bfe8d5e743dc659cc7f08009f9587d58",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-2.12.0-18.cf0680a1bfe8d5e743dc659cc7f08009f9587d58.tgz",
|
||||
"integrity": "sha512-IHb/Jag1Wmoq5tLZhOHP5zqLHEXqQEfrHb6l0drIBSvh2AF7yWQ3yyuD0ZEb1Nq37SvbBgop5wrWMOU8YWFTGQ=="
|
||||
},
|
||||
"node_modules/@protobufjs/aspromise": {
|
||||
"version": "1.1.2",
|
||||
|
@ -10741,33 +10741,33 @@
|
|||
"devOptional": true
|
||||
},
|
||||
"@prisma/cli": {
|
||||
"version": "2.11.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.11.0.tgz",
|
||||
"integrity": "sha512-RphW+1SPrEKgpuE5RFM0mv3BeVTF8MCRIyBt35Z9Z/E4YI30qgEWfZu6VfsNDarHRsFiJRKC73wx/aMQ2rLp4g==",
|
||||
"version": "2.12.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.12.1.tgz",
|
||||
"integrity": "sha512-obkwK95dEeifCdVehG0rS0BlPQGLsOtc9U1MgbrjNX3MnhXQdwROnvymfPB3DBlNyoLoHGklPgi9UlwBokNXcQ==",
|
||||
"devOptional": true,
|
||||
"requires": {
|
||||
"@prisma/bar": "0.0.1",
|
||||
"@prisma/engines": "2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918"
|
||||
"@prisma/bar": "^0.0.1",
|
||||
"@prisma/engines": "2.12.0-18.cf0680a1bfe8d5e743dc659cc7f08009f9587d58"
|
||||
}
|
||||
},
|
||||
"@prisma/client": {
|
||||
"version": "2.11.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.11.0.tgz",
|
||||
"integrity": "sha512-BF7K/yi5fAnrt7MelQqUueJyl06IGmIxf+7f5RxFSvyO6xZMbOYxhW21kV2wt10mOIS0khQbo0xY6w/8jViJuQ==",
|
||||
"version": "2.12.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.12.1.tgz",
|
||||
"integrity": "sha512-HP4/E9sRdxw/FB7XP4EeRa5ri8Lp1U/L7G4VAA95aM8C+8ARioQHMNDpEjC83NrOrOr4EcaZV5pXDDQL1H+F0g==",
|
||||
"requires": {
|
||||
"@prisma/engines-version": "2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918"
|
||||
"@prisma/engines-version": "2.12.0-18.cf0680a1bfe8d5e743dc659cc7f08009f9587d58"
|
||||
}
|
||||
},
|
||||
"@prisma/engines": {
|
||||
"version": "2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918.tgz",
|
||||
"integrity": "sha512-0WaUybWM7J5zQuG/zYLbV+ZKx9/nzS7Ruu7Y0K2lXJKy3Z9koeVttq+Xt7tVmUX9TLgI1Rwhb9R2e1JMNDWbsw==",
|
||||
"version": "2.12.0-18.cf0680a1bfe8d5e743dc659cc7f08009f9587d58",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-2.12.0-18.cf0680a1bfe8d5e743dc659cc7f08009f9587d58.tgz",
|
||||
"integrity": "sha512-F6RmUZ5JpPWxmGvVDji8c4gepHIGkvYbtuFi0IoDDJVaCVo8yS656stciKFyswI6/BLWXa0X47/MIMbz6nzw7g==",
|
||||
"devOptional": true
|
||||
},
|
||||
"@prisma/engines-version": {
|
||||
"version": "2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918.tgz",
|
||||
"integrity": "sha512-qlkW4dKoW1dUnperWPuhFriZ/NTHlsKLhBbebxRa8qMuD3o37SvWIDGLjFOQx1N0Eb4H04rI3XxgjkWLFVlZCw=="
|
||||
"version": "2.12.0-18.cf0680a1bfe8d5e743dc659cc7f08009f9587d58",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-2.12.0-18.cf0680a1bfe8d5e743dc659cc7f08009f9587d58.tgz",
|
||||
"integrity": "sha512-IHb/Jag1Wmoq5tLZhOHP5zqLHEXqQEfrHb6l0drIBSvh2AF7yWQ3yyuD0ZEb1Nq37SvbBgop5wrWMOU8YWFTGQ=="
|
||||
},
|
||||
"@protobufjs/aspromise": {
|
||||
"version": "1.1.2",
|
||||
|
|
|
@ -30,12 +30,12 @@
|
|||
"@babel/node": "^7.0.0",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
|
||||
"@babel/preset-env": "^7.0.0",
|
||||
"@prisma/cli": "^2.11.0",
|
||||
"@prisma/cli": "^2.12.1",
|
||||
"nodemon": "^2.0.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/polyfill": "^7.12.1",
|
||||
"@prisma/client": "^2.11.0",
|
||||
"@prisma/client": "^2.12.1",
|
||||
"activedirectory2": "^2.1.0",
|
||||
"apollo-server": "^2.19.0",
|
||||
"apollo-server-plugin-response-cache": "^0.5.6",
|
||||
|
|
|
@ -82,7 +82,7 @@ class ResetToken {
|
|||
}
|
||||
|
||||
const user = await prisma.resetToken
|
||||
.findOne({
|
||||
.findUnique({
|
||||
where: { id: resetToken.id }
|
||||
})
|
||||
.user()
|
||||
|
|
|
@ -17,7 +17,7 @@ class User {
|
|||
*/
|
||||
async init() {
|
||||
try {
|
||||
let user = await prisma.user.findOne({
|
||||
let user = await prisma.user.findUnique({
|
||||
where: { sAMAccountName: this.username }
|
||||
})
|
||||
|
||||
|
|
|
@ -91,12 +91,19 @@ const Query = {
|
|||
}
|
||||
},
|
||||
|
||||
wifiDevices: async (_, { identifiedOnly }) => {
|
||||
wifiDevices: async (_, { identifiedOnly, nonIdentifiedOnly }) => {
|
||||
if (identifiedOnly && nonIdentifiedOnly)
|
||||
throw new Error('Invalid combination of filters')
|
||||
|
||||
updateDBWithOnlineDevices()
|
||||
|
||||
return prisma.wifiDevice.findMany({
|
||||
orderBy: [{ lastSeen: 'desc' }],
|
||||
where: identifiedOnly ? { NOT: { userId: null } } : {},
|
||||
where: identifiedOnly
|
||||
? { NOT: { userId: null } }
|
||||
: nonIdentifiedOnly
|
||||
? { userId: null }
|
||||
: {},
|
||||
include: { user: true }
|
||||
})
|
||||
},
|
||||
|
|
|
@ -2,10 +2,10 @@ import prisma from '../prisma'
|
|||
|
||||
const ResetToken = {
|
||||
creator(_) {
|
||||
return prisma.resetToken.findOne({ where: { id: _.id } }).creator()
|
||||
return prisma.resetToken.findUnique({ where: { id: _.id } }).creator()
|
||||
},
|
||||
user(_) {
|
||||
return prisma.resetToken.findOne({ where: { id: _.id } }).user()
|
||||
return prisma.resetToken.findUnique({ where: { id: _.id } }).user()
|
||||
},
|
||||
expiration: _ => _.expiration.toISOString(),
|
||||
createdAt: _ => _.createdAt.toISOString()
|
||||
|
|
|
@ -39,7 +39,7 @@ const User = {
|
|||
return []
|
||||
|
||||
return prisma.user
|
||||
.findOne({
|
||||
.findUnique({
|
||||
where: {
|
||||
sAMAccountName: _.sAMAccountName
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@ const typeDefs = gql`
|
|||
|
||||
wifiDevices(
|
||||
search: String = ""
|
||||
identifiedOnly: Boolean = true
|
||||
identifiedOnly: Boolean = false
|
||||
nonIdentifiedOnly: Boolean = false
|
||||
): [WifiDevice]!
|
||||
|
||||
userPresence(search: String = ""): [UserPresence!] @auth(roles: ["watcher"])
|
||||
|
|
|
@ -46,7 +46,7 @@ export async function getOnlineWifiDevices() {
|
|||
const onlineDevices = await getDevices()
|
||||
|
||||
const hydratedOnlineDevices = onlineDevices.map(client => ({
|
||||
user: client.Name == 'unknown' ? undefined : client.Name,
|
||||
user: client.Name == 'unknown' ? null : client.Name,
|
||||
oui: ouiFinder(client.macaddr),
|
||||
mac: client.macaddr,
|
||||
hostname: client.HN == 'unknown' ? undefined : client.HN,
|
||||
|
|
|
@ -29,22 +29,33 @@ async function updateDBWithOnlineDevices() {
|
|||
|
||||
const onlineDevices = [...onlineUnifiDevices, ...onlineCiscoDevices]
|
||||
|
||||
for (const onlineDevice of onlineDevices) {
|
||||
const device = {
|
||||
...onlineDevice,
|
||||
user: onlineDevice.user
|
||||
? { connect: { sAMAccountName: onlineDevice.user } }
|
||||
: undefined
|
||||
}
|
||||
for (const device of onlineDevices) {
|
||||
if (!device.user)
|
||||
await prisma.$executeRaw(
|
||||
'UPDATE "WifiDevice" SET "userId" = null WHERE mac = $1',
|
||||
device.mac
|
||||
)
|
||||
|
||||
try {
|
||||
await prisma.wifiDevice.upsert({
|
||||
where: { mac: onlineDevice.mac },
|
||||
create: { ...device, firstSeen: device.firstSeen || new Date() },
|
||||
update: device
|
||||
where: { mac: device.mac },
|
||||
create: {
|
||||
...device,
|
||||
firstSeen: device.firstSeen || new Date(),
|
||||
user: device.user
|
||||
? { connect: { sAMAccountName: device.user } }
|
||||
: undefined
|
||||
},
|
||||
update: {
|
||||
...device,
|
||||
user: device.user
|
||||
? { connect: { sAMAccountName: device.user } }
|
||||
: undefined
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
if (e.code != 'P2016') console.log('[wifiDevice upsert error]', e)
|
||||
if (!['P2016'].includes(e.code))
|
||||
console.log('[wifiDevice upsert error]', e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,44 +1,78 @@
|
|||
<template>
|
||||
<v-container fluid>
|
||||
<div v-if="$apollo.queries.wifiDevices.loading">
|
||||
Carregando informações...
|
||||
</div>
|
||||
<v-data-table
|
||||
v-if="!$apollo.queries.wifiDevices.loading"
|
||||
:headers="headers"
|
||||
:items="items"
|
||||
:options="{ itemsPerPage: 15 }"
|
||||
<v-data-iterator
|
||||
:items="computedWifiDevices"
|
||||
:items-per-page.sync="itemsPerPage"
|
||||
:page="page"
|
||||
>
|
||||
</v-data-table>
|
||||
<template #header>
|
||||
<v-toolbar flat>
|
||||
Dispositivos Wi-Fi
|
||||
<v-spacer />
|
||||
<v-btn
|
||||
:loading="$apollo.queries.wifiDevices.loading"
|
||||
color="primary"
|
||||
text
|
||||
@click="$apollo.queries.wifiDevices.refresh()"
|
||||
>
|
||||
<v-icon left>mdi-refresh</v-icon> Atualizar
|
||||
</v-btn>
|
||||
</v-toolbar>
|
||||
</template>
|
||||
<template #default="{ items }">
|
||||
<v-row>
|
||||
<v-col
|
||||
v-for="item in items"
|
||||
:key="item.mac"
|
||||
cols="12"
|
||||
md="4"
|
||||
class="grow"
|
||||
>
|
||||
<v-card>
|
||||
<v-card-text>
|
||||
<Avatar :src="item.user.thumbnailPhoto" />
|
||||
<p>
|
||||
{{ item.user.displayName }}
|
||||
</p>
|
||||
<p>
|
||||
{{ item.essid }}
|
||||
</p>
|
||||
{{ item.status }}
|
||||
{{ item.mac }}
|
||||
{{ item.ip }}
|
||||
{{ item.controller }}
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</template>
|
||||
<template #footer> Footer </template>
|
||||
</v-data-iterator>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import gql from 'graphql-tag'
|
||||
import Avatar from '../components/Avatar.vue'
|
||||
|
||||
export default {
|
||||
name: 'WifiDevices',
|
||||
components: { Avatar },
|
||||
data: () => ({
|
||||
headers: [
|
||||
// { text: 'Hostname', value: 'hostname' },
|
||||
{ text: 'Usuário', value: 'user' },
|
||||
{ text: 'OUI', value: 'oui' },
|
||||
{ text: 'AP', value: 'apName' },
|
||||
{ text: 'Controladora', value: 'controller' },
|
||||
{ text: 'SSID', value: 'essid' },
|
||||
{ text: 'Status', value: 'status' },
|
||||
{ text: 'Endereço MAC', value: 'mac' }
|
||||
]
|
||||
itemsPerPage: 6,
|
||||
itemsPerPageArray: [15, 30, 60, 120],
|
||||
page: 1
|
||||
}),
|
||||
apollo: {
|
||||
wifiDevices: {
|
||||
fetchPolicy: 'cache-and-network',
|
||||
query: gql`
|
||||
query {
|
||||
wifiDevices {
|
||||
wifiDevices(nonIdentifiedOnly: true) {
|
||||
user {
|
||||
displayName
|
||||
sAMAccountName
|
||||
thumbnailPhoto
|
||||
}
|
||||
oui
|
||||
mac
|
||||
|
@ -57,11 +91,15 @@ export default {
|
|||
}
|
||||
},
|
||||
computed: {
|
||||
items() {
|
||||
computedWifiDevices() {
|
||||
return this.wifiDevices?.map(device => ({
|
||||
...device,
|
||||
hostname: device.hostname || 'Desconhecido',
|
||||
user: device.user.displayName
|
||||
user: device.user || {
|
||||
displayName: 'Não identificado',
|
||||
sAMAccountName: null,
|
||||
thumbnailPhoto: null
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user