-
-
Notifications
You must be signed in to change notification settings - Fork 871
[16.0][ADD] project_task_create_portal: Module added #1578
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
base: 16.0
Are you sure you want to change the base?
[16.0][ADD] project_task_create_portal: Module added #1578
Conversation
1db972f to
34dac90
Compare
34dac90 to
f2e45e1
Compare
5f4ccc9 to
a47028f
Compare
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.
Create and edit work well. tests look solid, but there are some problems.
- incompatible with project_task_code_portal, that loads the task page with sudo user, therefore making the edit button dissapear from form (env.user != task.create_uid)
- the edit button is visible when accessing portal task form from projects > task , but not directly from tasks > task. this is caused by the widespread sudo problem in portal templates. solved by:
def is_portal_task_creation_allowed(self):
self.ensure_one()
return bool(self.portal_stage_id) and self.env.context['uid'] in self.portal_user_ids.ids
created an MR to this branch with the proposed fixes for this problem.
- settings name only refers to "create" , make clear also "edit" is possible.
- in settings make clear that stage_id is bothe the stage the new task will be created in and also the only stage it will be allowed to be edited in.
- Optionally, refactor to have, also separate "edit" setting on project form.
- Module name is misleading, it allows to edit and create tasks.
|
|
||
| - Go to the portal, navigate to Projects | ||
| - Select an available project | ||
| - Select a task in the stage permitted for task creation and task editing |
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.
Edit button not visible on task form. should be under
- task, history , does not show. (explanation of reason in other comments)
| priority="20" | ||
| > | ||
| <xpath expr="//t[@t-set='entries']/ul" position="inside"> | ||
| <li class="list-group-item" t-if="task.check_portal_edit_access()"> |
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.
here we have our edit button, that will refer to the edit controller, only for records in correct stage and owned by users.
Edit works perfectly, but it is incompatible with module project_task_code_portal, if that module is installed all edit functions are gone. route is still accessible by manually inserting the url.
The reason for this incompatibility lies in this line of code: https://github.com/OCA/project/blob/16.0/project_task_code_portal/controllers/portal.py#L87
where we freturn sudo page values:
https://github.com/OCA/project/blob/16.0/project_task_code_portal/controllers/portal.py#L91
then leaving self.env.user as sudo in the task page. In other comments i suggest to replace self.env.user with self.env.context['uid'], to make code work with project_task_code_portal and any other modules that may sudo the page.
| """Check if the current user has portal access to edit this task.""" | ||
| # Portal users can only access tasks in projects with portal task creation enabled | ||
| if not self.project_id.is_portal_task_creation_allowed(): | ||
| return False |
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.
Why would edit be forbidden , because creation is not allowed?
Yes, our edit feature is tied to "only the tasks the user has created" but this would cause problems if we have a situation a user creates many tasks, is then removed from create permissions , but still wants to modify the issues they created.
I suggest to remove this. edit should be depending only on the current user and record creator .
Or create separate configuration settings for edit function.
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.
Just to add to add it here, In the write where check_portal_edit_access is called you might want to add self.ensure_one() because write call can be called with multi-records. Either add self.ensure_one() or for loop that will loop over self just in case its called with multi recordset.
| <field name="arch" type="xml"> | ||
| <group name="extra_settings" position="before"> | ||
| <group | ||
| string="Allow Create Task In Portal" |
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.
Create and edit own tasks in portal.
settings name is misleading.
| @@ -0,0 +1,124 @@ | |||
| ============================ | |||
| Project Portal Task Creation | |||
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.
Misleading name. this module supports create and has also an "own task edit" feature
| def is_portal_task_creation_allowed(self): | ||
| """Check if portal task creation is allowed for this project.""" | ||
| self.ensure_one() | ||
| return bool(self.portal_stage_id) and self.env.user in self.portal_user_ids |
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.
because of a sudo in project_task_code_portal, this will fail everytime, therefore all edit features will not show (the button is conditionally checked on this being true)
Works if replaced by:
return bool(self.portal_stage_id) and self.env.context['uid'] in self.portal_user_ids.ids
this problem was found on runboat with all oca/project modules installed.
| return False | ||
|
|
||
| # Portal users can only edit their own tasks | ||
| if self.create_uid != self.env.user: |
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.
if self.env.user is sudo, as imposed in project_task_code_portal this will fail.
replace self.env.user with self.env.context['uid']
| if not self.env.user.has_group("base.group_portal"): | ||
| return records | ||
| for record in self: | ||
| if not record.project_id.is_portal_task_creation_allowed(): |
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.
I think here you meant to loop through the record set returned by records = super().create(vals_list) otherwise I don't think the call to is_portal_task_creation_allowed() is being executed.
| """Check if the current user has portal access to edit this task.""" | ||
| # Portal users can only access tasks in projects with portal task creation enabled | ||
| if not self.project_id.is_portal_task_creation_allowed(): | ||
| return False |
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.
Just to add to add it here, In the write where check_portal_edit_access is called you might want to add self.ensure_one() because write call can be called with multi-records. Either add self.ensure_one() or for loop that will loop over self just in case its called with multi recordset.
| """Override write to handle portal user restrictions.""" | ||
| if ( | ||
| self.env.user.has_group("base.group_portal") | ||
| and not self.check_portal_edit_access() |
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.
this is what I meant when write is called and check_portal_edit_access isn't secured to check multiple records or single check.
|
@gfcapalbo, @KKamaa |
- Module name is updated on "Project Portal Own Task Management" - ensure_one method is added for method "is_portal_task_creation_allowed" - Сompatibility with project_task_code_portal is added - Project settings group description is updated
8c48953 to
5a8a62c
Compare
No description provided.