-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
fix(systemtags): unify restrict_creation_to_admin handling #51288
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: skjnldsv <[email protected]>
6ef85aa
to
9f77664
Compare
Signed-off-by: skjnldsv <[email protected]>
9f77664
to
e41d716
Compare
Signed-off-by: skjnldsv <[email protected]>
Signed-off-by: skjnldsv <[email protected]>
import { elementColor, invertTextColor, isDarkModeEnabled } from '../utils/colorUtils' | ||
import { getNodeSystemTags, setNodeSystemTags } from '../utils' |
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.
import { getNodeSystemTags, setNodeSystemTags } from '../utils' | |
import { getNodeSystemTags, setNodeSystemTags } from '../utils.ts' |
@@ -204,6 +209,8 @@ export default defineComponent({ | |||
emit, | |||
Status, | |||
t, | |||
// Either tag creation is not restricted to admins or the current user is an admin | |||
canEditOrCreateTag: !restrictSystemTagsCreationToAdmin || getCurrentUser()?.isAdmin, |
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.
name clash with line 251
@@ -189,7 +189,8 @@ export default Vue.extend({ | |||
this.sortedTags.unshift(createdTag) | |||
this.selectedTags.push(createdTag) | |||
} catch (error) { | |||
if(loadState('settings', 'restrictSystemTagsCreationToAdmin', '0') === '1') { | |||
const systemTagsCreationRestrictedToAdmin = loadState<true|false>('settings', 'restrictSystemTagsCreationToAdmin', false) === true |
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.
Simple types here (should be boolean
), but those simple types are also inferred from default value (false
) so it correctly infers boolean
.
const systemTagsCreationRestrictedToAdmin = loadState<true|false>('settings', 'restrictSystemTagsCreationToAdmin', false) === true | |
const systemTagsCreationRestrictedToAdmin = loadState('settings', 'restrictSystemTagsCreationToAdmin', false) |
</p> | ||
|
||
<NcCheckboxRadioSwitch type="switch" | ||
:checked.sync="systemTagsCreationRestrictedToAdmin" | ||
@update:checked="updateSystemTagsDefault"> | ||
{{ t('settings', 'Restrict tag creation to admins only') }} | ||
{{ t('settings', 'Restrict tag edition and creation to admins only') }} |
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.
I think it is
{{ t('settings', 'Restrict tag edition and creation to admins only') }} | |
{{ t('settings', 'Restrict tag editing and creation to admins only') }} |
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.
I checked and you're right! What a weird phrazing 😁
I would even go for
{{ t('settings', 'Restrict tag edition and creation to admins only') }} | |
{{ t('settings', 'Restrict tag creation and editing to administrators only') }} |
data() { | ||
return { | ||
// By default, system tags creation is not restricted to admins | ||
systemTagsCreationRestrictedToAdmin: loadState('settings', 'restrictSystemTagsCreationToAdmin', '0') === '1', | ||
systemTagsCreationRestrictedToAdmin: loadState<true|false>('settings', 'restrictSystemTagsCreationToAdmin', false) === true, |
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.
systemTagsCreationRestrictedToAdmin: loadState<true|false>('settings', 'restrictSystemTagsCreationToAdmin', false) === true, | |
systemTagsCreationRestrictedToAdmin: loadState('settings', 'restrictSystemTagsCreationToAdmin', false), |
@@ -206,6 +208,11 @@ public function updateTag( | |||
); | |||
} | |||
|
|||
$user = $this->userSession->getUser(); | |||
if (!$this->canUserCreateTag($user)) { | |||
throw new TagUpdateForbiddenException('Tag update forbidden'); |
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.
IMHO the message is basically the exception class name, so could also drop it.
throw new TagUpdateForbiddenException('Tag update forbidden'); | |
throw new TagUpdateForbiddenException(); |
* @param IUser|null $user user to check permission for | ||
* @return bool true if the user is allowed to update a tag, false otherwise | ||
* | ||
* @since 31.0.0 |
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.
* @since 31.0.0 | |
* @since 31.0.1 |
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
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.
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | |
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
/** | ||
* Exception when a user doesn't have the right to create a tag | ||
* | ||
* @since 31.0.0 |
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.
* @since 31.0.0 | |
* @since 31.0.1 |
Fix #51233
Fix #51247
false
) and value handling asbool
(previouslystring
)