Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Oct 16, 2023
2 parents d70b107 + daa879e commit a427ca7
Show file tree
Hide file tree
Showing 138 changed files with 932 additions and 5,865 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"nestjs-console": "^9.0.0",
"p-retry": "^5.1.2",
"pako": "^2.1.0",
"pg": "^8.11.3",
"pkg-up": "^4.0.0",
"plur": "^5.1.0",
"prismjs-terminal": "^1.2.2",
Expand Down Expand Up @@ -118,7 +117,6 @@
"@types/luxon": "^3.3.1",
"@types/node": "^18.17.7",
"@types/pako": "^2.0.0",
"@types/pg": "^8.10.2",
"@types/prismjs": "^1.26.0",
"@types/react": "^18.2.20",
"@types/stack-trace": "^0.0.30",
Expand Down
13 changes: 5 additions & 8 deletions src/common/sensitivity.enum.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { applyDecorators } from '@nestjs/common';
import { Field, FieldOptions, registerEnumType } from '@nestjs/graphql';
import { Field, FieldOptions } from '@nestjs/graphql';
import { Transform } from 'class-transformer';
import { uniq } from 'lodash';
import { rankSens } from '../core/database/query';
import { DbSort } from './db-sort.decorator';
import { EnumType, makeEnum } from './make-enum';

export enum Sensitivity {
Low = 'Low',
Medium = 'Medium',
High = 'High',
}

registerEnumType(Sensitivity, {
export type Sensitivity = EnumType<typeof Sensitivity>;
export const Sensitivity = makeEnum({
name: 'Sensitivity',
values: ['Low', 'Medium', 'High'],
});

export const SensitivityField = (options: FieldOptions = {}) =>
Expand Down
7 changes: 3 additions & 4 deletions src/components/admin/admin.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
import { DateTime } from 'luxon';
import { ID, ServerException } from '~/common';
import { ID, Role, ServerException } from '~/common';
import { ConfigService } from '~/core/config/config.service';
import { Transactional } from '~/core/database';
import { ILogger, Logger } from '~/core/logger';
import { AuthenticationService } from '../authentication';
import { CryptoService } from '../authentication/crypto.service';
import { Powers, Role } from '../authorization/dto';
import { Power } from '../authorization/dto';
import { AdminRepository } from './admin.repository';

@Injectable()
Expand Down Expand Up @@ -84,8 +84,7 @@ export class AdminService implements OnApplicationBootstrap {
});

// set root user label & give all powers
const powers = Object.keys(Powers);
await this.repo.setUserLabel(powers, id);
await this.repo.setUserLabel([...Power.values], id);
}

// TODO do this a different way. Using a global like this can cause race conditions.
Expand Down
2 changes: 1 addition & 1 deletion src/components/authentication/login.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { stripIndent } from 'common-tags';
import { AnonSession, GqlContextType, Session } from '../../common';
import { Loader, LoaderOf } from '../../core';
import { Powers as Power, Privileges } from '../authorization';
import { Power, Privileges } from '../authorization';
import { User, UserLoader } from '../user';
import { AuthenticationService } from './authentication.service';
import { LoginInput, LoginOutput, LogoutOutput } from './dto';
Expand Down
2 changes: 1 addition & 1 deletion src/components/authentication/register.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { stripIndent } from 'common-tags';
import { AnonSession, GqlContextType, Session } from '../../common';
import { Loader, LoaderOf } from '../../core';
import { Powers as Power, Privileges } from '../authorization';
import { Power, Privileges } from '../authorization';
import { User, UserLoader } from '../user';
import { AuthenticationService } from './authentication.service';
import { RegisterInput, RegisterOutput } from './dto';
Expand Down
2 changes: 1 addition & 1 deletion src/components/authentication/session.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
UnauthenticatedException,
} from '../../common';
import { ConfigService, ILogger, Loader, LoaderOf, Logger } from '../../core';
import { Powers as Power, Privileges } from '../authorization';
import { Power, Privileges } from '../authorization';
import { User, UserLoader } from '../user';
import { AuthenticationService } from './authentication.service';
import { SessionOutput } from './dto';
Expand Down
2 changes: 1 addition & 1 deletion src/components/authorization/authorization.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Query, Resolver } from '@nestjs/graphql';
import { AnonSession, Session } from '~/common';
import { Powers as Power } from './dto';
import { Power } from './dto';
import { Privileges } from './policy';

