from utils.exceptions import NotFound, Forbidden, UnprocessableEntity from typing import Optional class ProjectCreationRestricted(Forbidden): """Raised in attempt to create a project in a label user not belong to.""" code = "project_creation_restricted" detail = "You don't have permission to create projects in this label." class ArtistTeamNotFound(NotFound): code = "artist team not found" detail = "Artist team not found" class CampaignNotFound(NotFound): code = "campaign_not_found" detail = "Campaign not found" class ProjectNotFound(NotFound): code = "project_not_found" detail = "Project not found" class PhaseNotFound(NotFound): code = "phase_not_found" detail = "Phase not found" class MediaPlanNotFound(NotFound): code = "media_plan_not_found" detail = "Media Plan not found" class MediaPlanSameNameError(Forbidden): code = "media_plan_with_same_name" detail = "Each media plan in project must have unique name" class MediaPlanNameValidationError(Forbidden): code = "media_plan_name_validation_error" detail = "Media plan forbidden name" class MediaPlanMaxNumberExceed(Forbidden): code = "media_plan_max_number_exceed" detail = "Maximum number of media plans for this project exceeded" class UserNotFound(NotFound): code = "user_not_found" detail = "User not found" class DataHealthNotAvailable(NotFound): code = "data_health_not_available" detail = "data health not available" class BaseProjectRestrictedError(Forbidden): """ Base exception to do some action with a project without a proper permission. Project owner contacts will be returned to request an access if needed. """ def __init__(self, data: Optional[dict] = None): self.detail = data class UnclaimnedProjectAccessRestricted(BaseProjectRestrictedError): """Raised in attempt to access an unclaimed project without permission.""" code = "unclaimed_project_access_restricted" class ProjectAccessRestricted(BaseProjectRestrictedError): """Raised in attempt to access a project without permission.""" code = "project_access_restricted" class ConfidentialProjectRestricted(Forbidden): """Raised in attempt to access a confidential project without admin permission.""" code = "confidential_project_access_restricted" class ArtistTeamCreationRestricted(Forbidden): """Raised in attempt to create an artist team without permission.""" code = "artist_team_creation_restricted" detail = "Only Label Admin can create Artist Team" class ArtistTeamEditingRestricted(Forbidden): """Raised in attempt to edit an artist team without permission.""" code = "artist_team_editing_restricted" detail = "Only Label Admin or owner of Artist Team can edit Artist Team" class ProjectEditingRestricted(BaseProjectRestrictedError): """Raised in attempt to edit any project data without permission.""" code = "project_edit_restricted" class ProjectDeletionRestricted(BaseProjectRestrictedError): """Raised in attempt to delete a project without permission.""" code = "project_delete_restricted" class CampaignCreationRestricted(BaseProjectRestrictedError): """Raised in attempt to create a campaign without permission.""" code = "campaign_creation_restricted" class CampaignEditingRestricted(BaseProjectRestrictedError): """Raised in attempt to edit a campaign without permission.""" code = "campaign_edit_restricted" class CampaignDeletionRestricted(BaseProjectRestrictedError): """Raised in attempt to delete a campaign without permission.""" code = "campaign_delete_restricted" class ProjectViewTeamRestricted(BaseProjectRestrictedError): """Raised in attempt to view a project team without permission.""" code = "team_view_restricted" class ProjectManageTeamRestricted(BaseProjectRestrictedError): """Raised in attempt to change a project team without permission.""" code = "team_edit_restricted" class UnassignedProjectClaimRestricted(Forbidden): """Raised in attempt to claim ownership for already claimed project""" code = "unassigned_project_claim_restricted" detail = "You can't claim ownership for this project." class NotApprovedCampaignEditRestricted(Forbidden): """Raised in attempt to edit not approved campaign""" code = "not_approved_campaign_edit_restricted" detail = "You can't edit not approved campaign." class AssignCampaignRestricted(Forbidden): """Raised in attempt to assign the campaign without permission.""" code = "assign_campaign_restricted" detail = "You can't assign campaign to this project." class UserHasNoAccessToLabel(Forbidden): """Raised in attempt to update something linked to a specific label""" code = "access_to_label_restricted" detail = "You can't access this label." class UserIsNotAnApprover(Forbidden): """Raised when user is trying to submit a media plan review while not being an approver""" code = "user_is_not_an_approver" detail = "User is not an approver." class LabelNotFound(Forbidden): code = "label_not_found" detail = "Label not found" class ArtistsValidationError(UnprocessableEntity): code = "artists_validation_error" def __init__(self, detail): self.detail = detail class UsersValidationError(UnprocessableEntity): code = "users_validation_error" def __init__(self, detail): self.detail = detail class UnassignedCampaignAccessRestricted(Forbidden): code = "unassigned_campaign_access_restricted" detail = "You can't access this campaign"