mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-26 05:19:05 +01:00
handle tag management based on role
This commit is contained in:
parent
d7a8bbf40b
commit
fe35313305
@ -104,8 +104,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
$: allTagsFiltered = ($initialized, fuzzySearchTags(filterTerm, allTags));
|
$: allTagsFiltered = ($initialized, fuzzySearchTags(filterTerm, allTags));
|
||||||
$: usedTagsFiltered = matchJobTags(jobTags, allTagsFiltered, 'used');
|
$: usedTagsFiltered = matchJobTags(jobTags, allTagsFiltered, 'used', isAdmin);
|
||||||
$: unusedTagsFiltered = matchJobTags(jobTags, allTagsFiltered, 'unused');
|
$: unusedTagsFiltered = matchJobTags(jobTags, allTagsFiltered, 'unused', isAdmin);
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
newTagType = "";
|
newTagType = "";
|
||||||
@ -117,12 +117,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchJobTags(tags, availableTags, type) {
|
function matchJobTags(tags, availableTags, type, isAdmin) {
|
||||||
const jobTagIds = tags.map((t) => t.id)
|
const jobTagIds = tags.map((t) => t.id)
|
||||||
if (type == 'used') {
|
if (type == 'used') {
|
||||||
return availableTags.filter((at) => jobTagIds.includes(at.id))
|
return availableTags.filter((at) => jobTagIds.includes(at.id))
|
||||||
} else if (type == 'unused') {
|
} else if (type == 'unused' && isAdmin) {
|
||||||
return availableTags.filter((at) => !jobTagIds.includes(at.id))
|
return availableTags.filter((at) => !jobTagIds.includes(at.id))
|
||||||
|
} else if (type == 'unused' && !isAdmin) { // Normal Users should not see unused global tags here
|
||||||
|
return availableTags.filter((at) => !jobTagIds.includes(at.id) && at.scope !== "global")
|
||||||
}
|
}
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
@ -209,13 +211,34 @@
|
|||||||
{#if pendingChange === utag.id}
|
{#if pendingChange === utag.id}
|
||||||
<Spinner size="sm" secondary />
|
<Spinner size="sm" secondary />
|
||||||
{:else}
|
{:else}
|
||||||
<Button
|
{#if utag.scope === 'global' || utag.scope === 'admin'}
|
||||||
size="sm"
|
{#if isAdmin}
|
||||||
color="danger"
|
<Button
|
||||||
on:click={() => removeTagFromJob(utag)}
|
size="sm"
|
||||||
>
|
color="danger"
|
||||||
<Icon name="x" />
|
on:click={() => removeTagFromJob(utag)}
|
||||||
</Button>
|
>
|
||||||
|
<Icon name="x" />
|
||||||
|
</Button>
|
||||||
|
{:else}
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
color="dark"
|
||||||
|
outline
|
||||||
|
disabled
|
||||||
|
>
|
||||||
|
Global Tag
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
color="danger"
|
||||||
|
on:click={() => removeTagFromJob(utag)}
|
||||||
|
>
|
||||||
|
<Icon name="x" />
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
</ListGroupItem>
|
</ListGroupItem>
|
||||||
@ -245,13 +268,25 @@
|
|||||||
{#if pendingChange === uutag.id}
|
{#if pendingChange === uutag.id}
|
||||||
<Spinner size="sm" secondary />
|
<Spinner size="sm" secondary />
|
||||||
{:else}
|
{:else}
|
||||||
<Button
|
{#if uutag.scope === 'global' || uutag.scope === 'admin'}
|
||||||
size="sm"
|
{#if isAdmin}
|
||||||
color="success"
|
<Button
|
||||||
on:click={() => addTagToJob(uutag)}
|
size="sm"
|
||||||
>
|
color="success"
|
||||||
<Icon name="plus" />
|
on:click={() => addTagToJob(uutag)}
|
||||||
</Button>
|
>
|
||||||
|
<Icon name="plus" />
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
color="success"
|
||||||
|
on:click={() => addTagToJob(uutag)}
|
||||||
|
>
|
||||||
|
<Icon name="plus" />
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
</ListGroupItem>
|
</ListGroupItem>
|
||||||
@ -345,13 +380,25 @@
|
|||||||
{#if pendingChange === utag.id}
|
{#if pendingChange === utag.id}
|
||||||
<Spinner size="sm" secondary />
|
<Spinner size="sm" secondary />
|
||||||
{:else}
|
{:else}
|
||||||
<Button
|
{#if utag.scope === 'global' || utag.scope === 'admin'}
|
||||||
size="sm"
|
{#if isAdmin}
|
||||||
color="danger"
|
<Button
|
||||||
on:click={() => removeTagFromJob(utag)}
|
size="sm"
|
||||||
>
|
color="danger"
|
||||||
<Icon name="x" />
|
on:click={() => removeTagFromJob(utag)}
|
||||||
</Button>
|
>
|
||||||
|
<Icon name="x" />
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
color="danger"
|
||||||
|
on:click={() => removeTagFromJob(utag)}
|
||||||
|
>
|
||||||
|
<Icon name="x" />
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
</ListGroupItem>
|
</ListGroupItem>
|
||||||
@ -381,13 +428,25 @@
|
|||||||
{#if pendingChange === uutag.id}
|
{#if pendingChange === uutag.id}
|
||||||
<Spinner size="sm" secondary />
|
<Spinner size="sm" secondary />
|
||||||
{:else}
|
{:else}
|
||||||
<Button
|
{#if uutag.scope === 'global' || uutag.scope === 'admin'}
|
||||||
size="sm"
|
{#if isAdmin}
|
||||||
color="success"
|
<Button
|
||||||
on:click={() => addTagToJob(uutag)}
|
size="sm"
|
||||||
>
|
color="success"
|
||||||
<Icon name="plus" />
|
on:click={() => addTagToJob(uutag)}
|
||||||
</Button>
|
>
|
||||||
|
<Icon name="plus" />
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
color="success"
|
||||||
|
on:click={() => addTagToJob(uutag)}
|
||||||
|
>
|
||||||
|
<Icon name="plus" />
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
</ListGroupItem>
|
</ListGroupItem>
|
||||||
|
Loading…
Reference in New Issue
Block a user