@Resolver()
Expand Down
2 changes: 1 addition & 1 deletion src/components/authorization/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './role.dto';
export * from './powers';
export * from './power.enum';
111 changes: 111 additions & 0 deletions src/components/authorization/dto/power.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { EnumType, makeEnum } from '~/common';

export type Power = EnumType<typeof Power>;
export const Power = makeEnum({
name: 'Power',
values: [
'BetaFeatures',
'CreateEthnoArt',
'CreateFieldRegion',
'CreateFieldZone',
'CreateFilm',
'CreateFundingAccount',
'CreateLanguage',
'CreateLiteracyMaterial',
'CreateLocation',
'CreateOrganization',
'CreatePartner',
'CreateProject',
'CreateSong',
'CreateStory',
'CreateUser',
{
value: 'CreateBudget',
deprecationReason: 'Use `Project.budget` instead',
},
{
value: 'CreateBudgetRecord',
deprecationReason: 'Use `Project.budget` instead',
},
{
value: 'CreateCeremony',
deprecationReason: 'Use `Engagement.ceremony` instead',
},
{
value: 'CreateChangeRequest',
deprecationReason: 'Use `Project.changeRequests` instead',
},
{
value: 'CreateDirectory',
deprecationReason: 'Use something else instead',
},
{
value: 'CreateEducation',
deprecationReason: 'Use `User.education` instead',
},
{
value: 'CreateEthnologueLanguage',
deprecationReason:
'Just check `CreateLanguage` instead. This is a sub-object ',
},
{ value: 'CreateFile', deprecationReason: 'Use something else instead' },
{
value: 'CreateFileVersion',
deprecationReason: 'Use something else instead',
},
{
value: 'CreateInternshipEngagement',
deprecationReason: 'Use `Project.engagements` instead',
},
{
value: 'CreateLanguageEngagement',
deprecationReason: 'Use `Project.engagements` instead',
},
{
value: 'CreatePartnership',
deprecationReason: 'Use `Project.partnerships` instead ',
},
{ value: 'CreatePost', deprecationReason: 'Use `X.posts` instead' },
{
value: 'CreateProduct',
deprecationReason: 'Use `Engagement.products` instead',
},
{
value: 'CreateProjectEngagement',
deprecationReason: 'Use `Project.engagements` instead',
},
{
value: 'CreateProjectMember',
deprecationReason: 'Use `Project.team` instead',
},
{
value: 'CreateTranslationEngagement',
deprecationReason: 'Use `Project.engagements` instead',
},
{
value: 'CreateUnavailability',
deprecationReason: 'Use `User.unavailabilities` instead',
},
{
value: 'GrantInternRole',
deprecationReason: 'Use `AuthorizedRoles.Intern` instead',
},
{
value: 'GrantLiaisonRole',
deprecationReason: 'Use `AuthorizedRoles.Liaison` instead',
},
{
value: 'GrantMentorRole',
deprecationReason: 'Use `AuthorizedRoles.Mentor` instead',
},
{
value: 'GrantRegionalCommunicationsCoordinatorRole',
deprecationReason:
'Use `AuthorizedRoles.RegionalCommunicationsCoordinator` instead',
},
{
value: 'GrantTranslatorRole',
deprecationReason: 'Use `AuthorizedRoles.Translator` instead',
},
],
});
74 changes: 0 additions & 74 deletions src/components/authorization/dto/powers.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/components/authorization/missing-power.exception.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { UnauthorizedException } from '../../common/exceptions';
import { Powers } from './dto/powers';
import { UnauthorizedException } from '~/common';
import { Power } from './dto';

