-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Archer <[email protected]> Co-authored-by: Finley Ge <[email protected]>
- Loading branch information
Showing
109 changed files
with
2,290 additions
and
1,090 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
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,12 @@ | ||
import { PermissionValueType } from '../../support/permission/type'; | ||
|
||
export type UpdateAppCollaboratorBody = { | ||
appId: string; | ||
tmbIds: string[]; | ||
permission: PermissionValueType; | ||
}; | ||
|
||
export type AppCollaboratorDeleteParams = { | ||
appId: string; | ||
tmbId: string; | ||
}; |
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,20 @@ | ||
import { NullPermission, PermissionKeyEnum, PermissionList } from '../constant'; | ||
import { PermissionListType } from '../type'; | ||
|
||
export enum AppPermissionKeyEnum {} | ||
export const AppPermissionList: PermissionListType = { | ||
[PermissionKeyEnum.read]: { | ||
...PermissionList[PermissionKeyEnum.read], | ||
description: '可使用该应用进行对话' | ||
}, | ||
[PermissionKeyEnum.write]: { | ||
...PermissionList[PermissionKeyEnum.write], | ||
description: '可查看和编辑应用' | ||
}, | ||
[PermissionKeyEnum.manage]: { | ||
...PermissionList[PermissionKeyEnum.manage], | ||
description: '写权限基础上,可配置发布渠道、查看对话日志、分配该应用权限' | ||
} | ||
}; | ||
|
||
export const AppDefaultPermission = NullPermission; |
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,15 @@ | ||
import { PerConstructPros, Permission } from '../controller'; | ||
import { AppDefaultPermission } from './constant'; | ||
|
||
export class AppPermission extends Permission { | ||
constructor(props?: PerConstructPros) { | ||
if (!props) { | ||
props = { | ||
per: AppDefaultPermission | ||
}; | ||
} else if (!props?.per) { | ||
props.per = AppDefaultPermission; | ||
} | ||
super(props); | ||
} | ||
} |
Empty file.
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,9 @@ | ||
import { PermissionValueType } from './type'; | ||
|
||
export type CollaboratorItemType = { | ||
teamId: string; | ||
tmbId: string; | ||
permission: PermissionValueType; | ||
name: string; | ||
avatar: string; | ||
}; |
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,71 @@ | ||
import { PermissionValueType } from './type'; | ||
import { PermissionList, NullPermission, OwnerPermissionVal } from './constant'; | ||
|
||
export type PerConstructPros = { | ||
per?: PermissionValueType; | ||
isOwner?: boolean; | ||
}; | ||
|
||
// the Permission helper class | ||
export class Permission { | ||
value: PermissionValueType; | ||
isOwner: boolean; | ||
hasManagePer: boolean; | ||
hasWritePer: boolean; | ||
hasReadPer: boolean; | ||
|
||
constructor(props?: PerConstructPros) { | ||
const { per = NullPermission, isOwner = false } = props || {}; | ||
if (isOwner) { | ||
this.value = OwnerPermissionVal; | ||
} else { | ||
this.value = per; | ||
} | ||
|
||
this.isOwner = isOwner; | ||
this.hasManagePer = this.checkPer(PermissionList['manage'].value); | ||
this.hasWritePer = this.checkPer(PermissionList['write'].value); | ||
this.hasReadPer = this.checkPer(PermissionList['read'].value); | ||
} | ||
|
||
// add permission(s) | ||
// it can be chaining called. | ||
// @example | ||
// const perm = new Permission(permission) | ||
// perm.add(PermissionList['read']) | ||
// perm.add(PermissionList['read'], PermissionList['write']) | ||
// perm.add(PermissionList['read']).add(PermissionList['write']) | ||
addPer(...perList: PermissionValueType[]) { | ||
for (let oer of perList) { | ||
this.value = this.value | oer; | ||
} | ||
this.updatePermissions(); | ||
return this.value; | ||
} | ||
|
||
removePer(...perList: PermissionValueType[]) { | ||
for (let per of perList) { | ||
this.value = this.value & ~per; | ||
} | ||
this.updatePermissions(); | ||
return this.value; | ||
} | ||
|
||
checkPer(perm: PermissionValueType): boolean { | ||
// if the permission is owner permission, only owner has this permission. | ||
if (perm === OwnerPermissionVal) { | ||
return this.value === OwnerPermissionVal; | ||
} else if (this.hasManagePer) { | ||
// The manager has all permissions except the owner permission | ||
return true; | ||
} | ||
return (this.value & perm) === perm; | ||
} | ||
|
||
private updatePermissions() { | ||
this.isOwner = this.value === OwnerPermissionVal; | ||
this.hasManagePer = this.checkPer(PermissionList['manage'].value); | ||
this.hasWritePer = this.checkPer(PermissionList['write'].value); | ||
this.hasReadPer = this.checkPer(PermissionList['read'].value); | ||
} | ||
} |
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,16 @@ | ||
import { PermissionKeyEnum, PermissionList, ReadPermissionVal } from '../constant'; | ||
|
||
export const TeamPermissionList = { | ||
[PermissionKeyEnum.read]: { | ||
...PermissionList[PermissionKeyEnum.read] | ||
}, | ||
[PermissionKeyEnum.write]: { | ||
...PermissionList[PermissionKeyEnum.write] | ||
}, | ||
[PermissionKeyEnum.manage]: { | ||
...PermissionList[PermissionKeyEnum.manage], | ||
description: '可邀请, 删除成员' | ||
} | ||
}; | ||
|
||
export const TeamDefaultPermissionVal = ReadPermissionVal; |
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,15 @@ | ||
import { PerConstructPros, Permission } from '../controller'; | ||
import { TeamDefaultPermissionVal } from './constant'; | ||
|
||
export class TeamPermission extends Permission { | ||
constructor(props?: PerConstructPros) { | ||
if (!props) { | ||
props = { | ||
per: TeamDefaultPermissionVal | ||
}; | ||
} else if (!props?.per) { | ||
props.per = TeamDefaultPermissionVal; | ||
} | ||
super(props); | ||
} | ||
} |
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
Oops, something went wrong.