From 3519e2c19f90002555163c7bae1bd07e14510e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 10 Apr 2013 18:01:39 +0200 Subject: [PATCH] [IMP] project, task, issues: improvement of ir rules. Still a bit WIP. bzr revid: tde@openerp.com-20130410160139-vx9z4rsmfiji1vu9 --- addons/portal_project/__init__.py | 1 + addons/portal_project/__openerp__.py | 2 +- .../security/portal_security.xml | 68 ++++++++++++-- .../security/portal_security.xml | 30 +++++-- addons/project/__openerp__.py | 3 +- addons/project/project.py | 28 +++--- addons/project/project_demo.xml | 14 ++- addons/project/project_view.xml | 2 +- addons/project/security/project_security.xml | 88 ++++++++++++------- .../security/project_issue_security.xml | 25 +++++- 10 files changed, 197 insertions(+), 64 deletions(-) diff --git a/addons/portal_project/__init__.py b/addons/portal_project/__init__.py index 26c654db9dd..164c7826e47 100644 --- a/addons/portal_project/__init__.py +++ b/addons/portal_project/__init__.py @@ -19,3 +19,4 @@ # ############################################################################## +import project diff --git a/addons/portal_project/__openerp__.py b/addons/portal_project/__openerp__.py index d502d278c38..afc7973ebc0 100644 --- a/addons/portal_project/__openerp__.py +++ b/addons/portal_project/__openerp__.py @@ -30,7 +30,7 @@ This module adds project menu and features (tasks) to your portal if project and ====================================================================================================== """, 'author': 'OpenERP SA', - 'depends': ['project','portal'], + 'depends': ['project', 'portal'], 'data': [ 'security/portal_security.xml', 'security/ir.model.access.csv', diff --git a/addons/portal_project/security/portal_security.xml b/addons/portal_project/security/portal_security.xml index 37f64421196..8476446a723 100644 --- a/addons/portal_project/security/portal_security.xml +++ b/addons/portal_project/security/portal_security.xml @@ -1,20 +1,70 @@ - + + - - Portal Projects - - ['|', ('privacy_visibility', 'in', ['public', 'publicall']), ('message_follower_ids', 'in', [user.partner_id.id])] + + Project: employees: public, portal, employees or following + ['|', + ('visibility', 'in', ['public', 'portal', 'employees']), + '&', + ('visibility', '=', 'followers'), + ('message_follower_ids', 'in', [user.id]), + ] + + + + + Project: portal users: public, portal or following + + ['|', + ('visibility', 'in', ['public', 'portal']), + '&', + ('visibility', '=', 'followers'), + ('message_follower_ids', 'in', [user.id]), + ] - - Portal Tasks - - ['|', ('project_id.privacy_visibility', '=', 'publicall'), ('message_follower_ids','in', [user.partner_id.id])] + + Project: anonymous users: public only + + [('visibility', '=', 'public')] + + + + + Project/Task: employees: public, portal, employee or following or assigned + ['|', + '|', + ('project_id.visibility', 'in', ['public', 'portal', 'employees']), + '&', + ('project_id.visibility', '=', 'followers'), + ('message_follower_ids', 'in', [user.id]), + ('user_id', '=', user.id), + ] + + + + Project/Task: portal users: public or portal and following + + ['|', + '|', + ('project_id.visibility', '=', 'public'), + '&', + ('project_id.visibility', 'in', ['portal', 'followers']), + ('message_follower_ids','in', [user.partner_id.id]), + ('user_id', '=', user.id), + ] + + Project/Task: anonymous users: public only + + [('project_id.visibility', '=', 'public')] + + + diff --git a/addons/portal_project_issue/security/portal_security.xml b/addons/portal_project_issue/security/portal_security.xml index 2ee830c7f84..f6d377c663b 100644 --- a/addons/portal_project_issue/security/portal_security.xml +++ b/addons/portal_project_issue/security/portal_security.xml @@ -1,11 +1,19 @@ - + + - - Portal Personal Issues - - ['|', ('project_id.privacy_visibility', '=', 'publicall'), ('message_follower_ids','in', [user.partner_id.id])] + + Project/Issue: portal users: public or portal and following + + ['|', + '|', + ('project_id.visibility', '=', 'public'), + '&', + ('project_id.visibility', 'in', ['portal', 'followers']), + ('message_follower_ids','in', [user.partner_id.id]), + ('user_id', '=', user.id), + ] @@ -13,5 +21,17 @@ + + Project/Issue: employees: public, portal, employee or following or assigned + ['|', + '|', + ('project_id.visibility', 'in', ['public', 'portal', 'employees']), + '&', + ('project_id.visibility', '=', 'followers'), + ('message_follower_ids', 'in', [user.id]), + ('user_id', '=', user.id), + ] + + diff --git a/addons/project/__openerp__.py b/addons/project/__openerp__.py index c0a516cf555..c39d8ee07a5 100644 --- a/addons/project/__openerp__.py +++ b/addons/project/__openerp__.py @@ -76,8 +76,9 @@ Dashboard / Reports for Project Management will include: 'report/project_cumulative.xml', 'board_project_view.xml', 'res_config_view.xml', + 'project_demo.xml', ], - 'demo': ['project_demo.xml'], + # 'demo': ['project_demo.xml'], 'test': [ 'test/project_demo.yml', 'test/project_process.yml', diff --git a/addons/project/project.py b/addons/project/project.py index 473b4e06fe9..524034aa0bc 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -173,7 +173,6 @@ class project(osv.osv): res[id]['progress_rate'] = 0.0 return res - def unlink(self, cr, uid, ids, context=None): alias_ids = [] mail_alias = self.pool.get('mail.alias') @@ -183,10 +182,10 @@ class project(osv.osv): _('You cannot delete a project containing tasks. You can either delete all the project\'s tasks and then delete the project or simply deactivate the project.')) elif proj.alias_id: alias_ids.append(proj.alias_id.id) - res = super(project, self).unlink(cr, uid, ids, context=context) + res = super(project, self).unlink(cr, uid, ids, context=context) mail_alias.unlink(cr, uid, alias_ids, context=context) return res - + def _get_attached_docs(self, cr, uid, ids, field_name, arg, context): res = {} attachment = self.pool.get('ir.attachment') @@ -197,7 +196,7 @@ class project(osv.osv): task_attachments = attachment.search(cr, uid, [('res_model', '=', 'project.task'), ('res_id', 'in', task_ids)], context=context, count=True) res[id] = (project_attachments or 0) + (task_attachments or 0) return res - + def _task_count(self, cr, uid, ids, field_name, arg, context=None): res = dict.fromkeys(ids, 0) task_ids = self.pool.get('project.task').search(cr, uid, [('project_id', 'in', ids)]) @@ -206,16 +205,21 @@ class project(osv.osv): return res def _get_alias_models(self, cr, uid, context=None): - """Overriden in project_issue to offer more options""" + """ Overriden in project_issue to offer more options """ return [('project.task', "Tasks")] + def _get_visibility_selection(self, cr, uid, context=None): + """ Overriden in project_issue to offer more options """ + return [('public', 'All Users'), + ('employees', 'Employees Only'), + ('followers', 'Followers Only')] + def attachment_tree_view(self, cr, uid, ids, context): task_ids = self.pool.get('project.task').search(cr, uid, [('project_id', 'in', ids)]) domain = [ - '|', + '|', '&', ('res_model', '=', 'project.project'), ('res_id', 'in', ids), - '&', ('res_model', '=', 'project.task'), ('res_id', 'in', task_ids) - ] + '&', ('res_model', '=', 'project.task'), ('res_id', 'in', task_ids)] res_id = ids and ids[0] or False return { 'name': _('Attachments'), @@ -228,8 +232,11 @@ class project(osv.osv): 'limit': 80, 'context': "{'default_res_model': '%s','default_res_id': %d}" % (self._name, res_id) } + # Lambda indirection method to avoid passing a copy of the overridable method when declaring the field _alias_models = lambda self, *args, **kwargs: self._get_alias_models(*args, **kwargs) + _visibility_selection = lambda self, *args, **kwargs: self._get_visibility_selection(*args, **kwargs) + _columns = { 'complete_name': fields.function(_complete_name, string="Project Name", type='char', size=250), 'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the project without removing it."), @@ -268,7 +275,8 @@ class project(osv.osv): "with Tasks (or optionally Issues if the Issue Tracker module is installed)."), 'alias_model': fields.selection(_alias_models, "Alias Model", select=True, required=True, help="The kind of document created when an email is received on this project's email alias"), - 'privacy_visibility': fields.selection([('publicall', 'All users will see all tasks'), ('public','All users'), ('employees','All employees'), ('followers','Followers Only')], 'Privacy / Visibility', required=True), + 'visibility': fields.selection(_visibility_selection, 'Privacy / Visibility', + select=True, required=True, oldname="privacy_visibility"), 'state': fields.selection([('template', 'Template'),('draft','New'),('open','In Progress'), ('cancelled', 'Cancelled'),('pending','Pending'),('close','Closed')], 'Status', required=True,), 'doc_count':fields.function(_get_attached_docs, string="Number of documents attached", type='int') } @@ -286,7 +294,7 @@ class project(osv.osv): 'sequence': 10, 'type_ids': _get_type_common, 'alias_model': 'project.task', - 'privacy_visibility': 'public', + 'visibility': 'public', } # TODO: Why not using a SQL contraints ? diff --git a/addons/project/project_demo.xml b/addons/project/project_demo.xml index f5fbf878fd0..42671c43002 100644 --- a/addons/project/project_demo.xml +++ b/addons/project/project_demo.xml @@ -1,6 +1,7 @@ - + + @@ -29,7 +30,7 @@ 3 - public + public @@ -46,9 +47,12 @@ Research & Development - public + followers project.task + @@ -62,7 +66,7 @@ E-Learning Integration project.task - public + public @@ -75,6 +79,7 @@ Website Design Templates + followers project.task @@ -89,6 +94,7 @@ Data Import/Export Plugin project.task + employees diff --git a/addons/project/project_view.xml b/addons/project/project_view.xml index 75d508f63fb..58ae4de1b6f 100644 --- a/addons/project/project_view.xml +++ b/addons/project/project_view.xml @@ -111,7 +111,7 @@ - + diff --git a/addons/project/security/project_security.xml b/addons/project/security/project_security.xml index 78da9284f9f..09d9f77d663 100644 --- a/addons/project/security/project_security.xml +++ b/addons/project/security/project_security.xml @@ -35,41 +35,65 @@ - - - Project multi-company - - - ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] - + + + + Project: multi-company + + + ['|', + ('company_id', '=', False), + ('company_id', 'child_of', [user.company_id.id]), + ] + - - Public Members - - ['|',('privacy_visibility','in',['public', 'publicall', 'employees']),('message_follower_ids','in',[user.partner_id.id])] - - + + Project: project manager: see all + + [(1, '=', 1)] + + - - Task multi-company - - - ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] - + + Project: employees: public, employees or followers + + ['|', + ('visibility', 'in', ['public', 'employees']), + ('message_follower_ids', 'in', [user.partner_id.id]) + ] + + - - Tasks According to User and Project - - ['|','|','|','|',('project_id.privacy_visibility', '=', 'publicall'),('user_id','=',False),('user_id','=',user.id),('project_id.members','in', [user.id]),('project_id.user_id','=',user.id)] - - + + Project/Task: multi-company + + + ['|', + ('company_id', '=', False), + ('company_id', 'child_of', [user.company_id.id]), + ] + - - Project Managers: all tasks from all projects - - [(1,'=',1)] - - - + + Project/Task: employees: public or employee or following or assigned + + ['|', + '|', + ('project_id.visibility', 'in', ['public', 'employees']), + '&', + ('project_id.visibility', '=', 'followers'), + ('message_follower_ids', 'in', [user.id]), + ('user_id', '=', user.id), + ] + + + + + Project/Task: project manager: see all + + [(1, '=', 1)] + + + diff --git a/addons/project_issue/security/project_issue_security.xml b/addons/project_issue/security/project_issue_security.xml index c3119073a75..b6b9d5e7d20 100644 --- a/addons/project_issue/security/project_issue_security.xml +++ b/addons/project_issue/security/project_issue_security.xml @@ -1,5 +1,28 @@ - + + + + + Project/Issue: project manager: see all + + [(1, '=', 1)] + + + + + Project/Issue: employees: public or employee or following or assigned + + ['|', + '|', + ('project_id.visibility', 'in', ['public', 'employees']), + '&', + ('project_id.visibility', '=', 'followers'), + ('message_follower_ids', 'in', [user.id]), + ('user_id', '=', user.id), + ] + + +