from flask import g from auth.auth_view import RegisteredAuthorizedView from labels.labels_permissions_service import LabelPermissionsService from flask_apispec import marshal_with, doc from labels.schemas import team_member_permissions_response, label_permissions_counter_response from services.users_repository import UsersRepository from utils.exceptions import NotFound @doc(tags=['LabelPermissions']) class LabelPermissionsTeamMembersView(RegisteredAuthorizedView): label_permissions_service = LabelPermissionsService() users_repository = UsersRepository() @doc(description='Retrieve label permissions team members') @marshal_with( team_member_permissions_response(many=True), code=200, description="List of team members permission for label" ) @marshal_with(None, code=403, description='User does not have access to the label.') @marshal_with(None, code=404, description='Label not found') def get(self, label_id): if not self.users_repository.is_label_exists(label_id): raise NotFound(f"Label with id {label_id} not exist.") self.permissions.can_access_label(label_id) return self.label_permissions_service.get_team_members_permissions(user_id=g.user_id, label_id=label_id) @doc(tags=['LabelPermissions']) class LabelPermissionsCountersView(RegisteredAuthorizedView): label_permissions_service = LabelPermissionsService() users_repository = UsersRepository() @doc(description='Retrieve label permissions counters') @marshal_with( label_permissions_counter_response, code=200, description="Label permissions counters for label" ) @marshal_with(None, code=403, description='User does not have access to the label.') @marshal_with(None, code=404, description='Label not found') def get(self, label_id): if not self.users_repository.is_label_exists(label_id): raise NotFound(f"Label with id {label_id} not exist.") self.permissions.can_access_label(label_id) return self.label_permissions_service.get_label_permissions_counters(label_id)