Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Galimybe priskirti administratorius perziurai #23

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions database/migrations/20240114212233_addAssigneeToForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.up = async function (knex) {
await knex.schema.alterTable('forms', (table) => {
table.integer('assigneeId').unsigned();
});
};

exports.down = async function (knex) {
await knex.schema.alterTable('forms', (table) => {
table.dropColumn('assigneeId');
});
};
6 changes: 3 additions & 3 deletions mixins/database.mixin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

import _ from 'lodash';
const DbService = require('@moleculer/database').Service;
import { config } from '../knexfile';
import filtersMixin from 'moleculer-knex-filters';
import { Context } from 'moleculer';
import filtersMixin from 'moleculer-knex-filters';
import { config } from '../knexfile';
import { parseToJsonIfNeeded } from '../utils';
const DbService = require('@moleculer/database').Service;

export default function (opts: any = {}) {
const adapter: any = {
Expand Down
26 changes: 21 additions & 5 deletions services/api.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Handlers } from '@sentry/node';
import pick from 'lodash/pick';
import moleculer, { Context, Errors } from 'moleculer';
import { Action, Method, Service } from 'moleculer-decorators';
import ApiGateway from 'moleculer-web';
import { COMMON_DELETED_SCOPES, EndpointType, RequestMessage } from '../types';
import {
COMMON_DELETED_SCOPES,
EndpointType,
RequestMessage,
throwUnauthorizedError,
} from '../types';
import { Tenant } from './tenants.service';
import { User } from './users.service';
import { throwUnauthorizedError } from '../types';
import { Handlers } from '@sentry/node';
import { User, UserType } from './users.service';
export interface UserAuthMeta {
user: User;
profile?: Tenant;
Expand Down Expand Up @@ -265,7 +269,19 @@ export default class ApiService extends moleculer.Service {
const app: any = await ctx.call('auth.apps.resolveToken');

if (user && user.id) {
ctx.meta.authUser = authUser;
const authUserWithGroups: any = await ctx.call('auth.users.get', {
id: authUser.id,
populate: 'groups',
});

const adminOfGroups = authUserWithGroups.groups
.filter(
(group: any) =>
group.apps.includes(app.id) && group.role === UserType.ADMIN
)
.map((group: any) => group.id);

ctx.meta.authUser = { ...authUser, adminOfGroups };
ctx.meta.authToken = token;
ctx.meta.app = app;

Expand Down
10 changes: 2 additions & 8 deletions services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import moleculer, { Context } from 'moleculer';
import { Action, Event, Method, Service } from 'moleculer-decorators';

import authMixin from 'biip-auth-nodejs/mixin';
import { UserAuthMeta } from './api.service';
import { User, UserType } from './users.service';
import {
AUTH_FREELANCERS_GROUP_ID,
EndpointType,
throwNotFoundError,
} from '../types';
import { UserAuthMeta } from './api.service';
import { TenantUserRole } from './tenantUsers.service';
import { User, UserType } from './users.service';

@Service({
name: 'auth',
Expand Down Expand Up @@ -67,12 +67,6 @@ export default class AuthService extends moleculer.Service {
};
}

if (user.type === UserType.ADMIN) {
data.tasks = await ctx.call('users.getTasksCounts', {
userId: user.id,
});
}

return data;
}

Expand Down
Loading
Loading