[ADD] web part of the share module, addition of DB handling to the module's wizard
bzr revid: xmo@openerp.com-20101122131150-603vgxc9dxg28dz3
This commit is contained in:
commit
e8ee855426
|
@ -48,6 +48,7 @@
|
|||
'wizard/share_wizard_view.xml'
|
||||
],
|
||||
'installable': True,
|
||||
'web': True,
|
||||
}
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
import controllers
|
||||
import editors
|
|
@ -0,0 +1,51 @@
|
|||
import urlparse
|
||||
|
||||
from openobject.tools import expose, ast
|
||||
from openerp.controllers import actions
|
||||
from openerp.utils import rpc
|
||||
|
||||
import openerp.controllers
|
||||
import cherrypy
|
||||
|
||||
|
||||
|
||||
class ShareWizardController(openerp.controllers.SecuredController):
|
||||
_cp_path = "/share"
|
||||
|
||||
@expose()
|
||||
def index(self, domain, search_domain, context, name):
|
||||
context = ast.literal_eval(context)
|
||||
view_name = context.get('_terp_view_name') or name
|
||||
if not view_name: return
|
||||
|
||||
action_id = rpc.RPCProxy('ir.actions.actions').search(
|
||||
[('name','=',view_name)], 0, 0, 0, context)
|
||||
if not action_id: return
|
||||
|
||||
domain = ast.literal_eval(domain)
|
||||
search_domain = ast.literal_eval(search_domain)
|
||||
domain.extend(search_domain)
|
||||
|
||||
action_id = action_id[0]
|
||||
share_model = 'share.wizard'
|
||||
|
||||
scheme, netloc, _, _, _ = urlparse.urlsplit(cherrypy.request.base)
|
||||
share_root_url = urlparse.urlunsplit((
|
||||
scheme, netloc, '/openerp/login',
|
||||
'db=%(dbname)s&user=%(login)s&password=%(password)s', ''))
|
||||
|
||||
share_wiz_id = rpc.RPCProxy('ir.ui.menu').search(
|
||||
[('name','=', 'Share Wizard')])
|
||||
context.update(
|
||||
active_ids=share_wiz_id,
|
||||
active_id=share_wiz_id[0],
|
||||
_terp_view_name='Share Wizard',
|
||||
share_root_url=share_root_url)
|
||||
sharing_view_id = rpc.RPCProxy(share_model).create({
|
||||
'domain': str(domain),
|
||||
'action_id':action_id
|
||||
}, context)
|
||||
return actions.execute(
|
||||
rpc.session.execute('object', 'execute', share_model, 'go_step_1',
|
||||
[sharing_view_id], context),
|
||||
ids=[sharing_view_id], context=context)
|
|
@ -0,0 +1,40 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import openobject.templating
|
||||
|
||||
class ShareActionEditor(openobject.templating.TemplateEditor):
|
||||
templates = ['/openerp/widgets/templates/sidebar.mako']
|
||||
ADD_SHARE_SECTION = u'id="sidebar"'
|
||||
|
||||
def insert_share_link(self, output):
|
||||
# Insert the link on the line right after the link to open the
|
||||
# attachment form
|
||||
share_opener_insertion = output.index(
|
||||
'\n',
|
||||
output.index(self.ADD_SHARE_SECTION)) + 1
|
||||
return output[:share_opener_insertion] + \
|
||||
'''<div id="share-wizard" class="sideheader-a"><h2>${_("Sharing")}</h2></div>
|
||||
<ul class="clean-a">
|
||||
<li>
|
||||
<a id="sharing" href="#share">${_("Share")}</a>
|
||||
</li>
|
||||
</ul>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function() {
|
||||
jQuery("#sharing").click(function() {
|
||||
jQuery(this).attr(
|
||||
"href",
|
||||
openobject.http.getURL('/share', {
|
||||
context: jQuery("#_terp_context").val(),
|
||||
domain: jQuery("#_terp_domain").val(),
|
||||
name: jQuery("#_terp_string").val(),
|
||||
search_domain: jQuery("#_terp_search_domain").val(),
|
||||
}));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
\n''' + \
|
||||
output[share_opener_insertion:]
|
||||
|
||||
def edit(self, template, template_text):
|
||||
return self.insert_share_link(
|
||||
super(ShareActionEditor, self).edit(template, template_text))
|
|
@ -289,7 +289,9 @@ class share_create(osv.osv_memory):
|
|||
user_obj = self.pool.get('res.users')
|
||||
result_obj = self.pool.get('share.wizard.result.line')
|
||||
share_root_url = wizard_data.share_root_url
|
||||
format_url = '%(login)s' in share_root_url and '%(password)s' in share_root_url
|
||||
format_url = '%(login)s' in share_root_url\
|
||||
and '%(password)s' in share_root_url\
|
||||
and '%(dbname)s' in share_root_url
|
||||
existing_passwd_str = _('*usual password*')
|
||||
if wizard_data.user_type == 'new':
|
||||
for email in wizard_data.new_users.split('\n'):
|
||||
|
@ -297,7 +299,8 @@ class share_create(osv.osv_memory):
|
|||
password = user_obj.read(cr, 1, user_id[0], ['password'])['password']
|
||||
share_url = share_root_url % \
|
||||
{'login': email,
|
||||
'password': password} if format_url else share_root_url
|
||||
'password': password,
|
||||
'dbname': cr.dbname} if format_url else share_root_url
|
||||
result_obj.create(cr, uid, {
|
||||
'share_wizard_id': wizard_data.id,
|
||||
'login': email,
|
||||
|
@ -308,8 +311,9 @@ class share_create(osv.osv_memory):
|
|||
# existing users
|
||||
for user in wizard_data.user_ids:
|
||||
share_url = share_root_url % \
|
||||
{'login': email,
|
||||
'password': ''} if format_url else share_root_url
|
||||
{'login': email,
|
||||
'password': '',
|
||||
'dbame': cr.dbname} if format_url else share_root_url
|
||||
result_obj.create(cr, uid, {
|
||||
'share_wizard_id': wizard_data.id,
|
||||
'login': user.user_id.login,
|
||||
|
@ -394,7 +398,6 @@ class share_create(osv.osv_memory):
|
|||
# C.
|
||||
all_relations = obj0 + obj1 + obj2 + obj3
|
||||
self._link_or_copy_current_user_rules(cr, uid, group_id, all_relations, context=context)
|
||||
|
||||
# so far, so good -> populate summary results and return them
|
||||
self._create_result_lines(cr, uid, wizard_data, context=context)
|
||||
|
||||
|
@ -426,6 +429,7 @@ class share_create(osv.osv_memory):
|
|||
body += _("You may use the following login and password to get access to this protected area:") + "\n"
|
||||
body += "%s: %s" % (_("Username"), result_line.login) + "\n"
|
||||
body += "%s: %s" % (_("Password"), result_line.password) + "\n"
|
||||
body += "%s: %s" % (_("Database"), cr.dbname) + "\n"
|
||||
else:
|
||||
body += _("This additional data has been automatically added to your current access.\n")
|
||||
body += _("You may use your existing login and password to view it. As a reminder, your login is %s.\n") % result_line.login
|
||||
|
|
Loading…
Reference in New Issue