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
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
['name' => 'Config#deleteRule', 'url' => '/rule/{id}', 'verb' => 'DELETE'],
['name' => 'Config#createRule', 'url' => '/rule', 'verb' => 'POST'],
['name' => 'Config#createTag', 'url' => '/tag', 'verb' => 'POST'],
['name' => 'Config#getTags', 'url' => '/tags', 'verb' => 'GET'],
],
'ocs' => [
/**
Expand Down
10 changes: 10 additions & 0 deletions lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public function createTag(string $name): DataResponse {
}
}

/**
* List all tags
*
* @return DataResponse
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
public function getTags(): DataResponse {
return new DataResponse($this->utilsService->getTags());
}

/**
*
* @return DataResponse
Expand Down
16 changes: 16 additions & 0 deletions lib/Service/UtilsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\IUserManager;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\TagAlreadyExistsException;
use OCP\SystemTag\TagNotFoundException;
Expand Down Expand Up @@ -174,4 +175,19 @@ public function deleteTag(int $id): array {
return ['error' => 'Tag not found'];
}
}

/**
* @return array
*/
public function getTags(): array {
return array_values(array_map(static function (ISystemTag $tag): array {
return [
'id' => $tag->getId(),
'displayName' => $tag->getName(),
'canAssign' => $tag->getAccessLevel() === ISystemTag::ACCESS_LEVEL_PUBLIC,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't canAssign express if the current user can assign this tag? Currently is expressed if the tag is public. Might be fine, just curious.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

public tags are the only ones that can be assigned by any user. The wording isn't great though. I don't remember exactly why I chose that wording. It might have to do with the NcSelectTags component.

'userAssignable' => $tag->isUserAssignable(),
'userVisible' => $tag->isUserVisible(),
];
}, $this->tagManager->getAllTags()));
}
}
7 changes: 6 additions & 1 deletion lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@
namespace OCA\Approval\Settings;

use OCA\Approval\AppInfo\Application;
use OCA\Approval\Service\UtilsService;
use OCP\AppFramework\Http\TemplateResponse;

use OCP\AppFramework\Services\IInitialState;
use OCP\Settings\IDelegatedSettings;

