mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-23 00:22:19 +01:00
fix: update user permission mapping
This commit is contained in:
parent
d2907d1887
commit
4409111be0
@ -9,6 +9,7 @@ import {
|
|||||||
IUserPermission,
|
IUserPermission,
|
||||||
} from '../types/stores/access-store';
|
} from '../types/stores/access-store';
|
||||||
import { IPermission } from 'lib/types/model';
|
import { IPermission } from 'lib/types/model';
|
||||||
|
import { roundToNearestMinutesWithOptions } from 'date-fns/fp';
|
||||||
|
|
||||||
const T = {
|
const T = {
|
||||||
ROLE_USER: 'role_user',
|
ROLE_USER: 'role_user',
|
||||||
@ -25,8 +26,10 @@ interface IPermissionRow {
|
|||||||
environment?: string;
|
environment?: string;
|
||||||
type: string;
|
type: string;
|
||||||
project?: string;
|
project?: string;
|
||||||
|
role_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EDITOR_ID = 2;
|
||||||
export class AccessStore implements IAccessStore {
|
export class AccessStore implements IAccessStore {
|
||||||
private logger: Logger;
|
private logger: Logger;
|
||||||
|
|
||||||
@ -132,7 +135,13 @@ export class AccessStore implements IAccessStore {
|
|||||||
async getPermissionsForUser(userId: number): Promise<IUserPermission[]> {
|
async getPermissionsForUser(userId: number): Promise<IUserPermission[]> {
|
||||||
const stopTimer = this.timer('getPermissionsForUser');
|
const stopTimer = this.timer('getPermissionsForUser');
|
||||||
const rows = await this.db
|
const rows = await this.db
|
||||||
.select('project', 'permission', 'environment', 'type')
|
.select(
|
||||||
|
'project',
|
||||||
|
'permission',
|
||||||
|
'environment',
|
||||||
|
'type',
|
||||||
|
'ur.role_id',
|
||||||
|
)
|
||||||
.from<IPermissionRow>(`${T.ROLE_PERMISSION} AS rp`)
|
.from<IPermissionRow>(`${T.ROLE_PERMISSION} AS rp`)
|
||||||
.join(`${T.ROLE_USER} AS ur`, 'ur.role_id', 'rp.role_id')
|
.join(`${T.ROLE_USER} AS ur`, 'ur.role_id', 'rp.role_id')
|
||||||
.join(`${T.PERMISSIONS} AS p`, 'p.id', 'rp.permission_id')
|
.join(`${T.PERMISSIONS} AS p`, 'p.id', 'rp.permission_id')
|
||||||
@ -142,7 +151,16 @@ export class AccessStore implements IAccessStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mapUserPermission(row: IPermissionRow): IUserPermission {
|
mapUserPermission(row: IPermissionRow): IUserPermission {
|
||||||
const project = row.type !== 'root' ? row.project : undefined;
|
let project;
|
||||||
|
// Since the editor should have access to the default project,
|
||||||
|
// we map the project to the project and environment specific
|
||||||
|
// permissions that are connected to the editor role.
|
||||||
|
if (row.role_id === EDITOR_ID && row.type !== 'root') {
|
||||||
|
project = 'default';
|
||||||
|
} else if (row.type !== 'root') {
|
||||||
|
project = row.project ? row.project : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const environment =
|
const environment =
|
||||||
row.type === 'environment' ? row.environment : undefined;
|
row.type === 'environment' ? row.environment : undefined;
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user