-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:UserOfficeProject/user-office-co…
…re into SWAP-4396-user-officer-experiment-safety-review-workflow
- Loading branch information
Showing
29 changed files
with
513 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
DO | ||
$$ | ||
BEGIN | ||
IF register_patch('0168_CreateCoProposerInvite', 'Jekabs Karklins', 'Adding co-proposer claims', '2025-01-10') THEN | ||
BEGIN | ||
CREATE TABLE IF NOT EXISTS co_proposer_invites ( | ||
invite_code_id INT NOT NULL REFERENCES invite_codes(invite_code_id) ON DELETE CASCADE, | ||
proposal_pk INT NOT NULL REFERENCES proposals(proposal_pk) ON DELETE CASCADE, | ||
PRIMARY KEY (invite_code_id, proposal_pk)); | ||
END; | ||
END IF; | ||
END; | ||
$$ | ||
LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { inject, injectable } from 'tsyringe'; | ||
|
||
import { Tokens } from '../config/Tokens'; | ||
import { UserRole, UserWithRole } from '../models/User'; | ||
import { UserAuthorization } from './UserAuthorization'; | ||
|
||
@injectable() | ||
export class InviteAuthorization { | ||
constructor( | ||
@inject(Tokens.UserAuthorization) private userAuth: UserAuthorization | ||
) {} | ||
|
||
public isRoleInviteAuthorized = async ( | ||
agent: UserWithRole | null, | ||
roleIds?: number[] | ||
) => { | ||
// If no roleIds are provided, the invite is considered as authorized | ||
if (roleIds === undefined || roleIds.length === 0) return true; | ||
|
||
if (this.userAuth.isUserOfficer(agent)) return true; | ||
|
||
const onlyUserRole = roleIds.length === 1 && roleIds[0] === UserRole.USER; | ||
|
||
return onlyUserRole; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { CoProposerInvite } from '../models/CoProposerInvite'; | ||
|
||
export interface CoProposerInviteDataSource { | ||
create(inviteCodeId: number, proposalPk: number): Promise<CoProposerInvite>; | ||
findByInviteCodeId(inviteCodeId: number): Promise<CoProposerInvite | null>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
apps/backend/src/datasources/mockups/CoProposerInviteDataSource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { CoProposerInvite } from '../../models/CoProposerInvite'; | ||
import { CoProposerInviteDataSource } from '../CoProposerInviteDataSource'; | ||
|
||
export class CoProposerInviteDataSourceMock | ||
implements CoProposerInviteDataSource | ||
{ | ||
private invites: CoProposerInvite[] = []; | ||
|
||
init() { | ||
this.invites = [ | ||
new CoProposerInvite(1, 1), | ||
new CoProposerInvite(2, 2), | ||
new CoProposerInvite(3, 3), | ||
]; | ||
} | ||
|
||
async findByInviteCodeId( | ||
inviteCodeId: number | ||
): Promise<CoProposerInvite | null> { | ||
return ( | ||
this.invites.find((invite) => invite.inviteCodeId === inviteCodeId) || | ||
null | ||
); | ||
} | ||
|
||
async create( | ||
inviteCodeId: number, | ||
proposalPk: number | ||
): Promise<CoProposerInvite> { | ||
const newInvite = new CoProposerInvite(inviteCodeId, proposalPk); | ||
|
||
this.invites.push(newInvite); | ||
|
||
return newInvite; | ||
} | ||
} |
Oops, something went wrong.