Browse Source

refactor

pull/5287/head
Attila Cseh 3 weeks ago
parent
commit
bba57a98f5
  1. 23
      apps/api/src/app/import/import.service.ts

23
apps/api/src/app/import/import.service.ts

@ -302,6 +302,15 @@ export class ImportService {
if (tagsDto?.length) { if (tagsDto?.length) {
const existingTags = await this.tagService.getTagsForUser(user.id); const existingTags = await this.tagService.getTagsForUser(user.id);
const canCreateTag = hasPermission(
user.permissions,
permissions.createTag
);
const canCreateOwnTag = hasPermission(
user.permissions,
permissions.createOwnTag
);
for (const tag of tagsDto) { for (const tag of tagsDto) {
// Check if there is any existing tag // Check if there is any existing tag
const existingTag = existingTags.find(({ name }) => { const existingTag = existingTags.find(({ name }) => {
@ -309,19 +318,7 @@ export class ImportService {
}); });
// If there is no tag or if the tag belongs to a different user, then create a new tag // If there is no tag or if the tag belongs to a different user, then create a new tag
if ( if (!existingTag || existingTag.userId !== user.id) {
!existingTag ||
(existingTag.userId && existingTag.userId !== user.id)
) {
const canCreateTag = hasPermission(
user.permissions,
permissions.createTag
);
const canCreateOwnTag = hasPermission(
user.permissions,
permissions.createOwnTag
);
if (!canCreateTag && !canCreateOwnTag) { if (!canCreateTag && !canCreateOwnTag) {
throw new Error('User does not have permission to create tags'); throw new Error('User does not have permission to create tags');
} }

Loading…
Cancel
Save