feat: implement permission checks for various actions across multiple resources, including acoes, atas, atestados, ausencias, ferias, and simbolos

This commit is contained in:
2025-12-12 09:26:30 -03:00
parent 4eb49d3e63
commit 92a9605417
8 changed files with 554 additions and 51 deletions

View File

@@ -1,5 +1,6 @@
import { v } from 'convex/values';
import { mutation, query } from './_generated/server';
import { internal } from './_generated/api';
import { simboloTipo } from './tables/funcionarios';
export const getAll = query({
@@ -17,6 +18,10 @@ export const getAll = query({
})
),
handler: async (ctx) => {
await ctx.runQuery(internal.permissoesAcoes.assertPermissaoAcaoAtual, {
recurso: 'simbolos',
acao: 'listar'
});
return await ctx.db.query('simbolos').collect();
}
});
@@ -39,6 +44,10 @@ export const getById = query({
v.null()
),
handler: async (ctx, args) => {
await ctx.runQuery(internal.permissoesAcoes.assertPermissaoAcaoAtual, {
recurso: 'simbolos',
acao: 'ver'
});
return await ctx.db.get(args.id);
}
});
@@ -53,6 +62,11 @@ export const create = mutation({
valor: v.optional(v.string())
},
handler: async (ctx, args) => {
await ctx.runQuery(internal.permissoesAcoes.assertPermissaoAcaoAtual, {
recurso: 'simbolos',
acao: 'criar'
});
let refValor = args.refValor;
let vencValor = args.vencValor;
let valor = args.valor ?? '';
@@ -90,6 +104,10 @@ export const remove = mutation({
},
returns: v.null(),
handler: async (ctx, args) => {
await ctx.runQuery(internal.permissoesAcoes.assertPermissaoAcaoAtual, {
recurso: 'simbolos',
acao: 'excluir'
});
await ctx.db.delete(args.id);
return null;
}
@@ -107,6 +125,11 @@ export const update = mutation({
},
returns: v.null(),
handler: async (ctx, args) => {
await ctx.runQuery(internal.permissoesAcoes.assertPermissaoAcaoAtual, {
recurso: 'simbolos',
acao: 'editar'
});
let refValor = args.refValor;
let vencValor = args.vencValor;
let valor = args.valor ?? '';
@@ -149,6 +172,11 @@ export const removerDuplicados = mutation({
mantidos: v.number()
}),
handler: async (ctx) => {
await ctx.runQuery(internal.permissoesAcoes.assertPermissaoAcaoAtual, {
recurso: 'simbolos',
acao: 'excluir'
});
const todosSimbolos = await ctx.db.query('simbolos').collect();
// Agrupar símbolos por nome