Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const canSelectNotAuth = computed(() => props.permissionOptions.some(({ value })
/* 查询与当前页选择 */
const { auth } = useStore()
const searchPermissionOptions = computed(() =>
RESOURCE_PERMISSION_OPTIONS.filter(({ value }) => !auth.isCE || value !== RESOURCE_PERMISSION.ROLE).map(({ label, value }) => ({
RESOURCE_PERMISSION_OPTIONS.filter(({ value }) => auth.isEE || auth.isPE || value !== RESOURCE_PERMISSION.ROLE).map(({ label, value }) => ({
label,
value,
})),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The main concern is semantic equivalence, not syntax.

Potential issue

Original condition:

!auth.isCE || value !== RESOURCE_PERMISSION.ROLE

means: hide ROLE only when the edition is CE.

Changed condition:

auth.isEE || auth.isPE || value !== RESOURCE_PERMISSION.ROLE

means: show ROLE only when the edition is EE or PE.

These are equivalent only if:

  1. Every non-CE edition is exactly EE or PE.
  2. isCE, isEE, and isPE are mutually exclusive.
  3. These flags are always initialized correctly.
  4. No new edition will be added later.

If auth flags are still loading/unknown, or if a new edition is introduced, ROLE may be hidden incorrectly. Conversely, if isEE or isPE is accidentally true for a CE environment, ROLE will be shown when the original code would hide it.

Recommendation

Prefer expressing the capability directly instead of duplicating edition checks:

const canSelectRolePermission = computed(
  () => auth.isEE || auth.isPE
)

const searchPermissionOptions = computed(() =>
  RESOURCE_PERMISSION_OPTIONS
    .filter(
      ({ value }) =>
        value !== RESOURCE_PERMISSION.ROLE ||
        canSelectRolePermission.value
    )
    .map(({ label, value }) => ({ label, value }))
)

Or, if the intended rule is still “ROLE is unavailable only in CE”, keep the original logic:

const searchPermissionOptions = computed(() =>
  RESOURCE_PERMISSION_OPTIONS
    .filter(
      ({ value }) =>
        !auth.isCE || value !== RESOURCE_PERMISSION.ROLE
    )
    .map(({ label, value }) => ({ label, value }))
)

Minor notes

  • The filter().map() pattern is fine and readable.
  • The map() creates new objects on every auth-flag change, but that is usually acceptable for a small static options list.
  • Make sure auth.isEE and auth.isPE are typed and guaranteed to exist. If they can be undefined, the boolean result is still safe, but explicit typing would be clearer.
  • If options contain extra fields beyond label and value, the map() will drop them.

Overall: the syntax is valid, but the changed logic is only safe if the edition flags are guaranteed to be mutually exclusive and exhaustive.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ const folderPermissions = computed(() => {
})
const isFolder = computed(() => Boolean(folderPermissions.value && (props.isFolder || props.isRootFolder || props.type.endsWith('_FOLDER'))))
const authorizationType = computed(() => (isFolder.value ? (folderPermissions.value?.target ?? props.type) : props.type))
const permissionOptions = computed(() => RESOURCE_PERMISSION_OPTIONS.filter(({ value }) => !auth.isCE || value !== RESOURCE_PERMISSION.ROLE))
const permissionOptions = computed(() =>
RESOURCE_PERMISSION_OPTIONS.filter(({ value }) => auth.isEE || auth.isPE || value !== RESOURCE_PERMISSION.ROLE),
)
const editablePermissionOptions = computed(() =>
permissionOptions.value.filter(({ value }) => !props.isRootFolder || value !== RESOURCE_PERMISSION.NOT_AUTH),
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The diff is syntactically valid; the trailing comma is fine with Prettier/TS. The main concern is a semantic behavior change:

// Before
!auth.isCE || value !== ROLE
// Keeps ROLE for every non-CE case

// After
auth.isEE || auth.isPE || value !== ROLE
// Keeps ROLE only when isEE or isPE is true

Potential issues

  1. Behavior differs if auth.isEE and auth.isPE are both false while auth.isCE is also false

    • Example: auth flags not loaded yet, unauthenticated state, or another edition.
    • Before: ROLE was included.
    • After: ROLE is excluded.
    • This may be intentional, but it is not equivalent unless the auth state is guaranteed to always be exactly one of CE/EE/PE.
  2. Flags are assumed to be mutually exclusive

    • If auth.isCE and auth.isEE can both be true, the new code includes ROLE because auth.isEE is true, whereas the old code excluded it because auth.isCE was true.
    • If that invariant is not guaranteed, make it explicit:
    const canUseRolePermission = computed(
      () => !auth.isCE && (auth.isEE || auth.isPE),
    )
  3. If the original intent was simply “ROLE is unavailable in CE”, the original condition is clearer and safer:

    !auth.isCE || value !== RESOURCE_PERMISSION.ROLE

Suggested optimization

If the intent is “ROLE is only available in EE/PE”:

const canUseRolePermission = computed(() => auth.isEE || auth.isPE)

const permissionOptions = computed(() =>
  RESOURCE_PERMISSION_OPTIONS.filter(
    ({ value }) => canUseRolePermission.value || value !== RESOURCE_PERMISSION.ROLE,
  ),
)

If CE can coexist with EE/PE flags, use:

const canUseRolePermission = computed(
  () => !auth.isCE && (auth.isEE || auth.isPE),
)

Minor adjacent concern

isFolder assumes props.type is always a string:

props.type.endsWith('_FOLDER')

If props.type can be undefined or null, this can throw. Consider:

const isFolder = computed(() =>
  Boolean(
    folderPermissions.value &&
      (props.isFolder ||
        props.isRootFolder ||
        props.type?.endsWith('_FOLDER')),
  ),
)

Recommendation

Confirm the intended rule for ROLE. If it is “only EE/PE”, extract canUseRolePermission and add tests for CE, EE, PE, loading/unauthenticated state, and any case where multiple auth flags may be true.

Expand Down
2 changes: 1 addition & 1 deletion ui/src/layout/LayoutHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function toUrl(url?: string) {
</span>

<!-- 社区版访问升级价格页 -->
<el-button v-if="!preview && auth.isCE" class="bg-primary-gradient" round @click="toUrl('https://maxkb.cn/price')">
<el-button v-if="!preview && (auth.isCE || auth.isExpire)" class="bg-primary-gradient" round @click="toUrl('https://maxkb.cn/price')">
<MkIcon name="icon_launch_outlined" />
<span>{{ t('layout.upgrade') }}</span>
</el-button>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here's my review of the diff:

Summary of Change

The condition for displaying the "Upgrade" button was broadened from auth.isCE (community edition) to auth.isCE || auth.isExpire.

Potential Issues

  1. Logic concern — expired paid users vs. CE users

    • If auth.isExpire can be true for non-CE (i.e., paid/enterprise) subscriptions that have lapsed, this button now links all of them to the same public pricing page (maxkb.cn/price).
    • Verify this is intended: an expired Enterprise customer may need a renewal flow rather than a generic "upgrade to community" page. Consider routing expired paid users to a renewal/contact-sales URL instead.
  2. Possible overlapping states / unclear precedence

    • Is isExpire mutually exclusive with isCE? If a CE license can also be flagged as "expired" (e.g., trial), the two flags may be redundant or semantically confusing. Clarify the flag semantics and whether both should key off the same message/tooltip.
  3. Button label mismatch

    • The i18n key is layout.upgrade. For an expired user, "upgrade" may be misleading — "renew" would be clearer. Consider a different label/copy conditioned on auth.isExpire (e.g., t(auth.isExpire ? 'layout.renew' : 'layout.upgrade')).
  4. Readability

    • A compound condition inside the template is fine but consider extracting it to a computed property for testability/clarity:
      const showUpgrade = computed(() => !props.preview && (auth.isCE || auth.isExpire));
      Then <el-button v-if="showUpgrade" ...>. This is easier to unit-test and keeps the template clean.
  5. Guard against undefined

    • Confirm auth.isExpire is always defined (boolean). If it can be undefined, || still works, but ensure reactivity is set up correctly in the store so the button updates when expiry state changes.
  6. No regression on preview

    • !preview guard is preserved — good. Just confirm preview and auth are both reactive sources driving re-render.

Minor Optimization Suggestions

  • Extract to a computed for readability/testing (see feat: 添加issues 模版 #4).
  • Consider centralizing the target URL (https://maxkb.cn/price) in a constant/config rather than hardcoding in the template.
  • Add a tooltip or title distinguishing upgrade vs. renew behavior if labels remain shared.

No functional bugs jump out, but the main thing to validate with product is whether expired non-CE users should be sent to the general pricing page and whether the "Upgrade" copy is appropriate for them.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const RESOURCE_AUTHORIZATION_LABELS: Record<ResourceAuthorizationType, st

export function getPermissionOptions(): (typeof RESOURCE_PERMISSION_OPTIONS)[number][] {
const permissionOptions = RESOURCE_PERMISSION_OPTIONS
if (auth.isCE) {
if (auth.isCE || auth.isExpire) {
return permissionOptions.filter((item) => item.value !== RESOURCE_PERMISSION.ROLE)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defineOptions({ name: 'UserGroupSetting' })

const { t } = useI18n({ useScope: 'global' })
const { auth } = useStore()
const usesDefaultWorkspace = computed(() => auth.isCE || auth.isPE)
const usesDefaultWorkspace = computed(() => !auth.isEE)

const props = defineProps<{ workspaceIds: string[]; workspaceOptions: ListItem[] }>()

Expand Down
Loading