Merge lp:~openerp/openobject-addons/share-web-addons into lp:openobject-addons

Proposed by Vaibhav Darji
Status: Merged
Merged at revision: 3948
Proposed branch: lp:~openerp/openobject-addons/share-web-addons
Merge into: lp:openobject-addons
Diff against target: 140 lines (+81/-2)
5 files modified
share/__openerp__.py (+1/-0)
share/web/__init__.py (+2/-0)
share/web/controllers.py (+31/-0)
share/web/editors.py (+41/-0)
share/wizard/share_wizard.py (+6/-2)
To merge this branch: bzr merge lp:~openerp/openobject-addons/share-web-addons
Reviewer Review Type Date Requested Status
Xavier (Open ERP) (community) Needs Fixing
Review via email: mp+40504@code.launchpad.net

Description of the change

Web addon for share module.

To post a comment you must log in.
Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

Business problems:
* share_root_url is not provided to the share.wizard object, so we don't get any URL (let alone a useable one) to send to the clients

Other than that it seems to work correctly

Technical issues in controllers.py (mostly):
* I don't think `active=False` is necessary in the share module descriptor
* There are a bunch of unused variables and imports in controllers.py (urlparse, cherrypy, TinyDict, filter_domain)
* By the way why is filter_domain sent but not used?
* Usage of **kwargs even though we know perfectly well what is going to be sent. Why not use regular method parameters and have

    def index(self, domain, search_domain, context)

  rather than the current completely opaque signature
* Why send `view_type` in the JS call if it's not used?
* No need for the `proxy` intermediate variable, it's used only once and doesn't make the code any clearer. It should be inlined
* Likewise with `res`, why not inline it into the `actions.execute` call? It provides no value.
* `model` should be renamed to something clearer (what model to what is it?) and maybe made into a module-level constant, it's not like there's much point defining it in the method
* Why not use keyword arguments in the `context.update` call? I don't think the explicit dict is clearer, let alone faster
* What happens if no action is found? E.g. if there is no view_name in the context? Or if there is no action found for that name? Wouldn't everything kind-of blow up? Please check/test (share.wizard seems to require an action_id, and I doubt None or an empty list is going to work). If it can not happen then we might as well not bother with the checking code line 24-26, and if it's going to blow up anyway sooner better than later, save yourself the RPC call. This means again line 24-26 can probably be simplified.

Technical issues in editors.py:
* Why style=right on the link? It's a regular link, it should not be needed.
* Why create a bunch of temp variables in the JS code? Why not just inline them in the dict/object literal? Their ids seem clear enough to understand what they are.
* Because of "fixed" behavior of actions, you should not open new window yourself as you're just opening an action. Framework will manage, so handler should just set the correct @href on the link.
* Don't use an initial @href of `javascript: void(0)`, use `#` or `#share` instead.
* Title of section is no good, what does "Share View" mean? Especially as a sidebar title? Something like "Sharing" is probably more appropriate that way it opens possibility of new modules building on that and adding stuff in the section.

That's pretty much it for now.

review: Needs Fixing
3904. By Vaibhav Darji

[FIX] Improved share action method,share url and passed active db in email.

Revision history for this message
Vaibhav Darji (vaibhav-openerp) wrote :

Fixed share root url.
Remove unused variables and imports.
Improvement in share web controller.
passed current db params in email.

Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

* Share root url not fixed, it only sends socket_host and socket_port which results in a returned "share url" of "0.0.0.0:8080". It's not possible to see share with that.

* A number of fixes I asked for were not done, as result for instance point 3 in editors.py issues mean it doesn't work with new action dialogs

* Also in editors.py, $share has no `var`, so is created as a global.

review: Needs Fixing
3905. By Vaibhav Darji

[FIX] Fixed share action according to framework,share_root_url.

Revision history for this message
Vaibhav Darji (vaibhav-openerp) wrote :

Fixed action and share root url.

3906. By Vaibhav Darji

