This question has been flagged
2 Replies
7519 Views

Hello, 

How can I strict permission mark done on mail thread so that only the staff that I sent schedule activity is the only one can "mark done" and/or maybe also "cancel"

i'm using this and it works great

self.env['mail.activity'].create({
'activity_type_id': self.env.ref('custom_module.mail_activity_custom').id,
'note': 'Report please confirm',
'res_id': self.id,
'res_model_id': self.env.ref('custom_module.model_custom').id,
'user_id': user_id
})

the problem is that i/creator can also click it as mark done and that would make the notification for the targeted staff to disappear, i have to make it strict policy that the target staff is the one that click it (except for super admin)

Thank you,

Avatar
Discard

If the mark as done button is calling a python function, you can restrict this by adding a condition inside the function. You can just add an if condition to check whether the assigned user is the same or not and execute accordingly. You will have the assigned user in any field, seems it is user_id from your code, then you can get the current user/logged in user using self.env.user.id, you can compare the values in this two and execute function only if both are same.

Author Best Answer

@niyas thank you for giving me a hint

i eventually use another work around, because i have to validate the records to sent to manager using button, just add more function to button that clear action_feedback:

self.env['mail.activity'].sudo().search(
                [('res_model', '=', self._name), ('res_id', 'in', self.ids),('user_id','=', self.user.id)]
            ).action_feedback()

I have to use sudo because i use custom permission restriction but for normal permission i guess not.

and using this if user submit, then mark done is clear. well it's not the right answer but this is what i got, i don't know how to override action_feedback() with what i want.


Avatar
Discard