export class MissingPowerException extends UnauthorizedException {
constructor(
readonly power: Powers,
readonly power: Power,
message = `Missing required power: ${power}`,
previous?: Error,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SecuredPropsPlusExtraKey,
Session,
} from '~/common';
import { Powers as Power } from '../../dto/powers';
import { Power } from '../../dto';
import { MissingPowerException } from '../../missing-power.exception';
import { ChildListAction, ChildSingleAction, PropAction } from '../actions';
import { ResourceObjectContext } from '../object.type';
Expand Down
5 changes: 2 additions & 3 deletions src/components/authorization/policy/policy.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { Injectable, OnModuleInit } from '@nestjs/common';
import { pick, startCase } from 'lodash';
import { DeepWritable, Writable } from 'ts-essentials';
import { keys as keysOf } from 'ts-transformer-keys';
import { EnhancedResource, many, mapFromList } from '~/common';
import { EnhancedResource, many, mapFromList, Role } from '~/common';
import { ResourcesHost } from '~/core/resources';
import { Powers as Power } from '../dto/powers';
import { Role } from '../dto/role.dto';
import { Power } from '../dto';
import { ChildListAction, ChildSingleAction } from './actions';
import { extract, Permission, Permissions } from './builder/perm-granter';
import {
Expand Down
15 changes: 6 additions & 9 deletions src/components/budget/dto/budget-status.enum.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { registerEnumType } from '@nestjs/graphql';
import { EnumType, makeEnum } from '~/common';

export enum BudgetStatus {
Pending = 'Pending',
Current = 'Current',
Superceded = 'Superceded',
Rejected = 'Rejected',
}

registerEnumType(BudgetStatus, { name: 'BudgetStatus' });
export type BudgetStatus = EnumType<typeof BudgetStatus>;
export const BudgetStatus = makeEnum({
name: 'BudgetStatus',
values: ['Pending', 'Current', 'Superceded', 'Rejected'],
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class UpdateProjectBudgetStatusHandler
if (!updates.step) {
return;
}
let budgetStatus = BudgetStatus.Current;
let budgetStatus: BudgetStatus = BudgetStatus.Current;
if (
stepToStatus(updates.step) !== ProjectStatus.Active ||
previous.status === ProjectStatus.Active
Expand Down
12 changes: 12 additions & 0 deletions src/components/ceremony/dto/ceremony-type.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { EnumType, makeEnum } from '~/common';

export type CeremonyType = EnumType<typeof CeremonyType>;
export const CeremonyType = makeEnum({
name: 'CeremonyType',
values: [
// Language Engagements can have dedications
'Dedication',
// Internship Engagements can have certifications
'Certification',
],
});
2 changes: 1 addition & 1 deletion src/components/ceremony/dto/ceremony.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Sensitivity,
SensitivityField,
} from '../../../common';
import { CeremonyType } from './type.enum';
import { CeremonyType } from './ceremony-type.enum';

@RegisterResource()
@Calculated()
Expand Down
2 changes: 1 addition & 1 deletion src/components/ceremony/dto/create-ceremony.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Field, InputType } from '@nestjs/graphql';
import { CalendarDate, DateField } from '../../../common';
import { CeremonyType } from './type.enum';
import { CeremonyType } from './ceremony-type.enum';

@InputType()
export abstract class CreateCeremony {
Expand Down
1 change: 1 addition & 0 deletions src/components/ceremony/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './create-ceremony.dto';
export * from './list-ceremony.dto';
export * from './ceremony.dto';
export * from './ceremony-type.enum';
export * from './update-ceremony.dto';
2 changes: 1 addition & 1 deletion src/components/ceremony/dto/list-ceremony.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Field, InputType, ObjectType } from '@nestjs/graphql';
import { FilterField, PaginatedList, SortablePaginationInput } from '~/common';
import { CeremonyType } from './ceremony-type.enum';
import { Ceremony } from './ceremony.dto';
import { CeremonyType } from './type.enum';

@InputType()
export abstract class CeremonyFilters {
Expand Down
Loading

0 comments on commit a427ca7

Please sign in to comment.