Skip to content

Commit

Permalink
fix: retrieve project using web browser (#1136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshimkus-rh authored Nov 15, 2024
1 parent c47adae commit 8ebeecb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 45 deletions.
41 changes: 21 additions & 20 deletions src/aap_eda/api/serializers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,40 +241,41 @@ class Meta:

def to_representation(self, project):
eda_credential = (
EdaCredentialRefSerializer(project["eda_credential"]).data
if project["eda_credential"]
EdaCredentialRefSerializer(project.eda_credential).data
if project.eda_credential
else None
)
signature_validation_credential = (
EdaCredentialRefSerializer(
project["signature_validation_credential"]
project.signature_validation_credential
).data
if project["signature_validation_credential"]
if project.signature_validation_credential
else None
)
organization = (
OrganizationRefSerializer(project["organization"]).data
if project["organization"]
OrganizationRefSerializer(project.organization).data
if project.organization
else None
)

return {
"id": project["id"],
"name": project["name"],
"description": project["description"],
"url": project["url"],
"proxy": project["proxy"],
"scm_type": project["scm_type"],
"scm_branch": project["scm_branch"],
"scm_refspec": project["scm_refspec"],
"git_hash": project["git_hash"],
"verify_ssl": project["verify_ssl"],
"id": project.id,
"name": project.name,
"description": project.description,
"url": project.url,
"proxy": self.get_proxy(project),
"scm_type": project.scm_type,
"scm_branch": project.scm_branch,
"scm_refspec": project.scm_refspec,
"git_hash": project.git_hash,
"verify_ssl": project.verify_ssl,
"organization": organization,
"eda_credential": eda_credential,
"signature_validation_credential": signature_validation_credential,
"import_state": project["import_state"],
"import_error": project["import_error"],
"created_at": project["created_at"],
"modified_at": project["modified_at"],
"import_state": project.import_state,
"import_error": project.import_error,
"created_at": project.created_at,
"modified_at": project.modified_at,
}


Expand Down
30 changes: 5 additions & 25 deletions src/aap_eda/api/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def destroy(self, request, *args, **kwargs):
class ProjectViewSet(
ResponseSerializerMixin,
mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
DestroyProjectMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet,
Expand Down Expand Up @@ -171,38 +170,19 @@ def create(self, request):
},
)
def retrieve(self, request, pk):
project = super().retrieve(request, pk)
project.data["eda_credential"] = (
models.EdaCredential.objects.get(
pk=project.data["eda_credential_id"]
)
if project.data["eda_credential_id"]
else None
)
project.data["signature_validation_credential"] = (
models.EdaCredential.objects.get(
pk=project.data["signature_validation_credential_id"]
)
if project.data["signature_validation_credential_id"]
else None
)
project.data["organization"] = (
models.Organization.objects.get(pk=project.data["organization_id"])
if project.data["organization_id"]
else None
)
project = self.get_object()

logger.info(
logging_utils.generate_simple_audit_log(
"Read",
resource_name,
project.data["name"],
project.data["id"],
project.data["organization"].name,
project.name,
project.id,
project.organization.name,
)
)

return Response(serializers.ProjectReadSerializer(project.data).data)
return Response(serializers.ProjectReadSerializer(project).data)

@extend_schema(
description="Partial update of a project",
Expand Down

0 comments on commit 8ebeecb

Please sign in to comment.