diff options
| author | Vijaykumar Baladaniya <vba@tinyerp.com> | 2012-07-09 18:31:13 +0530 |
|---|---|---|
| committer | Vijaykumar Baladaniya <vba@tinyerp.com> | 2012-07-09 18:31:13 +0530 |
| commit | be2e95656aaa113addea2b510fcdcf2f890eaaa4 (patch) | |
| tree | abcb3dd4ef350a1b8ad0eaffdd2b9a1cb91521af /addons/share/wizard | |
| parent | b982ea278b33132def3927417b7a854b98b5028a (diff) | |
| parent | 3925f76ce85854e5d4834902a05f57bcfc5ace85 (diff) | |
[MERGE]merged with trunk-survey-layout-tta
bzr revid: vba@tinyerp.com-20120709130113-3lchipgil9oqpglg
Diffstat (limited to 'addons/share/wizard')
| -rw-r--r-- | addons/share/wizard/share_wizard.py | 55 | ||||
| -rw-r--r-- | addons/share/wizard/share_wizard_view.xml | 47 |
2 files changed, 58 insertions, 44 deletions
diff --git a/addons/share/wizard/share_wizard.py b/addons/share/wizard/share_wizard.py index 07004f333a8..41871480f45 100644 --- a/addons/share/wizard/share_wizard.py +++ b/addons/share/wizard/share_wizard.py @@ -32,6 +32,7 @@ from osv import expression from tools.translate import _ from tools.safe_eval import safe_eval import openerp +_logger = logging.getLogger(__name__) FULL_ACCESS = ('perm_read', 'perm_write', 'perm_create', 'perm_unlink') READ_WRITE_ACCESS = ('perm_read', 'perm_write') @@ -47,8 +48,7 @@ RANDOM_PASS_CHARACTERS = 'aaaabcdeeeefghjkmnpqrstuvwxyzAAAABCDEEEEFGHJKLMNPQRSTU def generate_random_pass(): return ''.join(random.sample(RANDOM_PASS_CHARACTERS,10)) -class share_wizard(osv.osv_memory): - _logger = logging.getLogger('share.wizard') +class share_wizard(osv.TransientModel): _name = 'share.wizard' _description = 'Share Wizard' @@ -176,10 +176,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)"), 'record_name': fields.char('Record name', size=128, help="Name of the shared record, if sharing a precise record"), - 'message': fields.text("Personal Message", help="An optional personal message, to be included in the e-mail notification."), - - 'embed_code': fields.function(_embed_code, type='text'), - 'embed_option_title': fields.boolean("Display title"), + 'message': fields.text("Personal Message", help="An optional personal message, to be included in the email notification."), + 'embed_code': fields.function(_embed_code, type='text', string='Code', + help="Embed this code in your documents to provide a link to the "\ + "shared document."), + 'embed_option_title': fields.boolean('Display title'), 'embed_option_search': fields.boolean('Display search view'), 'embed_url': fields.function(_embed_url, string='Share URL', type='char', size=512, readonly=True), } @@ -200,8 +201,8 @@ class share_wizard(osv.osv_memory): def go_step_1(self, cr, uid, ids, context=None): wizard_data = self.browse(cr,uid,ids,context)[0] if wizard_data.user_type == 'emails' and not self.has_email(cr, uid, context=context): - raise osv.except_osv(_('No e-mail address configured'), - _('You must configure your e-mail address in the user preferences before using the Share button.')) + raise osv.except_osv(_('No email address configured'), + _('You must configure your email address in the user preferences before using the Share button.')) model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'share', 'action_share_wizard_step1') action = self.pool.get(model).read(cr, uid, res_id, context=context) action['res_id'] = ids[0] @@ -335,7 +336,7 @@ class share_wizard(osv.osv_memory): except Exception: # Note: must catch all exceptions, as UnquoteEvalContext may cause many # different exceptions, as it shadows builtins. - self._logger.debug("Failed to cleanup action context as it does not parse server-side", exc_info=True) + _logger.debug("Failed to cleanup action context as it does not parse server-side", exc_info=True) result = context_str return result @@ -496,8 +497,8 @@ class share_wizard(osv.osv_memory): [x.id for x in current_user.groups_id], target_model_ids, context=context) group_access_map = self._get_access_map_for_groups_and_models(cr, uid, [group_id], target_model_ids, context=context) - self._logger.debug("Current user access matrix: %r", current_user_access_map) - self._logger.debug("New group current access matrix: %r", group_access_map) + _logger.debug("Current user access matrix: %r", current_user_access_map) + _logger.debug("New group current access matrix: %r", group_access_map) # Create required rights if allowed by current user rights and not # already granted @@ -520,7 +521,7 @@ class share_wizard(osv.osv_memory): need_creation = True if need_creation: model_access_obj.create(cr, UID_ROOT, values) - self._logger.debug("Creating access right for model %s with values: %r", model.model, values) + _logger.debug("Creating access right for model %s with values: %r", model.model, values) def _link_or_copy_current_user_rules(self, cr, current_user, group_id, fields_relations, context=None): rule_obj = self.pool.get('ir.rule') @@ -542,13 +543,13 @@ class share_wizard(osv.osv_memory): 'groups': [(6,0,[group_id])], 'domain_force': rule.domain, # evaluated version! }) - self._logger.debug("Copying rule %s (%s) on model %s with domain: %s", rule.name, rule.id, model.model, rule.domain_force) + _logger.debug("Copying rule %s (%s) on model %s with domain: %s", rule.name, rule.id, model.model, rule.domain_force) else: # otherwise we can simply link the rule to keep it dynamic rule_obj.write(cr, 1, [rule.id], { 'groups': [(4,group_id)] }) - self._logger.debug("Linking rule %s (%s) on model %s with domain: %s", rule.name, rule.id, model.model, rule.domain_force) + _logger.debug("Linking rule %s (%s) on model %s with domain: %s", rule.name, rule.id, model.model, rule.domain_force) def _check_personal_rule_or_duplicate(self, cr, group_id, rule, context=None): """Verifies that the given rule only belongs to the given group_id, otherwise @@ -567,7 +568,7 @@ class share_wizard(osv.osv_memory): 'groups': [(6,0,[group_id])], 'domain_force': rule.domain_force, # non evaluated! }) - self._logger.debug("Duplicating rule %s (%s) (domain: %s) for modified access ", rule.name, rule.id, rule.domain_force) + _logger.debug("Duplicating rule %s (%s) (domain: %s) for modified access ", rule.name, rule.id, rule.domain_force) # then disconnect from group_id: rule.write({'groups':[(3,group_id)]}) # disconnects, does not delete! return rule_obj.browse(cr, UID_ROOT, new_id, context=context) @@ -602,7 +603,7 @@ class share_wizard(osv.osv_memory): if restrict: continue else: - self._logger.debug("Ignoring sharing rule on model %s with domain: %s the same rule exists already", model_id, domain) + _logger.debug("Ignoring sharing rule on model %s with domain: %s the same rule exists already", model_id, domain) return if restrict: # restricting existing rules is done by adding the clause @@ -614,7 +615,7 @@ class share_wizard(osv.osv_memory): new_clause = expression.normalize(eval(domain, eval_ctx)) combined_domain = expression.AND([new_clause, org_domain]) rule.write({'domain_force': combined_domain, 'name': rule.name + _('(Modified)')}) - self._logger.debug("Combining sharing rule %s on model %s with domain: %s", rule.id, model_id, domain) + _logger.debug("Combining sharing rule %s on model %s with domain: %s", rule.id, model_id, domain) if not rule_ids or not restrict: # Adding the new rule in the group is ok for normal cases, because rules # in the same group and for the same model will be combined with OR @@ -625,7 +626,7 @@ class share_wizard(osv.osv_memory): 'domain_force': domain, 'groups': [(4,group_id)] }) - self._logger.debug("Created sharing rule on model %s with domain: %s", model_id, domain) + _logger.debug("Created sharing rule on model %s with domain: %s", model_id, domain) def _create_indirect_sharing_rules(self, cr, current_user, wizard_data, group_id, fields_relations, context=None): rule_name = _('Indirect sharing filter created by user %s (%s) for group %s') % \ @@ -648,7 +649,7 @@ class share_wizard(osv.osv_memory): group_id, model_id=model.id, domain=str(related_domain), rule_name=rule_name, restrict=True, context=context) except Exception: - self._logger.exception('Failed to create share access') + _logger.exception('Failed to create share access') 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.')) @@ -668,7 +669,8 @@ class share_wizard(osv.osv_memory): """Creates the appropriate share group and share users, and populates result_line_ids of wizard_data with one line for each user. - :return: the new group id (to which the shared access should be granted) + :return: a tuple composed of the new group id (to which the shared access should be granted), + the ids of the new share users that have been created and the ids of the existing share users """ group_id = self._create_share_group(cr, uid, wizard_data, context=context) # First create any missing user, based on the email addresses provided @@ -739,7 +741,7 @@ class share_wizard(osv.osv_memory): all_relations = obj0 + obj1 + obj2 self._link_or_copy_current_user_rules(cr, current_user, group_id, all_relations, context=context) # B. - main_domain = wizard_data.domain if wizard_data.domain != '[]' else DOMAIN_ALL + main_domain = wizard_data.domain if wizard_data.domain != '[]' else str(DOMAIN_ALL) self._create_or_combine_sharing_rule(cr, current_user, wizard_data, group_id, model_id=model.id, domain=main_domain, restrict=True, context=context) @@ -852,7 +854,7 @@ class share_wizard(osv.osv_memory): notification_obj.create(cr, uid, {'user_id': result_line.user_id.id, 'message_id': msg_id}, context=context) def send_emails(self, cr, uid, wizard_data, context=None): - self._logger.info('Sending share notifications by email...') + _logger.info('Sending share notifications by email...') mail_message = self.pool.get('mail.message') user = self.pool.get('res.users').browse(cr, UID_ROOT, uid) if not user.user_email: @@ -885,7 +887,7 @@ class share_wizard(osv.osv_memory): msg_ids.append(mail_message.schedule_with_attach(cr, uid, user.user_email, [email_to], subject, body, model='share.wizard', context=context)) # force direct delivery, as users expect instant notification mail_message.send(cr, uid, msg_ids, context=context) - self._logger.info('%d share notification(s) sent.', len(msg_ids)) + _logger.info('%d share notification(s) sent.', len(msg_ids)) def onchange_embed_options(self, cr, uid, ids, opt_title, opt_search, context=None): wizard = self.browse(cr, uid, ids[0], context) @@ -902,8 +904,11 @@ class share_result_line(osv.osv_memory): 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='') - result[this.id] = this.share_wizard_id.share_url_template() % data + data = dict(dbname=cr.dbname, login=this.login, password=this.password) + if this.share_wizard_id and this.share_wizard_id.action_id: + data['action_id'] = this.share_wizard_id.action_id.id + ctx = dict(context, share_url_template_hash_arguments=['action_id']) + result[this.id] = this.share_wizard_id.share_url_template(context=ctx) % data return result _columns = { diff --git a/addons/share/wizard/share_wizard_view.xml b/addons/share/wizard/share_wizard_view.xml index 1c9bb011432..58734caa25b 100644 --- a/addons/share/wizard/share_wizard_view.xml +++ b/addons/share/wizard/share_wizard_view.xml @@ -9,8 +9,9 @@ <field name="arch" type="xml"> <form string="Sharing: preparation" version="7.0"> <header> - <button name="go_step_1" string="Next" type="object" icon="gtk-go-forward"/> - <button special="cancel" string="Cancel" icon='gtk-cancel'/> + <button name="go_step_1" string="Next" type="object" class="oe_highlight"/> + or + <button string="Cancel" class="oe_link" special="cancel" /> </header> <separator string="Please select the action that opens the screen containing the data you want to share."/> @@ -31,21 +32,27 @@ <field name="arch" type="xml"> <form version="7.0"> <header> - <button name="go_step_2" string="Share" type="object" icon="gtk-go-forward"/> - <button special="cancel" string="Cancel" icon='gtk-cancel'/> + <button name="go_step_2" string="Share" type="object" class="oe_highlight"/> + or + <button string="Cancel" class="oe_link" special="cancel" /> </header> - <field name="user_type" invisible="1"/> - <field name="invite" invisible="1"/> <group> - <group name="emails_group" attrs="{'invisible':['|', ('user_type', '!=', 'emails'), ('invite', '=', True)]}" string="Share with these People (one e-mail per line)"> - <field colspan="2" nolabel="1" name="new_users" attrs="{'required':[('user_type','=','emails'), ('invite', '!=', True)]}"/> + <field name="user_type" invisible="1"/> + <field name="invite" invisible="1"/> + </group> + <group> + <group colspan="4" name="emails_group" attrs="{'invisible':['|', ('user_type', '!=', 'emails'), ('invite', '=', True)]}" + string="Share with these People (one email per line)"> + <field nolabel="1" name="new_users" attrs="{'required':[('user_type','=','emails'), ('invite', '!=', True)]}"/> </group> - <group name="email_lines" attrs="{'invisible':[('invite', '!=', True)]}" string="Share with these People (one e-mail per line)"> + <group colspan="4" name="email_lines" attrs="{'invisible':['|', ('invite', '!=', True), ('user_type', '!=', 'emails')]}" + string="Share with these People (one email per line)"> <field name="email_1"/> <field name="email_2"/> <field name="email_3"/> </group> - <group attrs="{'invisible':[('user_type', '=', 'embedded')]}" string="Include an Optional Personal Message"> + <group colspan="4" attrs="{'invisible':[('user_type', '=', 'embedded')]}" + string="Include an Optional Personal Message"> <field name="message" colspan="2" nolabel="1"/> </group> <group attrs="{'invisible':[('invite', '=', True)]}" string="Sharing Options"> @@ -64,12 +71,11 @@ <field name="arch" type="xml"> <form string="Access granted!" version="7.0"> <header> - <button special="cancel" string="Close" icon='gtk-ok'/> <field name="user_type" invisible="1"/> <field name="access_mode" invisible="1"/> </header> - <group attrs="{'invisible':[('user_type','=','embedded')]}"> - <separator string="An e-mail notification with instructions has been sent to the following people:"/> + <group attrs="{'invisible':[('user_type','=','embedded')]}" + string="An email notification with instructions has been sent to the following people:"> <field name="result_line_ids" nolabel="1" mode="tree"> <tree string="Summary"> <field name="login"/> @@ -82,14 +88,17 @@ </field> </group> <group colspan="4" col="1" attrs="{'invisible':[('user_type','!=','embedded')]}"> - <separator string="Use this Link"/> - <field name="embed_url"/> - <separator string="Or insert the following code where you want to embed your documents"/> - <group string="Options"> - <field name="embed_option_title" on_change="onchange_embed_options(embed_option_title, embed_option_search)"/> - <field name="embed_option_search" on_change="onchange_embed_options(embed_option_title, embed_option_search)" attrs="{'invisible':[('access_mode','=','readonly')]}"/> + <group string="Use this link"> + <field name="embed_url"/> + </group> + <group string="Or insert the following code where you want to embed your documents"> <field name="embed_code"/> </group> + <group string="Embedded code options"> + <field name="embed_option_title" on_change="onchange_embed_options(embed_option_title, embed_option_search)"/> + <field name="embed_option_search" on_change="onchange_embed_options(embed_option_title, embed_option_search)" + attrs="{'invisible':[('access_mode','=','readonly')]}"/> + </group> </group> </form> |
