Skip to content

Commit

Permalink
fix: move DEFAULT_PROJECT to types
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarconr committed Jan 11, 2022
1 parent b582bb1 commit 6d6686a
Show file tree
Hide file tree
Showing 4 changed files with 6,839 additions and 6,693 deletions.
20 changes: 14 additions & 6 deletions src/lib/db/access-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
IRole,
IUserPermission,
} from '../types/stores/access-store';
import { IPermission } from '../../lib/types/model';
import { IPermission } from '../types/model';
import NotFoundError from '../error/notfound-error';
import {
ENVIRONMENT_PERMISSION_TYPE,
ROOT_PERMISSION_TYPE,
} from '../util/constants';
import { DEFAULT_PROJECT } from '../../lib/services/project-service';
import { DEFAULT_PROJECT } from '../types/project';

const T = {
ROLE_USER: 'role_user',
Expand All @@ -34,7 +34,8 @@ interface IPermissionRow {
role_id: number;
}

const EDITOR_ID = 2;
const EDITOR_ROLE_ID = 2;

export class AccessStore implements IAccessStore {
private logger: Logger;

Expand Down Expand Up @@ -126,26 +127,33 @@ export class AccessStore implements IAccessStore {
}

mapUserPermission(row: IPermissionRow): IUserPermission {
let project;
let project: string;
// 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_PERMISSION_TYPE) {
console.log('before', row);
if (row.role_id === EDITOR_ROLE_ID && row.type !== ROOT_PERMISSION_TYPE) {
project = DEFAULT_PROJECT;
} else if (row.type !== ROOT_PERMISSION_TYPE) {
project = row.project ? row.project : undefined;
}

console.log('row.role_id === EDITOR_ID', row.role_id === EDITOR_ROLE_ID);
console.log('row.type !== ROOT_PERMISSION_TYPE', row.type !== ROOT_PERMISSION_TYPE);
console.log('DEFAULT_PROJECT', DEFAULT_PROJECT);

const environment =
row.type === ENVIRONMENT_PERMISSION_TYPE
? row.environment
: undefined;

return {
const result = {
project,
environment,
permission: row.permission,
};
console.log('after:', result);
return result;
}

async getPermissionsForRole(roleId: number): Promise<IPermission[]> {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/services/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ import FeatureToggleService from './feature-toggle-service';
import { CREATE_FEATURE, UPDATE_FEATURE } from '../types/permissions';
import NoAccessError from '../error/no-access-error';
import IncompatibleProjectError from '../error/incompatible-project-error';
import { DEFAULT_PROJECT } from '../types/project';

const getCreatedBy = (user: User) => user.email || user.username;

export const DEFAULT_PROJECT = 'default';

export interface UsersWithRoles {
users: IUserWithRole[];
roles: IRoleDescriptor[];
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_PROJECT = 'default';

0 comments on commit 6d6686a

Please sign in to comment.