-
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.
feat: add co proposer claim to invite (#908)
Co-authored-by: Jekabs Karklins <[email protected]> Co-authored-by: Yoganandan Pandiyan <[email protected]>
- Loading branch information
1 parent
4bd7218
commit 9f5019b
Showing
23 changed files
with
487 additions
and
34 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; |
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; | ||
} | ||
} |
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/postgres/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'; | ||
import database from './database'; | ||
|
||
export default class PostgresCoProposerInviteDataSource | ||
implements CoProposerInviteDataSource | ||
{ | ||
async findByInviteCodeId( | ||
inviteCodeId: number | ||
): Promise<CoProposerInvite | null> { | ||
return database('co_proposer_invites') | ||
.where({ invite_code_id: inviteCodeId }) | ||
.select('*') | ||
.first() | ||
.then((row) => { | ||
if (!row) { | ||
return null; | ||
} | ||
|
||
return new CoProposerInvite(row.invite_code_id, row.proposal_pk); | ||
}); | ||
} | ||
async create( | ||
inviteCodeId: number, | ||
proposalPk: number | ||
): Promise<CoProposerInvite> { | ||
return database('co_proposer_invites') | ||
.insert({ invite_code_id: inviteCodeId, proposal_pk: proposalPk }) | ||
.returning('*') | ||
.then((rows) => { | ||
const row = rows[0]; | ||
|
||
return new CoProposerInvite(row.invite_code_id, row.proposal_pk); | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.