-
Notifications
You must be signed in to change notification settings - Fork 0
Bugfix add auto assigning manager if he create project #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,7 @@ class ProjectCreateView(CreateView): | |
|
|
||
| def get_context_data(self, **kwargs: Any) -> dict: | ||
| logger.info(f"User with id: {self.request.user.pk} is in project create view") | ||
| ProjectAdminForm.user_pk = self.request.user.pk | ||
| context_data = super().get_context_data(**kwargs) | ||
| context_data["back_url"] = self.get_success_url() | ||
| return context_data | ||
|
|
@@ -102,6 +103,12 @@ def get_success_url(self) -> str: # pylint: disable=no-self-use | |
| return reverse("custom-projects-list") | ||
|
|
||
| def form_valid(self, form: ProjectAdminForm) -> HttpRequest: | ||
| if self.request.user not in form.cleaned_data["managers"]: | ||
| assert not self.request.user.is_employee | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems overly cautious to me, since AFAIK we already successfully restrict access for unauthorised personel.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I gave assert here only for safety-check purposes. It already gave me feed back when I set there |
||
| managers_pk_list = [manager.pk for manager in form.cleaned_data["managers"]] | ||
| managers_pk_list.append(self.request.user.pk) | ||
| managers_queryset = CustomUser.objects.filter(pk__in=managers_pk_list) | ||
| form.cleaned_data["managers"] = managers_queryset | ||
| project = form.save() | ||
| logger.info(f"New project with id: {project.pk} has been created") | ||
| return super(ModelFormMixin, self).form_valid(form) # pylint: disable=bad-super-call | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the user is assigned either way, the user should be excluded from the field and the field should be marked as optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done