Skip to content

Commit

Permalink
Merge branch 'develop' into authorization-lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
techsmyth authored Dec 20, 2024
2 parents ff673ec + 6dabcba commit a91aabc
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 88 deletions.
13 changes: 0 additions & 13 deletions src/domain/space/space.settings/space.settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@ export class SpaceSettingsService {
@Inject(WINSTON_MODULE_NEST_PROVIDER) private readonly logger: LoggerService
) {}

public getSettings(settingsStr: string): ISpaceSettings {
const states: ISpaceSettings = this.deserializeSettings(settingsStr);
return states;
}

public serializeSettings(settings: ISpaceSettings): string {
return JSON.stringify(settings);
}

private deserializeSettings(settingsStr: string): ISpaceSettings {
return JSON.parse(settingsStr);
}

public updateSettings(
settings: ISpaceSettings,
updateData: UpdateSpaceSettingsEntityInput
Expand Down
22 changes: 21 additions & 1 deletion src/domain/space/space/sort.spaces.by.activity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { SpaceType } from '@common/enums/space.type';
import { SpaceVisibility } from '@common/enums/space.visibility';
import { ProfileType } from '@common/enums';
import { AccountType } from '@common/enums/account.type';
import { CommunityMembershipPolicy } from '@common/enums/community.membership.policy';
import { SpacePrivacyMode } from '@common/enums/space.privacy.mode';

const createTestActivity = (createdDate: Date): IActivity => {
return {
Expand All @@ -22,12 +24,30 @@ const createTestActivity = (createdDate: Date): IActivity => {
};
};

const spaceSettings = {
privacy: {
mode: SpacePrivacyMode.PUBLIC,
allowPlatformSupportAsAdmin: false,
},
membership: {
policy: CommunityMembershipPolicy.OPEN,
trustedOrganizations: [],
allowSubspaceAdminsToInviteMembers: false,
},
collaboration: {
inheritMembershipRights: true,
allowMembersToCreateSubspaces: true,
allowMembersToCreateCallouts: true,
allowEventsFromSubspaces: true,
},
};

const createTestSpace = (id: string): ISpace => {
return {
id,
rowId: 1,
nameID: 'space1',
settingsStr: '',
settings: spaceSettings,
levelZeroSpaceID: '',
visibility: SpaceVisibility.ACTIVE,
profile: {
Expand Down
6 changes: 4 additions & 2 deletions src/domain/space/space/space.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Profile } from '@domain/common/profile';
import { TemplatesManager } from '@domain/template/templates-manager';
import { License } from '@domain/common/license/license.entity';
import { SpaceLevel } from '@common/enums/space.level';
import { ISpaceSettings } from '../space.settings/space.settings.interface';
@Entity()
export class Space extends NameableEntity implements ISpace {
@OneToOne(() => Profile, {
Expand Down Expand Up @@ -85,8 +86,8 @@ export class Space extends NameableEntity implements ISpace {
@JoinColumn()
agent?: Agent;

@Column('text')
settingsStr: string = '';
@Column('json', { nullable: true })
settings: ISpaceSettings;

@OneToOne(() => StorageAggregator, {
eager: false,
Expand Down Expand Up @@ -130,5 +131,6 @@ export class Space extends NameableEntity implements ISpace {
constructor() {
super();
this.nameID = '';
this.settings = {} as ISpaceSettings;
}
}
3 changes: 2 additions & 1 deletion src/domain/space/space/space.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SpaceVisibility } from '@common/enums/space.visibility';
import { ITemplatesManager } from '@domain/template/templates-manager';
import { ILicense } from '@domain/common/license/license.interface';
import { SpaceLevel } from '@common/enums/space.level';
import { ISpaceSettings } from '../space.settings/space.settings.interface';

@ObjectType('Space')
export class ISpace extends INameable {
Expand Down Expand Up @@ -46,7 +47,7 @@ export class ISpace extends INameable {
context?: IContext;
community?: ICommunity;

settingsStr!: string;
settings!: ISpaceSettings;

storageAggregator?: IStorageAggregator;

Expand Down
2 changes: 1 addition & 1 deletion src/domain/space/space/space.resolver.fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class SpaceResolverFields {
})
@UseGuards(GraphqlGuard)
settings(@Parent() space: ISpace): ISpaceSettings {
return this.spaceService.getSettings(space);
return space.settings;
}

@AuthorizationAgentPrivilege(AuthorizationPrivilege.READ)
Expand Down
4 changes: 1 addition & 3 deletions src/domain/space/space/space.service.authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ export class SpaceAuthorizationService {
const updatedAuthorizations: IAuthorizationPolicy[] = [];

const spaceVisibility = space.visibility;
const spaceSettings = this.spaceSettingsService.getSettings(
space.settingsStr
);
const spaceSettings = space.settings;
const isPrivate = spaceSettings.privacy.mode === SpacePrivacyMode.PRIVATE;

// Store the provided parent authorization so that later resets can happen
Expand Down
107 changes: 98 additions & 9 deletions src/domain/space/space/space.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { AccountType } from '@common/enums/account.type';
import { Repository } from 'typeorm';
import { getRepositoryToken } from '@nestjs/typeorm';
import { ISpaceSettings } from '@domain/space/space.settings/space.settings.interface';
import { SpacePrivacyMode } from '@common/enums/space.privacy.mode';
import { CommunityMembershipPolicy } from '@common/enums/community.membership.policy';

const moduleMocker = new ModuleMocker(global);

Expand Down Expand Up @@ -56,11 +58,10 @@ describe('SpaceService', () => {
} as ISpaceSettings;
const space = {
id: spaceId,
settingsStr: JSON.stringify(settingsData),
settings: settingsData,
} as Space;

jest.spyOn(spaceRepository, 'findOneOrFail').mockResolvedValue(space);
jest.spyOn(service, 'getSettings').mockReturnValue(settingsData);

const result = await service.shouldUpdateAuthorizationPolicy(
spaceId,
Expand All @@ -85,11 +86,10 @@ describe('SpaceService', () => {
} as ISpaceSettings;
const space = {
id: spaceId,
settingsStr: JSON.stringify(originalSettings),
settings: originalSettings,
} as Space;

jest.spyOn(spaceRepository, 'findOneOrFail').mockResolvedValue(space);
jest.spyOn(service, 'getSettings').mockReturnValue(originalSettings);

const result = await service.shouldUpdateAuthorizationPolicy(
spaceId,
Expand All @@ -108,11 +108,10 @@ describe('SpaceService', () => {
} as ISpaceSettings;
const space = {
id: spaceId,
settingsStr: JSON.stringify(originalSettings),
settings: originalSettings,
} as Space;

jest.spyOn(spaceRepository, 'findOneOrFail').mockResolvedValue(space);
jest.spyOn(service, 'getSettings').mockReturnValue(originalSettings);

const result = await service.shouldUpdateAuthorizationPolicy(
spaceId,
Expand Down Expand Up @@ -252,6 +251,24 @@ const getAuthorizationPolicyMock = (
...getEntityMock<AuthorizationPolicy>(),
});

const spaceSettings = {
privacy: {
mode: SpacePrivacyMode.PUBLIC,
allowPlatformSupportAsAdmin: false,
},
membership: {
policy: CommunityMembershipPolicy.OPEN,
trustedOrganizations: [],
allowSubspaceAdminsToInviteMembers: false,
},
collaboration: {
inheritMembershipRights: true,
allowMembersToCreateSubspaces: true,
allowMembersToCreateCallouts: true,
allowEventsFromSubspaces: true,
},
};

const getSubspacesMock = (
spaceId: string,
count: number,
Expand All @@ -263,7 +280,7 @@ const getSubspacesMock = (
id: `${spaceId}.${i}`,
rowId: i,
nameID: `challenge-${spaceId}.${i}`,
settingsStr: JSON.stringify({}),
settings: spaceSettings,
levelZeroSpaceID: spaceId,
account: {
id: `account-${spaceId}.${i}`,
Expand Down Expand Up @@ -360,7 +377,7 @@ const getSubsubspacesMock = (subsubspaceId: string, count: number): Space[] => {
id: `${subsubspaceId}.${i}`,
rowId: i,
nameID: `subsubspace-${subsubspaceId}.${i}`,
settingsStr: JSON.stringify({}),
settings: spaceSettings,
levelZeroSpaceID: subsubspaceId,
account: {
id: `account-${subsubspaceId}.${i}`,
Expand Down Expand Up @@ -452,18 +469,20 @@ const getSpaceMock = ({
anonymousReadAccess,
challengesCount,
opportunitiesCounts,
settings,
}: {
id: string;
visibility: SpaceVisibility;
anonymousReadAccess: boolean;
challengesCount: number;
opportunitiesCounts: number[];
settings: ISpaceSettings;
}): Space => {
return {
id,
rowId: parseInt(id),
nameID: `space-${id}`,
settingsStr: JSON.stringify({}),
settings: settings,
levelZeroSpaceID: '',
profile: {
id: `profile-${id}`,
Expand Down Expand Up @@ -512,68 +531,138 @@ const spaceTestData: Space[] = [
visibility: SpaceVisibility.ACTIVE,
challengesCount: 1,
opportunitiesCounts: [5],
settings: {
...spaceSettings,
privacy: {
mode: SpacePrivacyMode.PUBLIC,
allowPlatformSupportAsAdmin: false,
},
},
}),
getSpaceMock({
id: '2',
anonymousReadAccess: true,
visibility: SpaceVisibility.ACTIVE,
challengesCount: 2,
opportunitiesCounts: [5, 3],
settings: {
...spaceSettings,
privacy: {
mode: SpacePrivacyMode.PUBLIC,
allowPlatformSupportAsAdmin: false,
},
},
}),
getSpaceMock({
id: '3',
anonymousReadAccess: true,
visibility: SpaceVisibility.DEMO,
challengesCount: 3,
opportunitiesCounts: [5, 3, 1],
settings: {
...spaceSettings,
privacy: {
mode: SpacePrivacyMode.PUBLIC,
allowPlatformSupportAsAdmin: false,
},
},
}),
getSpaceMock({
id: '4',
anonymousReadAccess: false,
visibility: SpaceVisibility.DEMO,
challengesCount: 3,
opportunitiesCounts: [1, 2, 1],
settings: {
...spaceSettings,
privacy: {
mode: SpacePrivacyMode.PRIVATE,
allowPlatformSupportAsAdmin: false,
},
},
}),
getSpaceMock({
id: '5',
anonymousReadAccess: false,
visibility: SpaceVisibility.ACTIVE,
challengesCount: 1,
opportunitiesCounts: [1],
settings: {
...spaceSettings,
privacy: {
mode: SpacePrivacyMode.PRIVATE,
allowPlatformSupportAsAdmin: false,
},
},
}),
getSpaceMock({
id: '6',
anonymousReadAccess: true,
visibility: SpaceVisibility.ACTIVE,
challengesCount: 3,
opportunitiesCounts: [1, 1, 6],
settings: {
...spaceSettings,
privacy: {
mode: SpacePrivacyMode.PUBLIC,
allowPlatformSupportAsAdmin: false,
},
},
}),
getSpaceMock({
id: '7',
anonymousReadAccess: true,
visibility: SpaceVisibility.ARCHIVED,
challengesCount: 0,
opportunitiesCounts: [],
settings: {
...spaceSettings,
privacy: {
mode: SpacePrivacyMode.PUBLIC,
allowPlatformSupportAsAdmin: false,
},
},
}),
getSpaceMock({
id: '8',
anonymousReadAccess: true,
visibility: SpaceVisibility.DEMO,
challengesCount: 0,
opportunitiesCounts: [],
settings: {
...spaceSettings,
privacy: {
mode: SpacePrivacyMode.PUBLIC,
allowPlatformSupportAsAdmin: false,
},
},
}),
getSpaceMock({
id: '9',
anonymousReadAccess: false,
visibility: SpaceVisibility.ACTIVE,
challengesCount: 0,
opportunitiesCounts: [],
settings: {
...spaceSettings,
privacy: {
mode: SpacePrivacyMode.PRIVATE,
allowPlatformSupportAsAdmin: false,
},
},
}),
getSpaceMock({
id: '10',
anonymousReadAccess: false,
visibility: SpaceVisibility.DEMO,
challengesCount: 3,
opportunitiesCounts: [1, 2, 0],
settings: {
...spaceSettings,
privacy: {
mode: SpacePrivacyMode.PRIVATE,
allowPlatformSupportAsAdmin: false,
},
},
}),
];
Loading

0 comments on commit a91aabc

Please sign in to comment.