class Admin implements IDelegatedSettings {

public function __construct(
private string $appName,
private IInitialState $initialStateProvider,
private UtilsService $utilsService,
) {
}

/**
* @return TemplateResponse
*/
public function getForm(): TemplateResponse {
$tags = $this->utilsService->getTags();
$this->initialStateProvider->provideInitialState('tags', $tags);
return new TemplateResponse(Application::APP_ID, 'adminSettings');
}

Expand Down
21 changes: 16 additions & 5 deletions src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<ApprovalRule v-for="(rule, id) in rules"
:key="id"
v-model:value="rules[id]"
:tags="tags"
class="approval-rule"
@input="onRuleInput(id, $event)"
@add-tag="onAddTagClick">
Expand All @@ -54,6 +55,7 @@
<div v-if="newRule" class="new-rule">
<ApprovalRule
v-model:value="newRule"
:tags="tags"
:delete-rule-label="newRuleDeleteLabel"
:focus="true"
@add-tag="onAddTagClick">
Expand Down Expand Up @@ -127,6 +129,7 @@ import ApprovalRule from './ApprovalRule.vue'
import { generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import { showSuccess, showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'

export default {
name: 'AdminSettings',
Expand All @@ -145,6 +148,7 @@ export default {

data() {
return {
tags: loadState('approval', 'tags'),
showRules: true,
newTagName: '',
rules: {},
Expand Down Expand Up @@ -206,6 +210,17 @@ export default {
},

methods: {
loadTags() {
const url = generateUrl('/apps/approval/tags')
axios.get(url).then((response) => {
this.tags = response.data
}).catch((error) => {
showError(
t('approval', 'Failed to load tags'),
)
console.error(error)
})
Comment thread
lukasdotcom marked this conversation as resolved.
},
loadRules() {
this.loadingRules = true
const url = generateUrl('/apps/approval/rules')
Expand Down Expand Up @@ -354,11 +369,7 @@ export default {
axios.post(url, req).then((response) => {
showSuccess(t('approval', 'Tag "{name}" created', { name: this.newTagName }))
this.newTagName = ''
// trick to reload tag list
this.showRules = false
this.$nextTick(() => {
this.showRules = true
})
this.loadTags()
}).catch((error) => {
showError(
t('approval', 'Failed to create tag "{name}"', { name: this.newTagName })
Expand Down
45 changes: 30 additions & 15 deletions src/components/ApprovalRule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
</span>
<NcSelectTags
class="tag-select"
:model-value="tagPendingAsString"
:options="tags"
:fetch-tags="false"
:model-value="value.tagPending"
:placeholder="t('approval', 'Select pending tag')"
:multiple="false"
:close-on-select="true"
Expand All @@ -39,6 +41,10 @@
:aria-label-combobox="pendingLabel"
:limit="null"
@update:model-value="update('tagPending', $event)" />
<NcNoteCard
v-if="isTagPublic(value.tagPending)"
:text="t('approval', 'Anyone can assign this tag and start this approval rule.')"
type="warning" />
</div>
<div class="users">
<span class="field-label">
Expand Down Expand Up @@ -82,14 +88,20 @@
</span>
<NcSelectTags
class="tag-select"
:model-value="tagApprovedAsString"
:options="tags"
:fetch-tags="false"
:model-value="value.tagApproved"
:placeholder="t('approval', 'Select approved tag')"
:multiple="false"
:close-on-select="true"
:clear-search-on-select="true"
:aria-label-combobox="approvedLabel"
:limit="null"
@update:model-value="update('tagApproved', $event)" />
<NcNoteCard
v-if="isTagPublic(value.tagApproved)"
:text="t('approval', 'Anyone can assign this tag and approve a file.')"
type="warning" />
</div>
<div class="tag">
<span class="field-label">
Expand All @@ -105,14 +117,20 @@
</span>
<NcSelectTags
class="tag-select"
:model-value="tagRejectedAsString"
:options="tags"
:fetch-tags="false"
:model-value="value.tagRejected"
:placeholder="t('approval', 'Select rejected tag')"
:multiple="false"
:close-on-select="true"
:clear-search-on-select="true"
:aria-label-combobox="rejectedLabel"
:limit="null"
@update:model-value="update('tagRejected', $event)" />
<NcNoteCard
v-if="isTagPublic(value.tagRejected)"
:text="t('approval', 'Anyone can assign this tag and reject a file.')"
type="warning" />
</div>
<div class="checkbox">
<NcFormBoxSwitch
Expand All @@ -135,6 +153,7 @@ import TagIcon from 'vue-material-design-icons/Tag.vue'

import NcSelectTags from '@nextcloud/vue/components/NcSelectTags'
import NcFormBoxSwitch from '@nextcloud/vue/components/NcFormBoxSwitch'
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'

import { delay } from '../utils.js'
import MultiselectWho from './MultiselectWho.vue'
Expand All @@ -149,6 +168,7 @@ export default {
NcSelectTags,
TagIcon,
NcFormBoxSwitch,
NcNoteCard,
},

props: {
Expand All @@ -160,6 +180,10 @@ export default {
type: Boolean,
default: false,
},
tags: {
type: Array,
required: true,
},
},

emits: ['add-tag', 'input', 'update:value'],
Expand All @@ -180,18 +204,6 @@ export default {
}
},

computed: {
tagPendingAsString() {
return parseInt(this.value.tagPending, 10)
},
tagApprovedAsString() {
return parseInt(this.value.tagApproved, 10)
},
tagRejectedAsString() {
return parseInt(this.value.tagRejected, 10)
},
},

watch: {},

mounted() {
Expand All @@ -201,6 +213,9 @@ export default {
},

methods: {
isTagPublic(tagId) {
return this.tags.find((tag) => tag.id === tagId)?.canAssign
},
resetFocus() {
this.$refs.title.focus()
},
Expand Down
Loading