Skip to content

[19.0][MIG] mail_activity_restrict: Migration to 19.0 - #169

Open
CRogos wants to merge 3 commits into
OCA:19.0from
c4a8-odoo:19.0-mig-mail_activity_restrict
Open

[19.0][MIG] mail_activity_restrict: Migration to 19.0#169
CRogos wants to merge 3 commits into
OCA:19.0from
c4a8-odoo:19.0-mig-mail_activity_restrict

Conversation

@CRogos

@CRogos CRogos commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@CRogos
CRogos force-pushed the 19.0-mig-mail_activity_restrict branch 2 times, most recently from d5bd366 to 5f4571f Compare April 10, 2026 21:09
@CRogos
CRogos marked this pull request as ready for review April 10, 2026 21:23
@CRogos CRogos changed the title [18.0][MIG] mail_activity_restrict: Migration to 19.0 [19.0][MIG] mail_activity_restrict: Migration to 19.0 Apr 10, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions Bot added the stale label Aug 9, 2026
@CRogos

CRogos commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Feature needs review.


def _get_can_write_restrict_allowed_activities(self):
"""Return restricted activities the current user may modify."""
return self.sudo().filtered_domain([("user_id", "=", self.env.uid)])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If nobody is assigned, this matches nobody, so nobody can edit, delete, assign or mark it done, not even Admin. In the UI the buttons are hidden for everyone, and in the Activity overview you only get an AccessError. The activity is stuck forever.

A possible fix:

return self.sudo().filtered_domain(
    ["|", ("user_id", "=", False), ("user_id", "=", self.env.uid)]
)

So if there is no assignee, normal odoo rules will apply. If assignee is set, the restriction applies.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I agree. If nobody is assigned, no restriction should be made. But check this also in the mail_activity_team_restrict. When there is no user_id but a team_id set, in this case only the team should be able to edit.

if operation not in ("write", "unlink") or not self or self.env.su:
return result

restricted = self.filtered("activity_type_id.can_write_restrict")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is actually suggested by Claude and i think it is useful:
"""
restricted = self.filtered("activity_type_id.can_write_restrict")

This reads mail.activity.type as the current user inside _check_access. If a read fails here it would raise instead of returning the (records, error) tuple. The helper above does it right with self.sudo(). Works today, but it's fragile:

restricted = self.sudo().filtered("activity_type_id.can_write_restrict")

"""

@MohamedOsman7 MohamedOsman7 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@CRogos

I clicked everything through in the UI. I found these things that i think should be fixed:

  1. In connection with the module mail_activity_reminder, nobody can create a restricted activity for other user: If you as Admin, open a contact -> Schedule Activity with "Restrict Write to Assigned User" -> assign it to another user -> Save. You get an AccessError and the activity is not created at all. It only works if you assign it to yourself.

  2. An activity without assignee is locked forever: Since 19.0 user_id is optional. (comment 1)

  3. (comment 2)

  4. Should reassigning be allowed at all, and by whom? Because currently when I create a restricted activity and assign it to myself, then save it, the activity is created successfully. However, if I assign it to someone else, I am no longer able to make any changes to the activity because the buttons are no longer visible. (Yet, with the "mail_activity_reminder" module, you aren't even allowed to change the user, you get an access error.)

@CRogos

CRogos commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author
  1. The idea behind the restricted activities is a kind of approval. But approval should only be granted by the assigned users. Therefore changing the user by the creator is not intended.
    When these activity types are defined by a custom module, and the activity is created from code, these activity could also be removed by some code. (like it is done in the timeoff approval process)
    We could allow assigning only on create or reassigned by the assigned user/team. Or we could also prevent user from manually creating restricted activities and leave these kind of activity exclusive to activities created by code (like the timeoff approval activity)
image

@OCA-git-bot OCA-git-bot added series:19.0 mod:mail_activity_restrict Module mail_activity_restrict labels Aug 13, 2026
@CRogos
CRogos force-pushed the 19.0-mig-mail_activity_restrict branch from fc3514b to 5f4571f Compare August 14, 2026 15:21
@github-actions github-actions Bot removed the stale label Aug 16, 2026
@CRogos
CRogos force-pushed the 19.0-mig-mail_activity_restrict branch from e45c24f to f945986 Compare August 18, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:mail_activity_restrict Module mail_activity_restrict series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants