[FIX] share+portal: fix share wizard.
[IMP] share wizard: share_root_url and share_url are now function fields bzr revid: chs@openerp.com-20111010142549-uvco15xdf2198e0x
This commit is contained in:
parent
dca92e2cc1
commit
a1e5797727
|
@ -40,10 +40,6 @@ class share_wizard_portal(osv.osv_memory):
|
|||
_columns = {
|
||||
'user_ids': fields.many2many('res.users', 'share_wizard_res_user_rel', 'share_id', 'user_id', 'Existing users', domain=[('share', '=', True)]),
|
||||
'group_ids': fields.many2many('res.groups', 'share_wizard_res_group_rel', 'share_id', 'group_id', 'Existing groups', domain=[('share', '=', False)]),
|
||||
|
||||
# no clean way to extend selection yet, copy the field.
|
||||
'user_type': fields.selection(_user_type_selection,'Users to share with',
|
||||
help="Select the type of user(s) you would like to share data with."),
|
||||
}
|
||||
|
||||
def is_portal_manager(self, cr, uid, context=None):
|
||||
|
|
|
@ -8,11 +8,7 @@
|
|||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="share.share_step1_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="/form/group[@name='emails_group']" position="before">
|
||||
<group name="groups_group" colspan="4" col="4" groups="portal.group_portal_manager">
|
||||
<separator colspan="4" string="Who do you want to share with?"/>
|
||||
<field name="user_type" />
|
||||
</group>
|
||||
<xpath expr="/form/group[@name='emails_group']" position="after">
|
||||
<group name="user_group" colspan="4" attrs="{'invisible':[('user_type','!=','existing')]}">
|
||||
<field colspan="4" nolabel="1" name="user_ids" mode="tree">
|
||||
<tree string="Existing users">
|
||||
|
|
|
@ -119,24 +119,35 @@ class share_wizard(osv.osv_memory):
|
|||
values['name'] = action.name
|
||||
return super(share_wizard,self).create(cr, uid, values, context=context)
|
||||
|
||||
|
||||
def _share_root_url(self, cr, uid, ids, _fieldname, _args, context=None):
|
||||
result = dict.fromkeys(ids, '')
|
||||
data = dict(dbname=cr.dbname, login='', password='')
|
||||
for this in self.browse(cr, uid, ids, context=context):
|
||||
result[this.id] = this.share_url_template % data
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
'action_id': fields.many2one('ir.actions.act_window', 'Action to share', required=True,
|
||||
help="The action that opens the screen containing the data you wish to share."),
|
||||
'domain': fields.char('Domain', size=256, help="Optional domain for further data filtering"),
|
||||
'user_type': fields.selection(_user_type_selection,'Users to share with',
|
||||
'user_type': fields.selection(lambda s, *a, **k: s._user_type_selection(*a, **k),'Users to share with', required=True,
|
||||
help="Select the type of user(s) you would like to share data with."),
|
||||
'new_users': fields.text("Emails"),
|
||||
'access_mode': fields.selection([('readonly','Can view'),('readwrite','Can edit')],'Access Mode', required=True,
|
||||
help="Access rights to be granted on the shared documents."),
|
||||
'result_line_ids': fields.one2many('share.wizard.result.line', 'share_wizard_id', 'Summary', readonly=True),
|
||||
'share_root_url': fields.char('Share Access URL', size=512, readonly=True, tooltip='Main access page for users that are granted shared access'),
|
||||
'share_url_template': fields.char('Share Access URL Template', size=512,
|
||||
help='Template for share url. May contains %(dbname)s, %(login)s and %(password)s'),
|
||||
'share_root_url': fields.function(_share_root_url, 'Share Access URL', type='char', size=512, readonly=True,
|
||||
help='Main access page for users that are granted shared access'),
|
||||
'name': fields.char('Share Title', size=64, required=True, help="Title for the share (displayed to users as menu and shortcut name)"),
|
||||
'message': fields.text("Personal Message", help="An optional personal message, to be included in the e-mail notification."),
|
||||
}
|
||||
_defaults = {
|
||||
'user_type' : 'emails',
|
||||
'domain': lambda self, cr, uid, context, *a: context.get('domain', '[]'),
|
||||
'share_root_url': lambda self, cr, uid, context, *a: context.get('share_root_url') or _('Please specify "share_root_url" in context'),
|
||||
'share_url_template': lambda self, cr, uid, context, *a: context.get('share_url_template') or _('Please specify "share_url_template" in context'),
|
||||
'action_id': lambda self, cr, uid, context, *a: context.get('action_id'),
|
||||
'access_mode': 'readonly',
|
||||
}
|
||||
|
@ -537,12 +548,11 @@ class share_wizard(osv.osv_memory):
|
|||
try:
|
||||
domain = safe_eval(wizard_data.domain)
|
||||
if domain:
|
||||
domain_expr = expression.expression(domain)
|
||||
for rel_field, model in fields_relations:
|
||||
related_domain = []
|
||||
if not rel_field: continue
|
||||
for element in domain:
|
||||
if domain_expr._is_leaf(element):
|
||||
if expression.is_leaf(element):
|
||||
left, operator, right = element
|
||||
left = '%s.%s'%(rel_field, left)
|
||||
element = left, operator, right
|
||||
|
@ -555,19 +565,6 @@ class share_wizard(osv.osv_memory):
|
|||
raise osv.except_osv(_('Sharing access could not be created'),
|
||||
_('Sorry, the current screen and filter you are trying to share are not supported at the moment.\nYou may want to try a simpler filter.'))
|
||||
|
||||
def _finish_result_lines(self, cr, uid, wizard_data, share_group_id, context=None):
|
||||
"""Perform finalization of the share, and populate the summary"""
|
||||
share_root_url = wizard_data.share_root_url
|
||||
format_url = '%(dbname)s' in share_root_url
|
||||
for result in wizard_data.result_line_ids:
|
||||
# share_root_url may contain placeholders for dbname, login and password
|
||||
share_url = (share_root_url % \
|
||||
{'login': quote_plus(result.user_id.login),
|
||||
'password': '', # kept empty for security reasons
|
||||
'dbname': quote_plus(cr.dbname)}) \
|
||||
if format_url else share_root_url
|
||||
result.write({'share_url': share_url}, context=context)
|
||||
|
||||
def _check_preconditions(self, cr, uid, wizard_data, context=None):
|
||||
self._assert(wizard_data.action_id and wizard_data.access_mode,
|
||||
_('Action and Access Mode are required to create a shared access'),
|
||||
|
@ -662,15 +659,6 @@ class share_wizard(osv.osv_memory):
|
|||
# C.
|
||||
self._create_indirect_sharing_rules(cr, current_user, wizard_data, group_id, obj1, context=context)
|
||||
|
||||
# so far, so good -> check summary results and return them
|
||||
self._finish_result_lines(cr, uid, wizard_data, group_id, context=context)
|
||||
|
||||
# update share URL to make it generic
|
||||
generic_share_url = wizard_data.share_root_url % {'dbname': cr.dbname,
|
||||
'login': '',
|
||||
'password': ''}
|
||||
wizard_data.write({'share_root_url': generic_share_url}, context=context)
|
||||
|
||||
# refresh wizard_data
|
||||
wizard_data = self.browse(cr, uid, ids[0], context=context)
|
||||
|
||||
|
@ -742,11 +730,20 @@ share_wizard()
|
|||
class share_result_line(osv.osv_memory):
|
||||
_name = 'share.wizard.result.line'
|
||||
_rec_name = 'user_id'
|
||||
|
||||
|
||||
def _share_url(self, cr, uid, ids, _fieldname, _args, context=None):
|
||||
result = dict.fromkeys(ids, '')
|
||||
for this in self.browse(cr, uid, ids, context=context):
|
||||
data = dict(dbname=cr.dbname, login=this.login, password='') # password is kept empty for security reasons
|
||||
result[this.id] = this.share_wizard_id.share_url_template % data
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
'user_id': fields.many2one('res.users', required=True, readonly=True),
|
||||
'login': fields.related('user_id', 'login', string='Login', type='char', size=64, required=True, readonly=True),
|
||||
'password': fields.char('Password', size=64, readonly=True),
|
||||
'share_url': fields.char('Share URL', size=512, required=True),
|
||||
'share_url': fields.function(_share_url, 'Share URL', type='char', size=512),
|
||||
'share_wizard_id': fields.many2one('share.wizard', 'Share Wizard', required=True),
|
||||
'newly_created': fields.boolean('Newly created', readonly=True),
|
||||
}
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Grant instant access to your documents">
|
||||
<group name="groups_group" colspan="4" col="4">
|
||||
<separator colspan="4" string="Who do you want to share with?"/>
|
||||
<field name="user_type" />
|
||||
</group>
|
||||
<group colspan="4" name="emails_group" attrs="{'invisible':[('user_type','!=','emails')]}">
|
||||
<separator colspan="4" string="Share with these people (one e-mail per line)"/>
|
||||
<field colspan="4" nolabel="1" name="new_users" attrs="{'required':[('user_type','=','emails')]}"/>
|
||||
|
@ -78,7 +82,7 @@
|
|||
- 'action_id' (id of action)
|
||||
- 'domain' (string expression for full domain to apply as sent to server,
|
||||
with dynamic data like 'uid' replaced by actual value (i.e. after eval)!)
|
||||
- 'share_root_url' : URL for direct access to share page (may include %(login)s and %(password)s placeholders)
|
||||
- 'share_url_template' : URL for direct access to share page (may include %(login)s and %(password)s placeholders)
|
||||
-->
|
||||
<record id="action_share_wizard" model="ir.actions.act_window">
|
||||
<field name="name">Share Wizard</field>
|
||||
|
@ -94,7 +98,7 @@
|
|||
- 'action_id' (id of action)
|
||||
- 'domain' (string expression for full domain to apply as sent to server,
|
||||
with dynamic data like 'uid' replaced by actual value (i.e. after eval)!)
|
||||
- 'share_root_url' : URL for direct access to share page (may include %(login)s and %(password)s placeholders)
|
||||
- 'share_url_template' : URL for direct access to share page (may include %(login)s and %(password)s placeholders)
|
||||
-->
|
||||
<record id="action_share_wizard_step1" model="ir.actions.act_window">
|
||||
<field name="name">Share Wizard</field>
|
||||
|
|
Loading…
Reference in New Issue