Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ui/src/layout/layout-header/avatar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,17 @@
</el-dropdown-item>
<el-dropdown-item
@click="openAbout"
v-if="hasPermission([RoleConst.ADMIN, PermissionConst.ABOUT_READ], 'OR')"
v-if="
hasPermission(
new ComplexPermission(
[RoleConst.ADMIN, RoleConst.USER, RoleConst.WORKSPACE_MANAGE],
[PermissionConst.ABOUT_READ],
[],
'OR',
),
'OR',
)
"
>
{{ $t('layout.about.title') }}
</el-dropdown-item>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is an issue with this code snippet. The second v-if condition uses a variable that is not defined:

hasPermission(new ComplexPermission([...], [...]), 'OR')

The ComplexPermission constructor takes four parameters: permissions for users/roles ([...].concat([ RoleConst.WORKSPACE_MANAGE])). However, inside the constructor call, you are only concatenating [ RoleConst.WORKSPACE_MANAGE]. This means that the permission array will be [ RoleConst.WORKSPACE_MANAGE ], which does not include any roles or permissions.

If no role/permission exists in this array, calling hasPermission(...) may result in unexpected behavior.

To correct this, ensure that all required arguments are passed correctly to new ComplexPermission(...): either both arrays (for users/roles and permissions) or one of them empty.

Here's how you can fix it:

Incorrect:

new ComplexPermission([RoleConst.ADMIN, RoleConst.USER, RoleConst.WORKSPACE_MANAGE], [PermissionConst.ABOUT_READ])

Corrected:

new ComplexPermission([
  ...[RoleConst ADMIN, RoleConst.USER]
  RoleConst.WORKSPACE_MANAGE,
],[
  PermissionConst.BLOG_DELETE,
  PermissionConst.ANNOUNCE_COMMENT_CREATE,
])

Ensure that every role or permission is added to at least one of those two arrays when using ComplexPermission.

Also, keep these considerations in mind when creating instances of complex permission classes to avoid runtime errors due to incorrect argument lengths.

Expand Down
Loading