Skip to content

Commit

Permalink
Merge pull request #233 from privacy-scaling-explorations/refactor/ne…
Browse files Browse the repository at this point in the history
…w-design

New M3 design
  • Loading branch information
cedoor authored Jul 27, 2023
2 parents e843b78 + b993cba commit feddf9a
Show file tree
Hide file tree
Showing 39 changed files with 1,394 additions and 638 deletions.
4 changes: 3 additions & 1 deletion apps/api/src/app/groups/entities/group.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export class Group {
@Column({ name: "fingerprint_duration" })
fingerprintDuration: number

@OneToMany(() => Member, (member) => member.group, { cascade: ["insert"] })
@OneToMany(() => Member, (member) => member.group, {
cascade: ["insert"]
})
members: Member[]

@OneToMany(() => ReputationAccount, (account) => account.group, {
Expand Down
4 changes: 3 additions & 1 deletion apps/api/src/app/groups/entities/member.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export class Member {
// i.e we allow same member id to be part of many groups.
// But since this property is not used in any feature at the moment,
// it is treated as many-to-one in the code for simplicity.
@ManyToOne(() => Group, (group) => group.members)
@ManyToOne(() => Group, (group) => group.members, {
onDelete: "CASCADE"
})
@JoinColumn({ name: "group_id" })
group: Group

Expand Down
12 changes: 12 additions & 0 deletions apps/api/src/app/groups/groups.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export class GroupsController {
)
}

@Delete(":group")
@UseGuards(AuthGuard)
async removeGroup(@Req() req: Request, @Param("group") groupId: string) {
await this.groupsService.removeGroup(groupId, req.session.adminId)
}

@Patch(":group")
@UseGuards(AuthGuard)
async updateGroup(
Expand All @@ -75,6 +81,12 @@ export class GroupsController {
)
}

@Patch(":group/api-key")
@UseGuards(AuthGuard)
async updateApiKey(@Req() req: Request, @Param("group") groupId: string) {
return this.groupsService.updateApiKey(groupId, req.session.adminId)
}

@Get(":group/members/:member")
isGroupMember(
@Param("group") groupId: string,
Expand Down
60 changes: 56 additions & 4 deletions apps/api/src/app/groups/groups.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class GroupsService {
/**
* Creates a new group.
* @param dto External parameters used to create a new group.
* @param admin Admin id.
* @param adminId Admin id.
* @returns Created group.
*/
async createGroup(
Expand All @@ -61,11 +61,11 @@ export class GroupsService {
treeDepth,
fingerprintDuration
}: CreateGroupDto,
admin: string
adminId: string
): Promise<Group> {
const _groupId =
groupId ||
BigInt(id(name + admin))
BigInt(id(name + adminId))
.toString()
.slice(0, 32)

Expand All @@ -75,7 +75,7 @@ export class GroupsService {
description,
treeDepth,
fingerprintDuration,
adminId: admin,
adminId,
members: []
})

Expand All @@ -94,6 +94,27 @@ export class GroupsService {
return group
}

/**
* Removes a group.
* @param groupId Group id.
* @param adminId Admin id.
*/
async removeGroup(groupId: string, adminId: string): Promise<void> {
const group = await this.getGroup(groupId)

if (group.adminId !== adminId) {
throw new UnauthorizedException(
`You are not the admin of the group '${groupId}'`
)
}

await this.groupRepository.remove(group)

this.cachedGroups.delete(groupId)

Logger.log(`GroupsService: group '${group.name}' has been removed`)
}

/**
* Updates some parameters of the group.
* @param groupId Group id.
Expand Down Expand Up @@ -155,6 +176,37 @@ export class GroupsService {
return group
}

/**
* Updates the group api key.
* @param groupId Group id.
* @param adminId Group admin id.
*/
async updateApiKey(groupId: string, adminId: string): Promise<string> {
const group = await this.getGroup(groupId)

if (group.adminId !== adminId) {
throw new UnauthorizedException(
`You are not the admin of the group '${groupId}'`
)
}

if (!group.apiEnabled) {
throw new UnauthorizedException(
`Group '${groupId}' APIs are not enabled`
)
}

group.apiKey = v4()

await this.groupRepository.save(group)

Logger.log(
`GroupsService: group '${group.name}' APIs have been updated`
)

return group.apiKey
}

/**
* Join the group by redeeming invite code.
* @param groupId Group name.
Expand Down
4 changes: 3 additions & 1 deletion apps/api/src/app/invites/entities/invite.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export class Invite {
@Column({ default: false, name: "is_redeemed" })
isRedeemed?: boolean

@ManyToOne(() => Group)
@ManyToOne(() => Group, {
onDelete: "CASCADE"
})
@JoinColumn({ name: "group_id" })
group: Group

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export class ReputationAccount {
@PrimaryColumn()
accountHash: string

@ManyToOne(() => Group, (group) => group.reputationAccounts)
@ManyToOne(() => Group, (group) => group.reputationAccounts, {
onDelete: "CASCADE"
})
@JoinColumn({ name: "group_id" })
group: Group
}
2 changes: 1 addition & 1 deletion apps/dashboard/.env.production
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file contains build time variables for prod env.

VITE_API_URL=https://api.bandada.appliedzkp.org
VITE_CLIENT_URL=https://client.bandada.appliedzkp.org
VITE_CLIENT_INVITES_URL=https://client.bandada.appliedzkp.org/invites/\
VITE_ETHEREUM_NETWORK=goerli
VITE_GITHUB_CLIENT_ID=6ccd7b93e84260e353f9
VITE_TWITTER_CLIENT_ID=NV82Mm85NWlSZ1llZkpLMl9vN3A6MTpjaQ
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"@chakra-ui/theme-tools": "^2.0.16",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@fontsource/ibm-plex-sans": "^4.5.13",
"@fontsource-variable/unbounded": "^5.0.5",
"@rainbow-me/rainbowkit": "^0.12.8",
"@semaphore-protocol/data": "3.10.0",
"ethers": "^5.4.7",
"framer-motion": "^10.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.8.0",
"react-icons": "^4.10.1",
"react-router-dom": "^6.8.1",
"siwe": "^1.1.6",
"wagmi": "^0.12.12"
Expand Down
32 changes: 32 additions & 0 deletions apps/dashboard/src/api/bandadaAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,38 @@ export async function updateGroup(
}
}

/**
* It generates a new API key.
* @param group The group id.
*/
export async function generateApiKey(groupId: string): Promise<string | null> {
try {
return await request(`${API_URL}/groups/${groupId}/api-key`, {
method: "PATCH"
})
} catch (error) {
console.error(error)

return null
}
}

/**
* It removes a group.
* @param groupId The group id.
*/
export async function removeGroup(groupId: string): Promise<void | null> {
try {
await request(`${API_URL}/groups/${groupId}`, {
method: "DELETE"
})
} catch (error) {
console.error(error)

return null
}
}

/**
* It returns a random string to be used as a OAuth state, to to protect against
* forgery attacks. It will be used to retrieve group, member, redirectURI and provider
Expand Down
1 change: 0 additions & 1 deletion apps/dashboard/src/api/semaphoreAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export async function getGroups(adminAddress: string): Promise<Group[] | null> {
id: group.id,
name: groupName,
treeDepth: group.merkleTree.depth,
fingerprintDuration: 3600,
members: group.members as string[],
admin: group.admin as string,
type: "on-chain"
Expand Down
17 changes: 17 additions & 0 deletions apps/dashboard/src/assets/clouds.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions apps/dashboard/src/assets/icon1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions apps/dashboard/src/assets/icon2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions apps/dashboard/src/assets/icon3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions apps/dashboard/src/assets/icon4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions apps/dashboard/src/assets/image1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit feddf9a

Please sign in to comment.