Skip to content

Commit

Permalink
Formatting file using linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ericosta-dev committed Aug 28, 2024
1 parent 9c98888 commit 467b1bb
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions connect/api/v2/organizations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Meta:
"is_suspended",
"extra_integration",
"enforce_2fa",
'show_chat_help'
"show_chat_help",
]
ref_name = None

Expand Down Expand Up @@ -90,7 +90,9 @@ def create(self, validated_data):
instance = super(OrganizationSeralizer, self).create(validated_data)
user = self.context["request"].user

authorizations = self.context["request"].data.get("organization").get("authorizations")
authorizations = (
self.context["request"].data.get("organization").get("authorizations")
)

if settings.CREATE_AI_ORGANIZATION:
created, data = instance.create_ai_organization(user.email)
Expand All @@ -111,11 +113,11 @@ def get_authorization(self, obj):
).data
return data

def create_authorizations(self, instance: Organization, authorizations: list, user: User):
def create_authorizations(
self, instance: Organization, authorizations: list, user: User
):
# Create authorization for the organization owner
instance.authorizations.create(
user=user, role=OrganizationRole.ADMIN.value
)
instance.authorizations.create(user=user, role=OrganizationRole.ADMIN.value)

instance.send_email_organization_create()

Expand All @@ -125,15 +127,17 @@ def create_authorizations(self, instance: Organization, authorizations: list, us
email=authorization.get("user_email"),
organization=instance,
role=authorization.get("role"),
created_by=user
created_by=user,
)

def publish_create_org_message(self, instance: Organization, user: User):

authorizations = []
for authorization in instance.authorizations.all():
if authorization.can_contribute:
authorizations.append({"user_email": authorization.user.email, "role": authorization.role})
authorizations.append(
{"user_email": authorization.user.email, "role": authorization.role}
)

message_body = {
"uuid": str(instance.uuid),
Expand All @@ -142,10 +146,12 @@ def publish_create_org_message(self, instance: Organization, user: User):
"user_email": user.email,
}
rabbitmq_publisher = RabbitmqPublisher()
rabbitmq_publisher.send_message(message_body, exchange="orgs.topic", routing_key="")
rabbitmq_publisher.send_message(
message_body, exchange="orgs.topic", routing_key=""
)

def get_show_chat_help(self, obj):
if obj.config.get('show_chat_help'):
if obj.config.get("show_chat_help"):
return True
return obj.authorizations.order_by("created_at").first().user.number_people == 4

Expand Down Expand Up @@ -174,9 +180,9 @@ def validate(self, attrs):
return attrs

def validate_email(self, email):
if ' ' in email:
if " " in email:
raise ValidationError(_("Email field cannot have spaces"))
if bool(re.match('[A-Z]', email)):
if bool(re.match("[A-Z]", email)):
raise ValidationError(_("Email field cannot have uppercase characters"))

def validate_role(self, role):
Expand All @@ -191,12 +197,9 @@ def calculate_user_data(self, user):
if user:
return {
"name": f"{user.first_name} {user.last_name}",
"photo": user.photo_url
"photo": user.photo_url,
}
return {
"name": None,
"photo": None
}
return {"name": None, "photo": None}


class OrganizationExistingAuthorizationSerializer(serializers.ModelSerializer):
Expand Down

0 comments on commit 467b1bb

Please sign in to comment.