-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: permission-related actions #38
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cf5a123
feat: basic actions for permissions
daichen-daisy 474ee39
feat: make permission detail page
daichen-daisy 875f363
feat: bind/unbind a permission's roles
daichen-daisy 4db03ab
feat: unbind roles or orgs in the user profile page
daichen-daisy 1f0e88e
pref: minor changes for user experience
daichen-daisy 0e0b4fc
crf use .go(0) instead of refreshing the whole page
daichen-daisy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,142 @@ | ||
import { api } from 'boot/axios'; | ||
import { Dialog } from 'quasar'; | ||
|
||
import ConfirmDialog from 'components/dialog/ConfirmDialog.vue'; | ||
import { Permission } from 'pages/permission/type'; | ||
import { Role } from 'pages/role/type'; | ||
|
||
import { PermOperationsType } from './type'; | ||
|
||
export const PermOperationsMixin: PermOperationsType = { | ||
methods: { | ||
togglePermissionsStatus( | ||
permissions: Permission[], | ||
isDeleted: boolean, | ||
handler?: (...args: [string]) => void | ||
) { | ||
const permissionDesc = `【${permissions[0].name}】${ | ||
permissions.length > 1 ? `等 ${permissions.length} 个权限` : '' | ||
}`; | ||
const content = isDeleted | ||
? `您正在请求禁用${permissionDesc}。操作后,该权限对应资源将无法被外界所获取,即使是已经关联了该权限的主体。` | ||
: `您正在请求启用${permissionDesc}。操作后,拥有该权限的主体将重新获取该权限所对应的资源。`; | ||
|
||
Dialog.create({ | ||
component: ConfirmDialog, | ||
componentProps: { | ||
title: isDeleted ? '禁用权限' : '启用权限', | ||
content: content, | ||
buttons: [ | ||
{ label: '取消', class: 'secondary-btn' }, | ||
{ | ||
label: isDeleted ? '禁用' : '启用', | ||
actionType: 'toggle', | ||
class: 'accent-btn', | ||
}, | ||
], | ||
}, | ||
}).onOk(async ({ type }) => { | ||
if (type === 'toggle') { | ||
try { | ||
await api.put( | ||
'/permissions/status', | ||
{ | ||
ids: permissions.map((p: Permission) => p.id), | ||
is_deleted: isDeleted, | ||
}, | ||
{ successMsg: `${isDeleted ? '禁用' : '启用'}权限成功` } | ||
); | ||
} finally { | ||
if (handler) { | ||
handler(isDeleted ? 'disable' : 'enable'); | ||
} | ||
} | ||
} | ||
}); | ||
}, | ||
|
||
deletePermissions( | ||
permissions: Permission[], | ||
handler?: (...args: [string]) => void | ||
) { | ||
const permissionDesc = `【${permissions[0].name}】${ | ||
permissions.length > 1 ? `等 ${permissions.length} 个权限` : '' | ||
}`; | ||
|
||
Dialog.create({ | ||
component: ConfirmDialog, | ||
componentProps: { | ||
title: '删除权限', | ||
content: `您正在请求删除${permissionDesc}。数据删除后将无法进行恢复,您确认要继续删除吗?`, | ||
buttons: [ | ||
{ label: '取消', class: 'secondary-btn' }, | ||
{ | ||
label: '删除', | ||
actionType: 'delete', | ||
class: 'accent-btn', | ||
}, | ||
], | ||
}, | ||
}).onOk(async ({ type }) => { | ||
if (type === 'delete') { | ||
try { | ||
await api.request({ | ||
method: 'DELETE', | ||
url: '/permissions', | ||
data: { ids: permissions.map((u: Permission) => u.id) }, | ||
successMsg: '删除权限成功', | ||
}); | ||
} finally { | ||
if (handler) { | ||
handler('delete'); | ||
} | ||
} | ||
} | ||
}); | ||
}, | ||
|
||
unbindRoles( | ||
permission: Permission, | ||
roles: Role[], | ||
handler?: (...args: [string]) => void | ||
) { | ||
const roleDesc = `【${roles[0].name}】${ | ||
roles.length > 1 ? `等 ${roles.length} 个角色` : '' | ||
}`; | ||
|
||
Dialog.create({ | ||
component: ConfirmDialog, | ||
componentProps: { | ||
title: '移除角色', | ||
content: `您正在请求解除角色${roleDesc}与当前权限的关联,该操作不会影响角色与其他权限的关联。`, | ||
buttons: [ | ||
{ label: '取消', class: 'secondary-btn' }, | ||
{ | ||
label: '解除关系', | ||
actionType: 'unbind', | ||
class: 'accent-btn', | ||
}, | ||
], | ||
}, | ||
}).onOk(async ({ type }) => { | ||
if (type === 'unbind') { | ||
try { | ||
await api.request({ | ||
method: 'POST', | ||
url: '/permissions/unbind_roles', | ||
data: { | ||
role_ids: roles.map((r: Role) => r.id), | ||
permission_ids: [permission.id], | ||
}, | ||
successMsg: '移除角色成功', | ||
}); | ||
} finally { | ||
if (handler) { | ||
handler('unbind'); | ||
} | ||
} | ||
} | ||
}); | ||
}, | ||
}, | ||
}; |
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,21 @@ | ||
import { Permission } from 'pages/permission/type'; | ||
import { Role } from 'pages/role/type'; | ||
|
||
export interface PermOperationsType { | ||
methods: { | ||
togglePermissionsStatus: ( | ||
permissions: Permission[], | ||
isDeleted: boolean, | ||
handler?: (...args: [string]) => void | ||
) => void; | ||
deletePermissions: ( | ||
permissions: Permission[], | ||
handler?: (...args: [string]) => void | ||
) => void; | ||
unbindRoles: ( | ||
permission: Permission, | ||
roles: Role[], | ||
handler?: (...args: [string]) => void | ||
) => void; | ||
}; | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use
$router.go(0)
to reload therouter-view
(page component) without refreshing the entire page.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 0e0b4fc