Skip to content

Commit

Permalink
remove the owner from project
Browse files Browse the repository at this point in the history
  • Loading branch information
velis74 committed Dec 6, 2024
1 parent 3b92a35 commit e316550
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions django_project_base/rest/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ def __init__(self, *args, is_filter: bool = False, **kwds):
self.fields.fields["owner"].display_form = DisplayMode.HIDDEN

# logo = fields.FileField(display=DisplayMode.SUPPRESS, required=False) # todo: not implemented UI
owner = fields.AutoGeneratedField(display_table=DisplayMode.SUPPRESS, display_form=DisplayMode.HIDDEN)

# we can remove the owner, because they're set at project creation and there will be a separate API for changing
# owner = fields.IntegerField(display_table=DisplayMode.SUPPRESS, display_form=DisplayMode.HIDDEN)

class Meta:
model = swapper.load_model("django_project_base", "Project")
exclude = ("logo",) # TODO we currently don't support logos well. see DPB #3
exclude = ("logo", "owner") # TODO we currently don't support logos well. see DPB #3
layout = Layout(Row("name"), Row("slug"), Row("description"))


Expand All @@ -68,15 +70,6 @@ class ProjectViewSet(DynamicModelMixin, ModelViewSet):
permission_classes = (IsProjectOwnerOrReadOnly | CreateAny,)
MODEL_FUNC_SETTING_NAME = "DJANGO_PROJECT_BASE_PROJECT_MODEL_AT_RUNTIME"

def new_object(self: ModelViewSet):
new_object = super().new_object()
if self.request and self.request.user and self.request.user.is_authenticated:
new_object.owner = getattr(
self.request.user, swapper.load_model("django_project_base", "Profile")._meta.model_name
)

return new_object

@staticmethod
def _get_queryset_for_request(request):
try:
Expand Down Expand Up @@ -198,6 +191,13 @@ def set_args(name: str) -> None:
return super().get_object()
return super().get_object()

def perform_create(self, serializer):
serializer.save(
owner=self.request.user
if self.request and self.request.user and self.request.user.is_authenticated
else None
)

def create(self, request, *args, **kwargs):
create_response = super().create(request, *args, **kwargs)
project = self.get_queryset().model.objects.get(slug=create_response.data["slug"])
Expand Down

0 comments on commit e316550

Please sign in to comment.