Skip to content
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

Bugfix: Readonly user attributes have no effect on group memberships #10347

Merged
merged 7 commits into from Jan 17, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,6 @@
Bugfix: Readonly user attributes have no effect on group memberships

We've fixed a bug where the entity 'user.memberOf' set via env var `FRONTEND_READONLY_USER_ATTRIBUTES`
had no effect.

https://github.com/owncloud/web/pull/10347
Expand Up @@ -8,6 +8,7 @@
option-label="displayName"
:label="$gettext('Groups')"
:fix-message-line="true"
v-bind="$attrs"
@update:model-value="onUpdate"
>
<template #selected-option="{ displayName, id }">
Expand Down
Expand Up @@ -91,6 +91,7 @@
/>
<group-select
class="oc-mb-s"
:read-only="isInputFieldReadOnly('user.memberOf')"
:selected-groups="editUser.memberOf"
:group-options="groupOptions"
@selected-option-change="changeSelectedGroupOption"
Expand Down
@@ -1,12 +1,13 @@
import { computed, Ref, unref } from 'vue'
import { useGettext } from 'vue3-gettext'
import { UserAction, useStore } from '@ownclouders/web-pkg'
import { useCapabilityReadOnlyUserAttributes, UserAction, useStore } from '@ownclouders/web-pkg'
import { Group } from '@ownclouders/web-client/src/generated'
import AddToGroupsModal from '../../../components/Users/AddToGroupsModal.vue'

export const useUserActionsAddToGroups = ({ groups }: { groups: Ref<Group[]> }) => {
const store = useStore()
const { $gettext, $ngettext } = useGettext()
const readOnlyUserAttributes = useCapabilityReadOnlyUserAttributes()

const handler = ({ resources }) => {
return store.dispatch('createModal', {
Expand Down Expand Up @@ -36,7 +37,13 @@ export const useUserActionsAddToGroups = ({ groups }: { groups: Ref<Group[]> })
componentType: 'button',
class: 'oc-users-actions-add-to-groups-trigger',
label: () => $gettext('Add to groups'),
isEnabled: ({ resources }) => resources.length > 0,
isEnabled: ({ resources }) => {
if (unref(readOnlyUserAttributes).includes('user.memberOf')) {
return false
}

return resources.length > 0
},
handler
}
])
Expand Down
@@ -1,12 +1,13 @@
import { computed, Ref, unref } from 'vue'
import { useGettext } from 'vue3-gettext'
import { UserAction, useStore } from '@ownclouders/web-pkg'
import { useCapabilityReadOnlyUserAttributes, UserAction, useStore } from '@ownclouders/web-pkg'
import { Group } from '@ownclouders/web-client/src/generated'
import RemoveFromGroupsModal from '../../../components/Users/RemoveFromGroupsModal.vue'

export const useUserActionsRemoveFromGroups = ({ groups }: { groups: Ref<Group[]> }) => {
const store = useStore()
const { $gettext, $ngettext } = useGettext()
const readOnlyUserAttributes = useCapabilityReadOnlyUserAttributes()

const handler = ({ resources }) => {
return store.dispatch('createModal', {
Expand Down Expand Up @@ -36,7 +37,13 @@ export const useUserActionsRemoveFromGroups = ({ groups }: { groups: Ref<Group[]
componentType: 'button',
class: 'oc-users-actions-remove-from-groups-trigger',
label: () => $gettext('Remove from groups'),
isEnabled: ({ resources }) => resources.length > 0,
isEnabled: ({ resources }) => {
if (unref(readOnlyUserAttributes).includes('user.memberOf')) {
return false
}

return resources.length > 0
},
handler
}
])
Expand Down
Expand Up @@ -18,7 +18,7 @@ exports[`EditPanel renders all available inputs 1`] = `
<div class="oc-text-input-message"></div>
</div>
<quota-select-stub class="oc-mb-s" description-message="" disabled="false" fix-message-line="true" id="quota-select-form" label="Personal quota" maxquota="0" read-only="false" totalquota="0"></quota-select-stub>
<group-select-stub class="oc-mb-s" groupoptions="undefined,undefined" selectedgroups=""></group-select-stub>
<group-select-stub class="oc-mb-s" groupoptions="undefined,undefined" read-only="false" selectedgroups=""></group-select-stub>
</div>
<compare-save-dialog-stub class="edit-compare-save-dialog oc-mb-l" compareobject="[object Object]" confirmbuttondisabled="false" originalobject="[object Object]"></compare-save-dialog-stub>
</form>
Expand Down
Expand Up @@ -17,6 +17,19 @@ describe('useUserActionsAddToGroups', () => {
}
})
})
it('returns false if included in capability readOnlyUserAttributes list', () => {
getWrapper({
setup: ({ actions }, { storeOptions }) => {
storeOptions.getters.capabilities.mockReturnValue({
graph: {
users: { read_only_attributes: ['user.memberOf'] }
}
})

expect(unref(actions)[0].isEnabled({ resources: [mock<User>()] })).toEqual(false)
}
})
})
})
describe('method "handler"', () => {
it('creates a modal', () => {
Expand Down
Expand Up @@ -17,6 +17,19 @@ describe('useUserActionsRemoveFromGroups', () => {
}
})
})
it('returns false if included in capability readOnlyUserAttributes list', () => {
getWrapper({
setup: ({ actions }, { storeOptions }) => {
storeOptions.getters.capabilities.mockReturnValue({
graph: {
users: { read_only_attributes: ['user.memberOf'] }
}
})

expect(unref(actions)[0].isEnabled({ resources: [mock<User>()] })).toEqual(false)
}
})
})
})
describe('method "handler"', () => {
it('creates a modal', () => {
Expand Down