From d6ebd88ba5691dfec5364c1830fe3638f1d74521 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 15 Nov 2011 16:56:30 +0100 Subject: [PATCH 01/10] [IMP] share: only show current view when selecting "readonly" mode bzr revid: chs@openerp.com-20111115155630-4ut72jrc8111ivm4 --- addons/share/static/src/js/share.js | 1 + addons/share/wizard/share_wizard.py | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/addons/share/static/src/js/share.js b/addons/share/static/src/js/share.js index b2abc1832a4..d37e653c2b5 100644 --- a/addons/share/static/src/js/share.js +++ b/addons/share/static/src/js/share.js @@ -14,6 +14,7 @@ function launch_wizard(self, view) { name: action.name, domain: domain, action_id: action.id, + view_type: view.fields_view.type, }, function(result) { var share_id = result.result; var step1 = Share.call('go_step_1', [[share_id],], function(result) { diff --git a/addons/share/wizard/share_wizard.py b/addons/share/wizard/share_wizard.py index 1cd8104100c..c62d55b3f52 100644 --- a/addons/share/wizard/share_wizard.py +++ b/addons/share/wizard/share_wizard.py @@ -136,6 +136,7 @@ class share_wizard(osv.osv_memory): _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."), + 'view_type': fields.char('Current View Type', size=32, required=True), 'domain': fields.char('Domain', size=256, help="Optional domain for further data filtering"), '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."), @@ -149,6 +150,7 @@ class share_wizard(osv.osv_memory): 'message': fields.text("Personal Message", help="An optional personal message, to be included in the e-mail notification."), } _defaults = { + 'view_type': 'tree', 'user_type' : 'emails', 'domain': lambda self, cr, uid, context, *a: context.get('domain', '[]'), 'action_id': lambda self, cr, uid, context, *a: context.get('action_id'), @@ -273,21 +275,33 @@ class share_wizard(osv.osv_memory): def _shared_action_def(self, cr, uid, wizard_data, context=None): copied_action = wizard_data.action_id + + if wizard_data.access_mode == 'readonly': + view_mode = wizard_data.view_type + view_id = copied_action.view_id.id if copied_action.view_id.type == wizard_data.view_type else False + else: + view_mode = copied_action.view_mode + view_id = copied_action.view_id.id + + action_def = { 'name': wizard_data.name, 'domain': copied_action.domain, 'context': self._cleanup_action_context(wizard_data.action_id.context, uid), 'res_model': copied_action.res_model, - 'view_mode': copied_action.view_mode, + 'view_mode': view_mode, 'view_type': copied_action.view_type, - 'search_view_id': copied_action.search_view_id.id, - 'view_id': copied_action.view_id.id, + 'search_view_id': copied_action.search_view_id.id if wizard_data.access_mode != 'readonly' else False, + 'view_id': view_id, + 'auto_search': True, } if copied_action.view_ids: action_def['view_ids'] = [(0,0,{'sequence': x.sequence, 'view_mode': x.view_mode, 'view_id': x.view_id.id }) - for x in copied_action.view_ids] + for x in copied_action.view_ids + if (wizard_data.access_mode != 'readonly' or x.view_mode == wizard_data.view_type) + ] return action_def def _setup_action_and_shortcut(self, cr, uid, wizard_data, user_ids, make_home, context=None): From a6438cae308f4453807caf31a0203db3aac58af2 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Thu, 1 Dec 2011 17:00:40 +0100 Subject: [PATCH 02/10] [IMP] share: add option to generate embedded code bzr revid: chs@openerp.com-20111201160040-15s4tn1pxixvmvnu --- addons/share/wizard/share_wizard.py | 138 ++++++++++++++++++---- addons/share/wizard/share_wizard_view.xml | 25 +++- 2 files changed, 138 insertions(+), 25 deletions(-) diff --git a/addons/share/wizard/share_wizard.py b/addons/share/wizard/share_wizard.py index c62d55b3f52..bbd4620af64 100644 --- a/addons/share/wizard/share_wizard.py +++ b/addons/share/wizard/share_wizard.py @@ -22,12 +22,16 @@ import logging import random import time from urllib import quote_plus +import uuid + +import simplejson import tools from osv import osv, fields from osv import expression from tools.translate import _ from tools.safe_eval import safe_eval +import openerp FULL_ACCESS = ('perm_read', 'perm_write', 'perm_create', 'perm_unlink') READ_WRITE_ACCESS = ('perm_read', 'perm_write') @@ -110,7 +114,8 @@ class share_wizard(osv.osv_memory): def _user_type_selection(self, cr, uid, context=None): """Selection values may be easily overridden/extended via inheritance""" - return [('emails','List of emails')] + return [('emails','List of emails'), + ('embedded', 'Anyone on a website')] """Override of create() to auto-compute the action name""" def create(self, cr, uid, values, context=None): @@ -133,6 +138,21 @@ class share_wizard(osv.osv_memory): result[this.id] = this.share_url_template() % data return result + def _embed_head(self, cr, uid, ids, _fn, _args, context=None): + base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url', default='', context=context) + head = """ + + + """ % (base_url, base_url) + return dict.fromkeys(ids, head) + + def _embed_code(self, cr, uid, ids, _fn, _args, context=None): + result = dict.fromkeys(ids, '') + for this in self.browse(cr, uid, ids, context=context): + result[this.id] = self._generate_embedded_code(this) + 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."), @@ -148,6 +168,11 @@ class share_wizard(osv.osv_memory): 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."), + + 'embed_head': fields.function(_embed_head, type='text'), + 'embed_code': fields.function(_embed_code, type='text'), + 'embed_option_title': fields.boolean("Display title"), + 'embed_option_search': fields.boolean('Display search view'), } _defaults = { 'view_type': 'tree', @@ -155,6 +180,8 @@ class share_wizard(osv.osv_memory): 'domain': lambda self, cr, uid, context, *a: context.get('domain', '[]'), 'action_id': lambda self, cr, uid, context, *a: context.get('action_id'), 'access_mode': 'readonly', + 'embed_option_title': True, + 'embed_option_search': True, } def go_step_1(self, cr, uid, ids, context=None): @@ -189,33 +216,52 @@ class share_wizard(osv.osv_memory): current_user = user_obj.browse(cr, UID_ROOT, uid, context=context) created_ids = [] existing_ids = [] - for new_user in (wizard_data.new_users or '').split('\n'): - # Ignore blank lines - new_user = new_user.strip() - if not new_user: continue - # Ignore the user if it already exists. - existing = user_obj.search(cr, UID_ROOT, [('login', '=', new_user)]) - existing_ids.extend(existing) - if existing: - new_line = { 'user_id': existing[0], - 'newly_created': False} + if wizard_data.user_type == 'emails': + for new_user in (wizard_data.new_users or '').split('\n'): + # Ignore blank lines + new_user = new_user.strip() + if not new_user: continue + # Ignore the user if it already exists. + existing = user_obj.search(cr, UID_ROOT, [('login', '=', new_user)]) + existing_ids.extend(existing) + if existing: + new_line = { 'user_id': existing[0], + 'newly_created': False} + wizard_data.write({'result_line_ids': [(0,0,new_line)]}) + continue + new_pass = generate_random_pass() + user_id = user_obj.create(cr, UID_ROOT, { + 'login': new_user, + 'password': new_pass, + 'name': new_user, + 'user_email': new_user, + 'groups_id': [(6,0,[group_id])], + 'share': True, + 'company_id': current_user.company_id.id + }) + new_line = { 'user_id': user_id, + 'password': new_pass, + 'newly_created': True} wizard_data.write({'result_line_ids': [(0,0,new_line)]}) - continue - new_pass = generate_random_pass() + created_ids.append(user_id) + + elif wizard_data.user_type == 'embedded': + new_login = 'embedded-%s' % (uuid.uuid4().hex,) + new_pass = generate_random_pass() user_id = user_obj.create(cr, UID_ROOT, { - 'login': new_user, - 'password': new_pass, - 'name': new_user, - 'user_email': new_user, - 'groups_id': [(6,0,[group_id])], - 'share': True, - 'company_id': current_user.company_id.id + 'login': new_login, + 'password': new_pass, + 'name': new_login, + 'groups_id': [(6,0,[group_id])], + 'share': True, + 'company_id': current_user.company_id.id }) new_line = { 'user_id': user_id, 'password': new_pass, 'newly_created': True} wizard_data.write({'result_line_ids': [(0,0,new_line)]}) created_ids.append(user_id) + return created_ids, existing_ids def _create_shortcut(self, cr, uid, values, context=None): @@ -706,6 +752,8 @@ class share_wizard(osv.osv_memory): emails_sent = 0 for result_line in wizard_data.result_line_ids: email_to = result_line.user_id.user_email + if not email_to: + continue subject = wizard_data.name body = _("Hello,") body += "\n\n" @@ -742,6 +790,56 @@ class share_wizard(osv.osv_memory): else: self._logger.warning('Failed to send share notification from %s to %s, ignored', user.user_email, email_to) self._logger.info('%s share notification(s) successfully sent.', emails_sent) + + + def _generate_embedded_code(self, wizard, options=None): + cr = wizard._cr + uid = wizard._uid + context = wizard._context + if options is None: + options = {} + + js_options = {} + title = options['title'] if 'title' in options else wizard.embed_option_title + search = (options['search'] if 'search' in options else wizard.embed_option_search) if wizard.access_mode != 'readonly' else False + + if not title: + js_options['display_title'] = False + if search: + js_options['search_view'] = True + + + js_options_str = (', ' + simplejson.dumps(js_options)) if js_options else '' + + base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url', default=None, context=context) + user = wizard.result_line_ids[0] + + return """ + + """ % { + 'init': simplejson.dumps(openerp.conf.server_wide_modules), + 'server': simplejson.dumps(base_url), + 'dbname': simplejson.dumps(cr.dbname), + 'login': simplejson.dumps(user.login), + 'password': simplejson.dumps(user.password), + 'action': user.user_id.action_id.id, + 'options': js_options_str, + } + + def onchange_embed_options(self, cr, uid, ids, opt_title, opt_search, context=None): + wizard = self.browse(cr, uid, ids[0], context) + options = dict(title=opt_title, search=opt_search) + return {'value': {'embed_code': self._generate_embedded_code(wizard, options)}} + share_wizard() class share_result_line(osv.osv_memory): diff --git a/addons/share/wizard/share_wizard_view.xml b/addons/share/wizard/share_wizard_view.xml index 128b32b07da..fb7544d1e68 100644 --- a/addons/share/wizard/share_wizard_view.xml +++ b/addons/share/wizard/share_wizard_view.xml @@ -37,8 +37,8 @@ - - + + @@ -61,15 +61,30 @@ form
- - + + + + + - + + + + + + + + + + + + +