Skip to content

Bugfix managers field in project admin form#472

Merged
dybi merged 1 commit intomasterfrom
bugfix-managers-fields-in-project-creation-form
Aug 6, 2019
Merged

Bugfix managers field in project admin form#472
dybi merged 1 commit intomasterfrom
bugfix-managers-fields-in-project-creation-form

Conversation

@Szymiks
Copy link
Contributor

@Szymiks Szymiks commented Aug 1, 2019

Resolves: #462

Should have done

  • managers field is optional, user of request is always set as manager.
  • when we go to update the project view, we could see all managers and if we want to update it, we do not remove the manager who created the project.

@Szymiks Szymiks added bug Something isn't working priority low Tasks with low priority labels Aug 1, 2019
@Szymiks Szymiks self-assigned this Aug 1, 2019
if hasattr(self, "user_pk"):
ManagerSelectMultiple.user_pk = self.user_pk

if "managers" in self.fields:
Copy link
Contributor

@rwrzesien rwrzesien Aug 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check doesn't make much sense, as this field is in form by its definition. If you really want to check this, make it an assert.

Copy link
Contributor Author

@Szymiks Szymiks Aug 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But manager is able to update project, too. However they don't have rights to update managers field in project and then we are using for themProjectManagerForm which inheritance from ProjectAdminForm but manager field is excluded in ProjectManagerForm

Copy link
Contributor

@rwrzesien rwrzesien Aug 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then inheritance doesn't make much sense here any more. It should be used if parent class can contain logic from subclasses so you don't have to repeat this logic. Here now those two forms have different logic. So please make ProjectManagerForm do not inherit from ProjectAdminForm and you can then remove this if.

@rwrzesien
Copy link
Contributor

rwrzesien commented Aug 1, 2019

user of request is always set as manager.

Is this implemented?

when we go to update the project view, we could see all managers and if we want to update it, we do not remove the manager who created the project.

I don't see this too.

@Szymiks
Copy link
Contributor Author

Szymiks commented Aug 2, 2019

@rwrzesien

user of request is always set as manager.

Is this implemented?

It is implemented in create view by someone else before that PR.

    def form_valid(self, form: ProjectAdminForm) -> HttpRequest:
        if self.request.user not in form.cleaned_data["managers"]:
            assert not self.request.user.is_employee
            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

when we go to update the project view, we could see all managers and if we want to update it, we do not remove the manager who created the project.

I don't see this too.

        if "managers" in self.fields:
            managers_to_choose = CustomUser.objects.exclude(user_type=CustomUser.UserType.EMPLOYEE.name)
            if self.instance.pk:
                self.fields["managers"].queryset = managers_to_choose

It is here, before we was excluding all the time user_pk

Copy link
Contributor

@dybi dybi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clarify

@Szymiks Szymiks requested review from dybi and rwrzesien August 2, 2019 12:31
@rwrzesien
Copy link
Contributor

@Szymiks

It is implemented in create view by someone else before that PR.

Thanks, I thought you will be adding this in this PR and I didn't saw that code in PR that is why I have asked.

It is here, before we was excluding all the time user_pk.

OK, what I have originally understood from we do not remove the manager who created the project. is that we want to block possibility of removing project creatior from managers, but you have explained it in #472 (comment) so it is clear now (that project creator can be removed from managers in update, right?)

Copy link
Contributor

@rwrzesien rwrzesien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, thanks for explanation, some small improvements can be applied.

@Szymiks
Copy link
Contributor Author

Szymiks commented Aug 5, 2019

OK, what I have originally understood from we do not remove the manager who created the project. is that we want to block possibility of removing project creatior from managers, but you have explained it in #472 (comment) so it is clear now (that project creator can be removed from managers in update, right?)

@rwrzesien, Yes he can be removed, but before he was allways removed during first updating.

@Szymiks Szymiks force-pushed the bugfix-managers-fields-in-project-creation-form branch from 0836337 to ae03d59 Compare August 5, 2019 07:49
@kbeker kbeker added this to the v1.0.0 milestone Aug 6, 2019
@Szymiks Szymiks force-pushed the bugfix-managers-fields-in-project-creation-form branch from ae03d59 to 3a10068 Compare August 6, 2019 11:32
@dybi dybi merged commit c22f9ed into master Aug 6, 2019
@dybi dybi deleted the bugfix-managers-fields-in-project-creation-form branch August 6, 2019 11:37
@kbeker kbeker modified the milestones: v1.0.0, v0.9.0 Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority low Tasks with low priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problems with managers field in project creation and update

4 participants