Added campus verification

This commit is contained in:
Douglas Barone 2022-04-20 09:06:54 -04:00
parent 3e05b12698
commit 01e0a30321
10 changed files with 35 additions and 15 deletions

View File

@ -1,12 +1,12 @@
{ {
"name": "ifms-pti-svr", "name": "ifms-pti-svr",
"version": "2.13.1", "version": "2.13.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "ifms-pti-svr", "name": "ifms-pti-svr",
"version": "2.13.1", "version": "2.13.2",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@prisma/client": "^3.11.0", "@prisma/client": "^3.11.0",

View File

@ -1,6 +1,6 @@
{ {
"name": "ifms-pti-svr", "name": "ifms-pti-svr",
"version": "2.13.1", "version": "2.13.2",
"description": "Servidor do Portal de TI do IFMS", "description": "Servidor do Portal de TI do IFMS",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {

View File

@ -2,6 +2,7 @@
import prisma from '../../prisma' import prisma from '../../prisma'
import { ACCESS_POINTS_UPDATED, pubsub } from '../../pubsub' import { ACCESS_POINTS_UPDATED, pubsub } from '../../pubsub'
import { logInfo } from '../../lib/logger' import { logInfo } from '../../lib/logger'
import { getSubnetInfo } from '../../utils/subnetInfo'
export async function updateAccessPoint( export async function updateAccessPoint(
parent, parent,
@ -11,15 +12,20 @@ export async function updateAccessPoint(
) { ) {
const accessPoint = await prisma.accessPoint.update({ const accessPoint = await prisma.accessPoint.findUnique({ where: { id: parseInt(id) }, })
if (getSubnetInfo(accessPoint.ip).shortName !== auth.campus)
throw new Error(`O AP ${accessPoint.name || accessPoint.hostname} não está na rede do campus ${auth.campus}. Você só pode editar APs da rede do seu campus.`)
const updatedAccessPoint = await prisma.accessPoint.update({
where: { id: parseInt(id) }, where: { id: parseInt(id) },
data: { name, local, notes } data: { name, local, notes }
}) })
logInfo({ logInfo({
tags: ['accessPointEdited', 'accessPoints'], tags: ['accessPointEdited', 'accessPoints'],
message: `O usuário ${auth.displayName} (${auth.sAMAccountName}) atualizou as informações do AP ${accessPoint.name || accessPoint.hostname}`, message: `O usuário ${auth.displayName} (${auth.sAMAccountName}) atualizou as informações do AP ${updatedAccessPoint.name || updatedAccessPoint.hostname}`,
data: accessPoint data: updatedAccessPoint
}) })
const accessPoints = await prisma.accessPoint.findMany({ const accessPoints = await prisma.accessPoint.findMany({
@ -30,5 +36,5 @@ export async function updateAccessPoint(
accessPointsUpdated: accessPoints accessPointsUpdated: accessPoints
}) })
return accessPoint return updatedAccessPoint
} }

View File

@ -20,15 +20,15 @@ const User = {
sharedFolders: parent => sharedFolders: parent =>
parent.groups parent.groups
? parent.groups ? parent.groups
.filter(group => group.cn.includes('-Share-')) .filter(group => group.cn.includes('-Share-'))
.map(group => group.cn.split('-')[2]) .map(group => group.cn.split('-')[2])
: [], : [],
sharedPrinters: parent => sharedPrinters: parent =>
parent.groups parent.groups
? parent.groups ? parent.groups
.filter(group => group.cn.includes('-Printer-')) .filter(group => group.cn.includes('-Printer-'))
.map(group => group.cn.split('-')[2]) .map(group => group.cn.split('-')[2])
: [], : [],
isSuperAdmin: parent => parent.roles.includes('superAdmin'), isSuperAdmin: parent => parent.roles.includes('superAdmin'),
@ -55,6 +55,12 @@ const User = {
} }
}) })
.wifiDevices() .wifiDevices()
},
campus: parent => {
const campus = parent.extensionAttribute1?.split('-')[0]
return campus || '--'
} }
} }

View File

@ -23,7 +23,10 @@ class AuthDirective extends SchemaDirectiveVisitor {
const user = await new User(sAMAccountName).init() const user = await new User(sAMAccountName).init()
context.auth = user context.auth = {
...user,
campus: user.extensionAttribute1?.split('-')[0] || '--',
}
if (user.pwdLastSet.toISOString() === pwdLastSet) { if (user.pwdLastSet.toISOString() === pwdLastSet) {
if ( if (

View File

@ -125,6 +125,7 @@ const typeDefs = gql`
groups: [Group!] groups: [Group!]
sharedFolders: [String!] sharedFolders: [String!]
sharedPrinters: [String!] sharedPrinters: [String!]
campus: String
firstName: String firstName: String

4
web/package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "ifms-pti", "name": "ifms-pti",
"version": "2.13.1", "version": "2.13.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "ifms-pti", "name": "ifms-pti",
"version": "2.13.1", "version": "2.13.2",
"dependencies": { "dependencies": {
"@mdi/font": "^6.6.96", "@mdi/font": "^6.6.96",
"apollo-link-ws": "^1.0.20", "apollo-link-ws": "^1.0.20",

View File

@ -1,6 +1,6 @@
{ {
"name": "ifms-pti", "name": "ifms-pti",
"version": "2.13.1", "version": "2.13.2",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",

View File

@ -42,6 +42,9 @@
Cancelar Cancelar
</v-btn> </v-btn>
</v-card-actions> </v-card-actions>
<v-alert v-for="error in errors" :key="error" class="mt-4" type="error">
{{ error }}
</v-alert>
</v-card> </v-card>
</v-navigation-drawer> </v-navigation-drawer>
</template> </template>

View File

@ -58,6 +58,7 @@ export default {
lastLogin lastLogin
lastLoginPrior lastLoginPrior
roles roles
campus
firstName firstName