diff --git a/src/services/impl/channels/edit-channel-by-id.ts b/src/services/impl/channels/edit-channel-by-id.ts
index 0c6e47d95cfbe9559c1f008e717423219514d6a4..d99fe40ebbcc3e187ca7c5d573d8a7c34bdc4751 100644
--- a/src/services/impl/channels/edit-channel-by-id.ts
+++ b/src/services/impl/channels/edit-channel-by-id.ts
@@ -5,52 +5,32 @@ import { ForbiddenError, NotFoundError } from 'routing-controllers';
import { AuthorizationBag } from '../../../models/authorization-bag';
import { EditChannelResponse } from '../../../controllers/channels/dto';
import { CernAuthorizationService } from '../../../models/cern-authorization-service';
-// eslint-disable-next-line @typescript-eslint/no-var-requires
-const { appsignal } = require('../../../../appsignal'); // Update to the location used in the previous step
export class EditChannelById implements Command {
constructor(private channelId: string, private authorizationBag: AuthorizationBag) {}
async execute(transactionManager: EntityManager): Promise<EditChannelResponse> {
- const tracer = appsignal.tracer();
- const span = tracer.createSpan(undefined, tracer.currentSpan());
- span.setCategory('services/impl');
- span.setName('EditChannelById');
-
- let child = span.child();
- child.setCategory('findOne-channel');
const channel = await transactionManager.findOne(Channel, {
relations: ['owner', 'adminGroup', 'category', 'tags'],
where: {
id: this.channelId,
},
});
- child.close();
if (!channel) {
- span.close();
throw new NotFoundError('Channel does not exist');
}
- child = span.child();
- child.setCategory('get-user-groups');
const userGroups = await CernAuthorizationService.getCurrentUserGroups(this.authorizationBag.userName);
- child.close();
- child = span.child();
- child.setCategory('hasAdminAccess');
- if (!(await channel.hasAdminAccess(transactionManager, this.authorizationBag, userGroups))) {
- child.close();
- span.close();
- throw new ForbiddenError('Access to Channel not Authorized !');
+ const hasAdminAccess = async (): Promise<boolean> => {
+ return await channel.hasAdminAccess(transactionManager, this.authorizationBag, userGroups);
+ };
+
+ if (this.authorizationBag.isSupporter || (await hasAdminAccess())) {
+ return new EditChannelResponse(channel);
}
- child.close();
- child = span.child();
- child.setCategory('creating-dto');
- const returnDto = new EditChannelResponse(channel);
- child.close();
- span.close();
- return returnDto;
+ throw new ForbiddenError('Access to Channel not Authorized !');
}
}