From a36146430decfca525de11e34424c8388ddb258e Mon Sep 17 00:00:00 2001
From: ara <>
Date: Wed, 30 May 2012 16:01:20 +0530
Subject: [PATCH 01/21] portal:Improve portal wizard of contact
bzr revid: mma@tinyerp.com-20120530103120-as3coz6hx3y2cvbg
---
addons/portal/wizard/portal_wizard.py | 68 ++++++++++++++++++---------
1 file changed, 45 insertions(+), 23 deletions(-)
diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py
index 1ec4cbb0e4b..3b5a0c31b8c 100644
--- a/addons/portal/wizard/portal_wizard.py
+++ b/addons/portal/wizard/portal_wizard.py
@@ -91,11 +91,20 @@ class wizard(osv.osv_memory):
def _default_user_ids(self, cr, uid, context):
""" determine default user_ids from the active records """
def create_user_from_address(address):
- return { # a user config based on a contact (address)
+ has_portal=False
+ portal_id = context.get('portal_id',False)
+ portal_users = self.pool.get('res.portal').browse(cr,uid,portal_id).group_id.users
+ active_user = [u.login for u in portal_users]
+ if address.email in active_user:
+ has_portal = True
+
+ return { # a user config based on a contact (address)
'name': address.name,
'user_email': extract_email(address.email),
'lang': address.parent_id and address.parent_id.lang or 'en_US',
'partner_id': address.parent_id and address.parent_id.id,
+ 'has_portal_user':has_portal,
+ 'portal_id': context.get('portal_id', False)
}
user_ids = []
@@ -112,9 +121,13 @@ class wizard(osv.osv_memory):
return user_ids
- _defaults = {
- 'user_ids': _default_user_ids
- }
+ def onchange_portal_id(self, cr, uid, ids, portal_id=False, context=None):
+ if not portal_id:
+ return {'value': {}}
+ user_obj = self.pool.get('res.users')
+ context.update({'portal_id':portal_id})
+ user_list = self._default_user_ids(cr, uid, context=context)
+ return {'value': {'user_ids': user_list}}
def action_create(self, cr, uid, ids, context=None):
""" create new users in portal(s), and notify them by email """
@@ -133,25 +146,33 @@ class wizard(osv.osv_memory):
portal_obj = self.pool.get('res.portal')
for wiz in self.browse(cr, uid, ids, context):
# determine existing users
- login_cond = [('login', 'in', [u.user_email for u in wiz.user_ids])]
- existing_uids = user_obj.search(cr, ROOT_UID, login_cond)
- existing_users = user_obj.browse(cr, ROOT_UID, existing_uids)
- existing_logins = [u.login for u in existing_users]
-
- # create new users in portal (skip existing logins)
- new_users_data = [ {
- 'name': u.name,
- 'login': u.user_email,
- 'password': random_password(),
- 'user_email': u.user_email,
- 'context_lang': u.lang,
- 'share': True,
- 'action_id': wiz.portal_id.home_action_id and wiz.portal_id.home_action_id.id or False,
- 'partner_id': u.partner_id and u.partner_id.id,
- } for u in wiz.user_ids if u.user_email not in existing_logins ]
- portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id],
- {'users': [(0, 0, data) for data in new_users_data]}, context0)
-
+
+ for u in wiz.user_ids:
+ login_cond = [('login', 'in', [u.user_email])]
+ existing_uids = user_obj.search(cr, ROOT_UID, login_cond)
+ existing_users = user_obj.browse(cr, ROOT_UID, existing_uids)
+ existing_logins = [user.login for user in existing_users]
+ new_users_data = []
+ if u.has_portal_user==False:
+ new_users_data = []
+ if u.user_email in existing_logins:
+ portal_uids = user_obj.search(cr, ROOT_UID, [('login','=',u.user_email),('partner_id', '=', u.partner_id.id)])
+ user_obj.unlink(cr,uid,portal_uids)
+ else:
+ if u.user_email not in existing_logins:
+ new_users_data.append({
+ 'name': u.name,
+ 'login': u.user_email,
+ 'password': random_password(),
+ 'user_email': u.user_email,
+ 'context_lang': u.lang,
+ 'share': True,
+ 'action_id': wiz.portal_id.home_action_id and wiz.portal_id.home_action_id.id or False,
+ 'partner_id': u.partner_id and u.partner_id.id,
+ } )
+ portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id],
+ {'users': [(0, 0, data) for data in new_users_data]}, context0)
+
# send email to all users (translated in their language)
data = {
'company': user.company_id.name,
@@ -205,6 +226,7 @@ class wizard_user(osv.osv_memory):
help="The language for the user's user interface"),
'partner_id': fields.many2one('res.partner',
string='Partner'),
+ 'has_portal_user':fields.boolean('Has portal access')
}
def _check_email(self, cr, uid, ids):
From 60df377cdfc992b75657749e9ec6f3f6903dee4c Mon Sep 17 00:00:00 2001
From: ara-desktop <>
Date: Wed, 30 May 2012 16:37:44 +0530
Subject: [PATCH 02/21] portal:add missing xml file changes
bzr revid: mma@tinyerp.com-20120530110744-4lufcl4veemhvewn
---
addons/portal/wizard/portal_wizard_view.xml | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/addons/portal/wizard/portal_wizard_view.xml b/addons/portal/wizard/portal_wizard_view.xml
index 7f36272720c..0f49c25d108 100644
--- a/addons/portal/wizard/portal_wizard_view.xml
+++ b/addons/portal/wizard/portal_wizard_view.xml
@@ -17,7 +17,7 @@
form
@@ -48,6 +48,7 @@
+
From 297ee5313a5ca72d4d77af6c65fcfb35a48840ac Mon Sep 17 00:00:00 2001
From: "ara@tinyerp.com" <>
Date: Wed, 30 May 2012 19:27:57 +0530
Subject: [PATCH 03/21] portal: add default user
bzr revid: ara@tinyerp.com-20120530135757-34eu8xtx3ybcaazn
---
addons/portal/wizard/portal_wizard.py | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py
index 3b5a0c31b8c..8ad99a00cbe 100644
--- a/addons/portal/wizard/portal_wizard.py
+++ b/addons/portal/wizard/portal_wizard.py
@@ -93,10 +93,11 @@ class wizard(osv.osv_memory):
def create_user_from_address(address):
has_portal=False
portal_id = context.get('portal_id',False)
- portal_users = self.pool.get('res.portal').browse(cr,uid,portal_id).group_id.users
- active_user = [u.login for u in portal_users]
- if address.email in active_user:
- has_portal = True
+ if portal_id:
+ portal_users = self.pool.get('res.portal').browse(cr,uid,portal_id).group_id.users
+ active_user = [u.login for u in portal_users]
+ if address.email in active_user:
+ has_portal = True
return { # a user config based on a contact (address)
'name': address.name,
@@ -121,6 +122,10 @@ class wizard(osv.osv_memory):
return user_ids
+ _defaults = {
+ 'user_ids': _default_user_ids
+ }
+
def onchange_portal_id(self, cr, uid, ids, portal_id=False, context=None):
if not portal_id:
return {'value': {}}
From 1e49be80c99bf752b4264d74a7f30e1d748f04f9 Mon Sep 17 00:00:00 2001
From: "ara@tinyerp.com" <>
Date: Mon, 4 Jun 2012 12:40:51 +0530
Subject: [PATCH 04/21] [IMP] Improve portal wizard string
bzr revid: ara@tinyerp.com-20120604071051-mwr1o7vq72s0iewh
---
addons/portal/wizard/portal_wizard.py | 13 ++++++-------
addons/portal/wizard/portal_wizard_view.xml | 4 ++--
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py
index 8ad99a00cbe..0e42a68f757 100644
--- a/addons/portal/wizard/portal_wizard.py
+++ b/addons/portal/wizard/portal_wizard.py
@@ -158,12 +158,7 @@ class wizard(osv.osv_memory):
existing_users = user_obj.browse(cr, ROOT_UID, existing_uids)
existing_logins = [user.login for user in existing_users]
new_users_data = []
- if u.has_portal_user==False:
- new_users_data = []
- if u.user_email in existing_logins:
- portal_uids = user_obj.search(cr, ROOT_UID, [('login','=',u.user_email),('partner_id', '=', u.partner_id.id)])
- user_obj.unlink(cr,uid,portal_uids)
- else:
+ if u.has_portal_user:
if u.user_email not in existing_logins:
new_users_data.append({
'name': u.name,
@@ -177,7 +172,11 @@ class wizard(osv.osv_memory):
} )
portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id],
{'users': [(0, 0, data) for data in new_users_data]}, context0)
-
+ else:
+ new_users_data = []
+ if u.user_email in existing_logins:
+ portal_uids = user_obj.search(cr, ROOT_UID, [('login','=',u.user_email),('partner_id', '=', u.partner_id.id)])
+ user_obj.unlink(cr,uid,portal_uids)
# send email to all users (translated in their language)
data = {
'company': user.company_id.name,
diff --git a/addons/portal/wizard/portal_wizard_view.xml b/addons/portal/wizard/portal_wizard_view.xml
index 0f49c25d108..ad64362ddb8 100644
--- a/addons/portal/wizard/portal_wizard_view.xml
+++ b/addons/portal/wizard/portal_wizard_view.xml
@@ -3,7 +3,7 @@
- Add Portal Access
+ Portal Access Management Wizard
res.portal.wizard
form
From a93cdd0dc11232296debc71690d5cc76e07a1a72 Mon Sep 17 00:00:00 2001
From: "ara@tinyerp.com" <>
Date: Wed, 6 Jun 2012 11:02:15 +0530
Subject: [PATCH 05/21] [IMP] create user when user not in current userlist
bzr revid: ara@tinyerp.com-20120606053215-4dnotn7dq5o6119g
---
addons/portal/wizard/portal_wizard.py | 35 ++++++++++++---------
addons/portal/wizard/portal_wizard_view.xml | 6 ++--
2 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py
index 0e42a68f757..c1c6856b5ac 100644
--- a/addons/portal/wizard/portal_wizard.py
+++ b/addons/portal/wizard/portal_wizard.py
@@ -158,21 +158,22 @@ class wizard(osv.osv_memory):
existing_users = user_obj.browse(cr, ROOT_UID, existing_uids)
existing_logins = [user.login for user in existing_users]
new_users_data = []
- if u.has_portal_user:
- if u.user_email not in existing_logins:
- new_users_data.append({
- 'name': u.name,
- 'login': u.user_email,
- 'password': random_password(),
- 'user_email': u.user_email,
- 'context_lang': u.lang,
- 'share': True,
- 'action_id': wiz.portal_id.home_action_id and wiz.portal_id.home_action_id.id or False,
- 'partner_id': u.partner_id and u.partner_id.id,
- } )
- portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id],
- {'users': [(0, 0, data) for data in new_users_data]}, context0)
- else:
+
+ if u.user_email not in existing_logins:
+ new_users_data.append({
+ 'name': u.name,
+ 'login': u.user_email,
+ 'password': random_password(),
+ 'user_email': u.user_email,
+ 'context_lang': u.lang,
+ 'share': True,
+ 'action_id': wiz.portal_id.home_action_id and wiz.portal_id.home_action_id.id or False,
+ 'partner_id': u.partner_id and u.partner_id.id,
+ } )
+ portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id],
+ {'users': [(0, 0, data) for data in new_users_data]}, context0)
+
+ if not u.has_portal_user:
new_users_data = []
if u.user_email in existing_logins:
portal_uids = user_obj.search(cr, ROOT_UID, [('login','=',u.user_email),('partner_id', '=', u.partner_id.id)])
@@ -243,6 +244,10 @@ class wizard_user(osv.osv_memory):
(_check_email, 'Invalid email address', ['email']),
]
+ _defaults = {
+ 'lang': lambda self,cr,uid,c: self.browse(cr, uid, uid, c).partner_id.lang or 'en_US',
+ }
+
wizard_user()
diff --git a/addons/portal/wizard/portal_wizard_view.xml b/addons/portal/wizard/portal_wizard_view.xml
index ad64362ddb8..77ccd44cd44 100644
--- a/addons/portal/wizard/portal_wizard_view.xml
+++ b/addons/portal/wizard/portal_wizard_view.xml
@@ -3,7 +3,7 @@
- Portal Access Management Wizard
+ Portal Access Management
res.portal.wizard
form