Example #1
0
 def _get_organization_for_superuser(self, organization_slug):
     try:
         return Organization.objects.get(slug=organization_slug)
     except Organization.DoesNotExist:
         error_message = f"Organization '{organization_slug}' does not exist."
         raise ValidationError(
             {"organization": to_single_line_str(error_message)})
Example #2
0
 def _get_organization_slug(self, request: Request):
     organization_slug = request.json_body.get("organization")
     if not organization_slug or not isinstance(organization_slug, str):
         error_message = "Please provide a valid value for the 'organization' field."
         raise ValidationError(
             {"organization": to_single_line_str(error_message)})
     return organization_slug
Example #3
0
 def _get_organization_for_user(self, user, organization_slug):
     try:
         return user.get_orgs().get(slug=organization_slug)
     except Organization.DoesNotExist:
         error_message = """
             User does not belong to the '{}' organization.
         """.format(organization_slug)
         raise PermissionDenied(to_single_line_str(error_message))