diff options
| author | jbm-odoo <jbm@odoo.com> | 2020-01-17 07:51:56 +0000 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2020-02-28 08:58:43 +0000 |
| commit | 49d64a8fb1fd79a6e53c3768183f6359d9bee6e4 (patch) | |
| tree | 1dd92636aeb17c7234bff9dfb1cee9ab37db09ac /addons/website_forum/models | |
| parent | ee519c222f0d1aec3f1b4082bbd76d13dedd07b2 (diff) | |
[IMP] website_forum: Add privacy
Add privacy on forum: public or private. If private, we must select
one group that has access.
For forum linked to eLearning course: the privacy of forum is the same
as the course. If the course is not yet published, the forum will be
invisible (unless we have the group group_website_slides_officer).
If a forum linked to a course is unlinked or removed, the forum will
become private and his group will be set to group_website_slides_officer.
All posts and tags have the same access rules as their linked forum.
closes odoo/odoo#43486
Taskid: 2169965
Related: odoo/upgrade#758
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons/website_forum/models')
| -rw-r--r-- | addons/website_forum/models/forum.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index 9f17605b690..4b70b2df39f 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -34,6 +34,14 @@ class Forum(models.Model): ('discussions', 'Discussions')], string='Forum Mode', required=True, default='questions', help='Questions mode: only one answer allowed\n Discussions mode: multiple answers allowed') + privacy = fields.Selection([ + ('public', 'Public'), + ('connected', 'Signed In'), + ('private', 'Some users')], + help="Public: Forum is pubic\nSigned In: Forum is visible for signed in users\nSome users: Forum and their content are hidden for non members of selected group", + default='public') + authorized_group_id = fields.Many2one('res.groups', 'Authorized Group') + menu_id = fields.Many2one('website.menu', 'Menu', copy=False) active = fields.Boolean(default=True) faq = fields.Html('Guidelines', default=_get_default_faq, translate=html_translate, sanitize=False) description = fields.Text('Description', translate=True) @@ -153,6 +161,20 @@ class Forum(models.Model): return super(Forum, self.with_context(mail_create_nolog=True, mail_create_nosubscribe=True)).create(values) def write(self, vals): + if 'privacy' in vals: + if not vals['privacy']: + # The forum is neither public, neither private, remove menu to avoid conflict + self.menu_id.unlink() + elif vals['privacy'] == 'public': + # The forum is public, the menu must be also public + vals['authorized_group_id'] = False + self.menu_id.write({'group_ids': [(5, 0, 0)]}) + elif vals['privacy'] == 'connected': + vals['authorized_group_id'] = False + self.menu_id.write({'group_ids': [(6, 0, [self.env.ref('base.group_portal').id, self.env.ref('base.group_user').id])]}) + if 'authorized_group_id' in vals and vals['authorized_group_id']: + self.menu_id.write({'group_ids': [(6, 0, [vals['authorized_group_id']])]}) + res = super(Forum, self).write(vals) if 'active' in vals: # archiving/unarchiving a forum does it on its posts, too |