[FIX] Fixed share root url with direct access of user.

Revision history for this message
Vaibhav Darji (vaibhav-openerp) wrote :

Fixed share root url. user can direct access using generated share root url.

3907. By Xavier (Open ERP)

[REV] alterations to server side of share wizard

3908. By Xavier (Open ERP)

[IMP] cleanup JS share button/link

3909. By Xavier (Open ERP)

[FIX] share: naming of classes in web module

3910. By Xavier (Open ERP)

[IMP] share: cleanup whitespace in web module

3911. By Xavier (Open ERP)

[IMP] action: formatting of ShareWizardController.index, bail out early to reduce nesting

3912. By Xavier (Open ERP)

[IMP] share: use **kwargs in dict.update call instead of creating a second dict within it

3913. By Xavier (Open ERP)

[FIX] share: send correct share_root_url to server action, add dbname to share_root_url so user can actually be logged in if server has multiple dbs

Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

The server side should *not* be aware of how the web client works, so I backed the last 2 revisions out and moved that functionality to the web client side, fixed the way the share action is handled/called (leaving most of the work to the existing action dispatcher), and cleaned up the code a bit (class names, nesting/conditions, non-optimal usage of dict.update) before merging it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'share/__openerp__.py'
2--- share/__openerp__.py 2010-10-20 12:20:32 +0000
3+++ share/__openerp__.py 2010-11-22 06:42:44 +0000
4@@ -48,6 +48,7 @@
5 'wizard/share_wizard_view.xml'
6 ],
7 'installable': True,
8+ 'web': True,
9 }
10
11 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
12
13=== added directory 'share/web'
14=== added file 'share/web/__init__.py'
15--- share/web/__init__.py 1970-01-01 00:00:00 +0000
16+++ share/web/__init__.py 2010-11-22 06:42:44 +0000
17@@ -0,0 +1,2 @@
18+import controllers
19+import editors
20\ No newline at end of file
21
22=== added file 'share/web/controllers.py'
23--- share/web/controllers.py 1970-01-01 00:00:00 +0000
24+++ share/web/controllers.py 2010-11-22 06:42:44 +0000
25@@ -0,0 +1,31 @@
26+from openobject.tools import expose, ast
27+from openerp.controllers import actions
28+from openerp.utils import rpc
29+
30+import openerp.controllers
31+import cherrypy
32+
33+
34+
35+class Piratepad(openerp.controllers.SecuredController):
36+ _cp_path = "/share"
37+
38+ @expose()
39+ def index(self, domain, search_domain, context, name):
40+ domain = ast.literal_eval(domain)
41+ search_domain = ast.literal_eval(search_domain)
42+ domain.extend(search_domain)
43+ context = ast.literal_eval(context)
44+ view_name = context.get('_terp_view_name') or name
45+ if view_name:
46+ action_id = rpc.RPCProxy('ir.actions.actions').search([('name','=',view_name)], 0, 0, 0, context)
47+ if action_id:
48+ action_id = action_id[0]
49+ share_model = 'share.wizard'
50+ share_root_url = cherrypy.request.base
51+
52+ share_wiz_id = rpc.RPCProxy('ir.ui.menu').search([('name','=', 'Share Wizard')])
53+ context.update({'active_ids': share_wiz_id, 'active_id': share_wiz_id[0], '_terp_view_name': 'Share Wizard', 'share_root_url': share_root_url})
54+ sharing_view_id = rpc.RPCProxy(share_model).create({'domain': str(domain), 'action_id':action_id}, context)
55+ return actions.execute(rpc.session.execute('object', 'execute', share_model, 'go_step_1', [sharing_view_id], context), ids=[sharing_view_id], context=context)
56+
57
58=== added file 'share/web/editors.py'
59--- share/web/editors.py 1970-01-01 00:00:00 +0000
60+++ share/web/editors.py 2010-11-22 06:42:44 +0000
61@@ -0,0 +1,41 @@
62+# -*- coding: utf-8 -*-
63+import openobject.templating
64+
65+class SidebarTemplateEditor(openobject.templating.TemplateEditor):
66+ templates = ['/openerp/widgets/templates/sidebar.mako']
67+ ADD_SHARE_BUTTON = u'id="sidebar"'
68+
69+ def insert_share_link(self, output):
70+ # Insert the link on the line right after the link to open the
71+ # attachment form
72+ form_opener_insertion = output.index(
73+ '\n',
74+ output.index(self.ADD_SHARE_BUTTON)) + 1
75+ output = output[:form_opener_insertion] + \
76+ '''<div id="share-wizard" class="sideheader-a"><h2>${_("Sharing")}</h2></div>
77+ <ul class="clean-a">
78+ <li>
79+ <a id="sharing" href="#share">${_("Share")}</a>
80+ </li>
81+ </ul>
82+ <script type="text/javascript">
83+ jQuery(document).ready(function() {
84+ var $share = jQuery('#sharing').click(function(){
85+ var _domain = jQuery('#_terp_domain').val();
86+ var _search_domain = jQuery('#_terp_search_domain').val();
87+ var _context = jQuery('#_terp_context').val();
88+ var _view_name = jQuery('#_terp_string').val();
89+ openLink(openobject.http.getURL('/share', {domain: _domain, search_domain: _search_domain, context: _context, name: _view_name}));
90+ return false;
91+ });
92+ });
93+ </script>
94+ \n''' + \
95+ output[form_opener_insertion:]
96+ return output
97+
98+ def edit(self, template, template_text):
99+ output = super(SidebarTemplateEditor, self).edit(template, template_text)
100+
101+ output = self.insert_share_link(output)
102+ return output
103
104=== modified file 'share/wizard/share_wizard.py'
105--- share/wizard/share_wizard.py 2010-11-12 16:23:38 +0000
106+++ share/wizard/share_wizard.py 2010-11-22 06:42:44 +0000
107@@ -98,12 +98,16 @@
108 for new_user in wizard_data.new_users.split('\n'):
109 # attempt to show more user-friendly msg than default constraint error
110 existing = user_obj.search(cr, 1, [('login', '=', new_user)])
111+ password = generate_random_pass()
112+ if wizard_data.share_root_url:
113+ wizard_data.share_root_url = wizard_data.share_root_url + '/openerp/login?db=%s'%(cr.dbname) + '&user=%s'%(new_user) + '&password=%s'%(password)
114+ self.write(cr, 1, [uid], {'share_root_url': wizard_data.share_root_url})
115 if existing:
116 raise osv.except_osv(_('User already exists'),
117 _('This username (%s) already exists, perhaps data has already been shared with this person.\nYou may want to try selecting existing shared users instead.'))
118 user_id = user_obj.create(cr, 1, {
119 'login': new_user,
120- 'password': generate_random_pass(),
121+ 'password': password,
122 'name': new_user,
123 'user_email': new_user,
124 'groups_id': [(6,0,[group_id])],
125@@ -394,7 +398,6 @@
126 # C.
127 all_relations = obj0 + obj1 + obj2 + obj3
128 self._link_or_copy_current_user_rules(cr, uid, group_id, all_relations, context=context)
129-
130 # so far, so good -> populate summary results and return them
131 self._create_result_lines(cr, uid, wizard_data, context=context)
132
133@@ -426,6 +429,7 @@
134 body += _("You may use the following login and password to get access to this protected area:") + "\n"
135 body += "%s: %s" % (_("Username"), result_line.login) + "\n"
136 body += "%s: %s" % (_("Password"), result_line.password) + "\n"
137+ body += "%s: %s" % (_("Database"), cr.dbname) + "\n"
138 else:
139 body += _("This additional data has been automatically added to your current access.\n")
140 body += _("You may use your existing login and password to view it. As a reminder, your login is %s.\n") % result_line.login

Subscribers

People subscribed via source and target branches

to all changes: