2009-10-20 10:52:23 +00:00
# -*- coding: utf-8 -*-
2006-12-07 13:41:40 +00:00
##############################################################################
2010-01-13 06:25:06 +00:00
#
2008-11-19 09:37:50 +00:00
# OpenERP, Open Source Management Solution
2009-10-14 12:32:15 +00:00
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
2008-06-16 11:00:21 +00:00
#
2008-11-03 18:27:16 +00:00
# This program is free software: you can redistribute it and/or modify
2009-10-14 12:32:15 +00:00
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
2006-12-07 13:41:40 +00:00
#
2008-11-03 18:27:16 +00:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2009-10-14 12:32:15 +00:00
# GNU Affero General Public License for more details.
2006-12-07 13:41:40 +00:00
#
2009-10-14 12:32:15 +00:00
# You should have received a copy of the GNU Affero General Public License
2010-01-13 06:25:06 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2006-12-07 13:41:40 +00:00
#
##############################################################################
from osv import fields , osv
2010-02-09 13:46:52 +00:00
from osv . orm import except_orm , browse_record
2006-12-07 13:41:40 +00:00
import tools
2008-06-16 18:27:17 +00:00
import pytz
2010-01-29 06:06:44 +00:00
import pooler
2009-03-06 18:06:50 +00:00
from tools . translate import _
2010-01-29 06:06:44 +00:00
from service import security
2010-02-08 06:05:22 +00:00
import netsvc
2006-12-07 13:41:40 +00:00
class groups ( osv . osv ) :
2008-07-22 14:24:36 +00:00
_name = " res.groups "
2008-09-03 18:11:03 +00:00
_order = ' name '
2008-07-22 14:24:36 +00:00
_columns = {
' name ' : fields . char ( ' Group Name ' , size = 64 , required = True ) ,
' model_access ' : fields . one2many ( ' ir.model.access ' , ' group_id ' , ' Access Controls ' ) ,
2010-04-29 12:01:58 +00:00
' rule_groups ' : fields . many2many ( ' ir.rule ' , ' rule_group_rel ' ,
2008-07-22 14:24:36 +00:00
' group_id ' , ' rule_group_id ' , ' Rules ' , domain = " [( ' global ' , ' <> ' , True)] " ) ,
' menu_access ' : fields . many2many ( ' ir.ui.menu ' , ' ir_ui_menu_group_rel ' , ' gid ' , ' menu_id ' , ' Access Menu ' ) ,
' comment ' : fields . text ( ' Comment ' , size = 250 ) ,
}
_sql_constraints = [
( ' name_uniq ' , ' unique (name) ' , ' The name of the group must be unique ! ' )
]
2010-02-16 06:31:14 +00:00
2009-09-17 07:27:12 +00:00
def copy ( self , cr , uid , id , default = None , context = { } ) :
group_name = self . read ( cr , uid , [ id ] , [ ' name ' ] ) [ 0 ] [ ' name ' ]
default . update ( { ' name ' : group_name + ' (copy) ' } )
return super ( groups , self ) . copy ( cr , uid , id , default , context )
2010-04-29 12:01:58 +00:00
2008-07-22 14:24:36 +00:00
def write ( self , cr , uid , ids , vals , context = None ) :
if ' name ' in vals :
if vals [ ' name ' ] . startswith ( ' - ' ) :
raise osv . except_osv ( _ ( ' Error ' ) ,
_ ( ' The name of the group can not start with " - " ' ) )
res = super ( groups , self ) . write ( cr , uid , ids , vals , context = context )
# Restart the cache on the company_get method
2009-01-26 23:19:05 +00:00
self . pool . get ( ' ir.model.access ' ) . call_cache_clearing_methods ( cr )
2008-07-22 14:24:36 +00:00
return res
2007-08-09 06:06:27 +00:00
2008-07-22 14:24:36 +00:00
def create ( self , cr , uid , vals , context = None ) :
if ' name ' in vals :
if vals [ ' name ' ] . startswith ( ' - ' ) :
raise osv . except_osv ( _ ( ' Error ' ) ,
_ ( ' The name of the group can not start with " - " ' ) )
2010-01-13 06:25:06 +00:00
gid = super ( groups , self ) . create ( cr , uid , vals , context = context )
2009-11-03 06:46:36 +00:00
if context and context . get ( ' noadmin ' , False ) :
pass
else :
# assign this new group to user_root
user_obj = self . pool . get ( ' res.users ' )
aid = user_obj . browse ( cr , 1 , user_obj . _get_admin_id ( cr ) )
if aid :
aid . write ( { ' groups_id ' : [ ( 4 , gid ) ] } )
2009-02-04 14:36:29 +00:00
return gid
2007-08-09 06:06:27 +00:00
2009-04-21 16:19:37 +00:00
def copy ( self , cr , uid , id , default = { } , context = { } , done_list = [ ] , local = False ) :
2009-11-24 14:44:05 +00:00
group = self . browse ( cr , uid , id , context = context )
2009-04-21 16:19:37 +00:00
default = default . copy ( )
2009-11-24 14:44:05 +00:00
if not ' name ' in default :
default [ ' name ' ] = group [ ' name ' ]
2009-04-21 16:19:37 +00:00
default [ ' name ' ] = default [ ' name ' ] + _ ( ' (copy) ' )
return super ( groups , self ) . copy ( cr , uid , id , default , context = context )
2006-12-07 13:41:40 +00:00
groups ( )
class roles ( osv . osv ) :
2008-07-22 14:24:36 +00:00
_name = " res.roles "
_columns = {
' name ' : fields . char ( ' Role Name ' , size = 64 , required = True ) ,
' parent_id ' : fields . many2one ( ' res.roles ' , ' Parent ' , select = True ) ,
2009-01-26 15:04:53 +00:00
' child_id ' : fields . one2many ( ' res.roles ' , ' parent_id ' , ' Children ' ) ,
2008-07-28 15:43:35 +00:00
' users ' : fields . many2many ( ' res.users ' , ' res_roles_users_rel ' , ' rid ' , ' uid ' , ' Users ' ) ,
2008-07-22 14:24:36 +00:00
}
_defaults = {
}
def check ( self , cr , uid , ids , role_id ) :
if role_id in ids :
return True
2008-12-09 12:37:22 +00:00
cr . execute ( ' select parent_id from res_roles where id= %s ' , ( role_id , ) )
2008-07-22 14:24:36 +00:00
roles = cr . fetchone ( ) [ 0 ]
if roles :
return self . check ( cr , uid , ids , roles )
return False
2006-12-07 13:41:40 +00:00
roles ( )
2008-06-16 18:27:17 +00:00
def _lang_get ( self , cr , uid , context = { } ) :
2008-07-22 14:24:36 +00:00
obj = self . pool . get ( ' res.lang ' )
ids = obj . search ( cr , uid , [ ] )
res = obj . read ( cr , uid , ids , [ ' code ' , ' name ' ] , context )
res = [ ( r [ ' code ' ] , r [ ' name ' ] ) for r in res ]
return res
2008-06-18 06:17:51 +00:00
def _tz_get ( self , cr , uid , context = { } ) :
2008-07-22 14:24:36 +00:00
return [ ( x , x ) for x in pytz . all_timezones ]
2008-06-16 18:27:17 +00:00
2006-12-07 13:41:40 +00:00
class users ( osv . osv ) :
2009-02-04 14:36:29 +00:00
__admin_ids = { }
2010-01-29 06:06:44 +00:00
_uid_cache = { }
2008-07-22 14:24:36 +00:00
_name = " res.users "
2010-01-13 06:25:06 +00:00
2010-01-27 11:28:49 +00:00
WELCOME_MAIL_SUBJECT = u " Welcome to OpenERP "
2010-01-27 12:14:12 +00:00
WELCOME_MAIL_BODY = u " An OpenERP account has been created for you, " \
" \" %(name)s \" . \n \n Your login is %(login)s , " \
2010-01-27 11:28:49 +00:00
" you should ask your supervisor or system administrator if you " \
" haven ' t been given your password yet. \n \n " \
" If you aren ' t %(name)s , this email reached you errorneously, " \
" please delete it. "
def get_welcome_mail_subject ( self , cr , uid , context = None ) :
""" Returns the subject of the mail new users receive (when
created via the res . config . users wizard ) , default implementation
is to return config_users . WELCOME_MAIL_SUBJECT
"""
return self . WELCOME_MAIL_SUBJECT
def get_welcome_mail_body ( self , cr , uid , context = None ) :
""" Returns the subject of the mail new users receive (when
created via the res . config . users wizard ) , default implementation
is to return config_users . WELCOME_MAIL_BODY
"""
return self . WELCOME_MAIL_BODY
2009-09-17 07:27:12 +00:00
def get_current_company ( self , cr , uid ) :
res = [ ]
cr . execute ( ' select company_id, res_company.name from res_users left join res_company on res_company.id = company_id where res_users.id= %s ' % uid )
res = cr . fetchall ( )
2010-01-13 06:25:06 +00:00
return res
2010-01-27 11:28:49 +00:00
def send_welcome_email ( self , cr , uid , id , context = None ) :
logger = netsvc . Logger ( )
user = self . pool . get ( ' res.users ' ) . read ( cr , uid , id , context = context )
if not tools . config . get ( ' smtp_server ' ) :
logger . notifyChannel ( ' mails ' , netsvc . LOG_WARNING ,
_ ( ' " smtp_server " needs to be set to send mails to users ' ) )
return False
if not tools . config . get ( ' email_from ' ) :
logger . notifyChannel ( " mails " , netsvc . LOG_WARNING ,
_ ( ' " email_from " needs to be set to send welcome mails '
' to users ' ) )
return False
if not user . get ( ' email ' ) :
return False
2010-01-27 12:14:12 +00:00
return tools . email_send ( email_from = None , email_to = [ user [ ' email ' ] ] ,
2010-01-27 11:28:49 +00:00
subject = self . get_welcome_mail_subject (
cr , uid , context = context ) ,
body = self . get_welcome_mail_body (
2010-01-31 17:48:44 +00:00
cr , uid , context = context ) % user )
2010-01-27 11:28:49 +00:00
2008-07-22 14:24:36 +00:00
_columns = {
2010-01-24 15:57:12 +00:00
' name ' : fields . char ( ' Name ' , size = 64 , required = True , select = True ,
help = " The new user ' s real name, used for searching "
" and most listings " ) ,
' login ' : fields . char ( ' Login ' , size = 64 , required = True ,
help = " Used to log into the system " ) ,
2008-11-19 20:22:44 +00:00
' password ' : fields . char ( ' Password ' , size = 64 , invisible = True , help = " Keep empty if you don ' t want the user to be able to connect on the system. " ) ,
2010-01-27 11:28:49 +00:00
' email ' : fields . char ( ' E-mail ' , size = 64 ,
help = ' If an email is provided, the user will be sent a message '
' welcoming him. \n \n Warning: if " email_from " and " smtp_server " '
" aren ' t configured, it won ' t be possible to email new "
" users. " ) ,
2008-07-22 14:24:36 +00:00
' signature ' : fields . text ( ' Signature ' , size = 64 ) ,
' address_id ' : fields . many2one ( ' res.partner.address ' , ' Address ' ) ,
' active ' : fields . boolean ( ' Active ' ) ,
' action_id ' : fields . many2one ( ' ir.actions.actions ' , ' Home Action ' ) ,
' menu_id ' : fields . many2one ( ' ir.actions.actions ' , ' Menu Action ' ) ,
' groups_id ' : fields . many2many ( ' res.groups ' , ' res_groups_users_rel ' , ' uid ' , ' gid ' , ' Groups ' ) ,
' roles_id ' : fields . many2many ( ' res.roles ' , ' res_roles_users_rel ' , ' uid ' , ' rid ' , ' Roles ' ) ,
2010-01-24 15:57:12 +00:00
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' , required = True ,
help = " The company this user is currently working for. " ) ,
2010-02-28 08:02:14 +00:00
' company_ids ' : fields . many2many ( ' res.company ' , ' res_company_users_rel ' , ' user_id ' , ' cid ' , ' Companies ' ) ,
2010-01-24 15:57:12 +00:00
' context_lang ' : fields . selection ( _lang_get , ' Language ' , required = True ,
help = " Sets the language for the user ' s user interface, when UI "
" translations are available " ) ,
' context_tz ' : fields . selection ( _tz_get , ' Timezone ' , size = 64 ,
help = " The user ' s timezone, used to perform timezone conversions "
" between the server and the client. " ) ,
2008-07-22 14:24:36 +00:00
}
def read ( self , cr , uid , ids , fields = None , context = None , load = ' _classic_read ' ) :
2008-09-23 16:24:56 +00:00
def override_password ( o ) :
2009-01-28 11:20:14 +00:00
if ' password ' in o and ( ' id ' not in o or o [ ' id ' ] != uid ) :
2008-09-23 16:24:56 +00:00
o [ ' password ' ] = ' ******** '
return o
2008-07-22 14:24:36 +00:00
result = super ( users , self ) . read ( cr , uid , ids , fields , context , load )
canwrite = self . pool . get ( ' ir.model.access ' ) . check ( cr , uid , ' res.users ' , ' write ' , raise_exception = False )
if not canwrite :
2008-09-23 16:24:56 +00:00
if isinstance ( ids , ( int , float ) ) :
result = override_password ( result )
else :
result = map ( override_password , result )
2008-07-22 14:24:36 +00:00
return result
2008-05-26 12:43:53 +00:00
2010-05-07 14:20:25 +00:00
def _check_company ( self , cr , uid , ids , context = None ) :
return all ( this . company_id in this . company_ids for this in self . browse ( cr , uid , ids , context ) )
_constraints = [
( _check_company , ' The chosen company is not in the allowed companies ' , [ ' company_id ' , ' company_ids ' ] ) ,
]
2008-07-22 14:24:36 +00:00
_sql_constraints = [
2009-09-17 07:27:12 +00:00
( ' login_key ' , ' UNIQUE (login) ' , _ ( ' You can not have two users with the same login ! ' ) )
2008-07-22 14:24:36 +00:00
]
2009-02-04 14:36:29 +00:00
def _get_admin_id ( self , cr ) :
if self . __admin_ids . get ( cr . dbname ) is None :
ir_model_data_obj = self . pool . get ( ' ir.model.data ' )
mdid = ir_model_data_obj . _get_id ( cr , 1 , ' base ' , ' user_root ' )
self . __admin_ids [ cr . dbname ] = ir_model_data_obj . read ( cr , 1 , [ mdid ] , [ ' res_id ' ] ) [ 0 ] [ ' res_id ' ]
return self . __admin_ids [ cr . dbname ]
2008-07-22 14:24:36 +00:00
def _get_action ( self , cr , uid , context = { } ) :
ids = self . pool . get ( ' ir.ui.menu ' ) . search ( cr , uid , [ ( ' usage ' , ' = ' , ' menu ' ) ] )
return ids and ids [ 0 ] or False
2008-06-30 15:33:15 +00:00
2010-05-07 14:20:25 +00:00
def _get_company ( self , cr , uid , context = None , uid2 = False ) :
2010-02-02 13:51:00 +00:00
if not uid2 :
uid2 = uid
2010-02-19 11:05:41 +00:00
user = self . pool . get ( ' res.users ' ) . read ( cr , uid , uid2 , [ ' company_id ' ] , context )
company_id = user . get ( ' company_id ' , False )
return company_id and company_id [ 0 ] or False
2008-06-30 15:33:15 +00:00
2010-05-07 14:20:25 +00:00
def _get_companies ( self , cr , uid , context = None ) :
c = self . _get_company ( cr , uid , context )
if c :
return [ c ]
return False
2008-07-22 14:24:36 +00:00
def _get_menu ( self , cr , uid , context = { } ) :
ids = self . pool . get ( ' ir.actions.act_window ' ) . search ( cr , uid , [ ( ' usage ' , ' = ' , ' menu ' ) ] )
return ids and ids [ 0 ] or False
2008-06-30 15:33:15 +00:00
2008-11-21 11:30:22 +00:00
def _get_group ( self , cr , uid , context = { } ) :
ids = self . pool . get ( ' res.groups ' ) . search ( cr , uid , [ ( ' name ' , ' = ' , ' Employee ' ) ] )
return ids or False
2008-07-22 14:24:36 +00:00
_defaults = {
2009-12-17 16:16:42 +00:00
' password ' : lambda * a : ' ' ,
2008-07-22 14:24:36 +00:00
' context_lang ' : lambda * args : ' en_US ' ,
2009-12-17 16:16:42 +00:00
' active ' : lambda * a : True ,
2008-07-22 14:24:36 +00:00
' menu_id ' : _get_menu ,
' action_id ' : _get_menu ,
' company_id ' : _get_company ,
2010-05-07 14:20:25 +00:00
' company_ids ' : _get_companies ,
2008-11-21 11:30:22 +00:00
' groups_id ' : _get_group ,
2009-12-17 19:42:50 +00:00
' address_id ' : False ,
2008-07-22 14:24:36 +00:00
}
2010-02-02 13:51:00 +00:00
def company_get ( self , cr , uid , uid2 , context = { } ) :
return self . _get_company ( cr , uid , context = context , uid2 = uid2 )
2008-07-22 14:24:36 +00:00
company_get = tools . cache ( ) ( company_get )
2006-12-07 13:41:40 +00:00
2008-07-22 14:24:36 +00:00
def write ( self , cr , uid , ids , values , * args , * * argv ) :
if ( ids == [ uid ] ) :
ok = True
for k in values . keys ( ) :
2009-12-23 16:37:11 +00:00
if k not in ( ' password ' , ' signature ' , ' action_id ' , ' context_lang ' , ' context_tz ' , ' company_id ' ) :
2008-07-22 14:24:36 +00:00
ok = False
if ok :
uid = 1
res = super ( users , self ) . write ( cr , uid , ids , values , * args , * * argv )
2009-01-05 21:17:46 +00:00
self . company_get . clear_cache ( cr . dbname )
2008-07-22 14:24:36 +00:00
# Restart the cache on the company_get method
2009-01-26 23:19:05 +00:00
self . pool . get ( ' ir.model.access ' ) . call_cache_clearing_methods ( cr )
2008-07-22 14:24:36 +00:00
return res
2006-12-07 13:41:40 +00:00
2009-01-21 11:19:56 +00:00
def unlink ( self , cr , uid , ids , context = None ) :
2008-07-22 14:24:36 +00:00
if 1 in ids :
2008-09-02 21:31:44 +00:00
raise osv . except_osv ( _ ( ' Can not remove root user! ' ) , _ ( ' You can not remove the admin user as it is used internally for resources created by OpenERP (updates, module installation, ...) ' ) )
2009-01-21 11:19:56 +00:00
return super ( users , self ) . unlink ( cr , uid , ids , context = context )
2008-06-20 11:49:23 +00:00
2009-12-09 11:42:41 +00:00
def name_search ( self , cr , user , name = ' ' , args = None , operator = ' ilike ' , context = None , limit = 100 ) :
2008-07-22 14:24:36 +00:00
if not args :
args = [ ]
if not context :
context = { }
ids = [ ]
if name :
ids = self . search ( cr , user , [ ( ' login ' , ' = ' , name ) ] + args , limit = limit )
if not ids :
ids = self . search ( cr , user , [ ( ' name ' , operator , name ) ] + args , limit = limit )
return self . name_get ( cr , user , ids )
2008-06-20 11:49:23 +00:00
2008-07-22 14:24:36 +00:00
def copy ( self , cr , uid , id , default = None , context = { } ) :
login = self . read ( cr , uid , [ id ] , [ ' login ' ] ) [ 0 ] [ ' login ' ]
default . update ( { ' login ' : login + ' (copy) ' } )
return super ( users , self ) . copy ( cr , uid , id , default , context )
2008-06-16 18:27:17 +00:00
2008-09-22 11:13:18 +00:00
def context_get ( self , cr , uid , context = None ) :
2008-07-22 14:24:36 +00:00
user = self . browse ( cr , uid , uid , context )
result = { }
for k in self . _columns . keys ( ) :
if k . startswith ( ' context_ ' ) :
2010-02-11 05:29:24 +00:00
res = getattr ( user , k ) or False
2010-02-09 13:46:52 +00:00
if isinstance ( res , browse_record ) :
2010-02-11 05:29:24 +00:00
res = res . id
2010-02-11 07:08:49 +00:00
result [ k [ 8 : ] ] = res or False
2008-07-22 14:24:36 +00:00
return result
2008-06-16 18:27:17 +00:00
2010-01-13 06:25:06 +00:00
def action_get ( self , cr , uid , context = { } ) :
dataobj = self . pool . get ( ' ir.model.data ' )
data_id = dataobj . _get_id ( cr , 1 , ' base ' , ' action_res_users_my ' )
return dataobj . browse ( cr , uid , data_id , context ) . res_id
2010-01-29 06:06:44 +00:00
def login ( self , db , login , password ) :
if not password :
return False
2010-02-11 05:29:24 +00:00
cr = pooler . get_db ( db ) . cursor ( )
2010-01-29 06:06:44 +00:00
cr . execute ( ' select id from res_users where login= %s and password= %s and active ' , ( tools . ustr ( login ) , tools . ustr ( password ) ) )
res = cr . fetchone ( )
cr . close ( )
if res :
return res [ 0 ]
else :
return False
def check_super ( self , passwd ) :
if passwd == tools . config [ ' admin_passwd ' ] :
return True
else :
raise security . ExceptionNoTb ( ' AccessDenied ' )
def check ( self , db , uid , passwd ) :
if not passwd :
return False
cached_pass = self . _uid_cache . get ( db , { } ) . get ( uid )
if ( cached_pass is not None ) and cached_pass == passwd :
return True
2010-02-11 05:29:24 +00:00
cr = pooler . get_db ( db ) . cursor ( )
cr . execute ( ' select count(1) from res_users where id= %s and password= %s and active= %s ' , ( int ( uid ) , passwd , True ) )
2010-01-29 06:06:44 +00:00
res = cr . fetchone ( ) [ 0 ]
cr . close ( )
if not bool ( res ) :
raise security . ExceptionNoTb ( ' AccessDenied ' )
if res :
if self . _uid_cache . has_key ( db ) :
ulist = self . _uid_cache [ db ]
ulist [ uid ] = passwd
else :
self . _uid_cache [ db ] = { uid : passwd }
return bool ( res )
def access ( self , db , uid , passwd , sec_level , ids ) :
if not passwd :
return False
2010-02-11 05:29:24 +00:00
cr = pooler . get_db ( db ) . cursor ( )
2010-01-29 06:06:44 +00:00
cr . execute ( ' select id from res_users where id= %s and password= %s ' , ( uid , passwd ) )
res = cr . fetchone ( )
cr . close ( )
if not res :
raise security . ExceptionNoTb ( ' Bad username or password ' )
return res [ 0 ]
2010-02-11 05:29:24 +00:00
2009-12-04 10:15:43 +00:00
users ( )
2008-06-16 18:27:17 +00:00
2009-12-04 10:15:43 +00:00
class config_users ( osv . osv_memory ) :
_name = ' res.config.users '
2009-12-17 19:42:50 +00:00
_inherit = [ ' res.users ' , ' res.config ' ]
2008-06-20 11:49:23 +00:00
2009-12-17 19:42:50 +00:00
def _generate_signature ( self , cr , name , email , context = None ) :
return _ ( ' -- \n %(name)s %(email)s \n ' ) % {
' name ' : name or ' ' ,
' email ' : email and ' < ' + email + ' > ' or ' ' ,
}
2008-07-02 08:42:47 +00:00
2009-12-08 14:48:35 +00:00
def create_user ( self , cr , uid , new_id , context = None ) :
2010-01-26 15:30:45 +00:00
""" create a new res.user instance from the data stored
in the current res . config . users .
If an email address was filled in for the user , sends a mail
composed of the return values of ` ` get_welcome_mail_subject ` `
and ` ` get_welcome_mail_body ` ` ( which should be unicode values ) ,
with the user ' s data %-f ormatted into the mail body
"""
2009-12-17 19:42:50 +00:00
base_data = self . read ( cr , uid , new_id , context = context )
partner_id = self . pool . get ( ' res.partner ' ) . main_partner ( cr , uid )
address = self . pool . get ( ' res.partner.address ' ) . create (
cr , uid , { ' name ' : base_data [ ' name ' ] ,
' email ' : base_data [ ' email ' ] ,
' partner_id ' : partner_id , } ,
context )
user_data = dict (
2009-12-17 19:47:16 +00:00
base_data ,
2009-12-17 19:42:50 +00:00
signature = self . _generate_signature (
cr , base_data [ ' name ' ] , base_data [ ' email ' ] , context = context ) ,
address_id = address ,
)
2010-01-27 11:28:49 +00:00
new_user = self . pool . get ( ' res.users ' ) . create (
2009-12-17 19:42:50 +00:00
cr , uid , user_data , context )
2010-01-27 11:28:49 +00:00
self . send_welcome_email ( cr , uid , new_user , context = context )
2009-12-10 07:32:13 +00:00
def execute ( self , cr , uid , ids , context = None ) :
2010-01-26 16:42:37 +00:00
' Do nothing on execution, just launch the next action/todo '
pass
def action_add ( self , cr , uid , ids , context = None ) :
' Create a user, and re-display the view '
2009-12-08 14:48:35 +00:00
self . create_user ( cr , uid , ids [ 0 ] , context = context )
2008-07-22 14:24:36 +00:00
return {
2009-12-04 10:15:43 +00:00
' view_type ' : ' form ' ,
" view_mode " : ' form ' ,
' res_model ' : ' res.config.users ' ,
' view_id ' : self . pool . get ( ' ir.ui.view ' ) \
. search ( cr , uid , [ ( ' name ' , ' = ' , ' res.config.users.confirm.form ' ) ] ) ,
' type ' : ' ir.actions.act_window ' ,
' target ' : ' new ' ,
}
config_users ( )
2006-12-07 13:41:40 +00:00
2008-07-28 15:43:35 +00:00
class groups2 ( osv . osv ) : ##FIXME: Is there a reason to inherit this object ?
2008-07-22 14:24:36 +00:00
_inherit = ' res.groups '
_columns = {
' users ' : fields . many2many ( ' res.users ' , ' res_groups_users_rel ' , ' gid ' , ' uid ' , ' Users ' ) ,
}
2007-07-19 13:47:25 +00:00
groups2 ( )
2008-06-21 09:54:30 +00:00
class res_config_view ( osv . osv_memory ) :
2009-12-04 10:15:43 +00:00
_name = ' res.config.view '
2009-12-04 10:58:21 +00:00
_inherit = ' res.config '
2008-07-22 14:24:36 +00:00
_columns = {
' name ' : fields . char ( ' Name ' , size = 64 ) ,
2009-12-17 15:30:08 +00:00
' view ' : fields . selection ( [ ( ' simple ' , ' Simplified ' ) ,
( ' extended ' , ' Extended ' ) ] ,
' Interface ' , required = True ) ,
2008-06-21 09:54:30 +00:00
}
2008-07-22 14:24:36 +00:00
_defaults = {
' view ' : lambda * args : ' simple ' ,
2008-08-24 17:10:28 +00:00
}
2008-07-07 09:41:01 +00:00
2009-12-10 07:32:13 +00:00
def execute ( self , cr , uid , ids , context = None ) :
2008-07-22 14:24:36 +00:00
res = self . read ( cr , uid , ids ) [ 0 ]
users_obj = self . pool . get ( ' res.users ' )
group_obj = self . pool . get ( ' res.groups ' )
if ' view ' in res and res [ ' view ' ] and res [ ' view ' ] == ' extended ' :
2008-09-19 07:28:20 +00:00
group_ids = group_obj . search ( cr , uid , [ ( ' name ' , ' ilike ' , ' Extended ' ) ] )
2008-07-22 14:24:36 +00:00
if group_ids and len ( group_ids ) :
2008-09-19 07:28:20 +00:00
users_obj . write ( cr , uid , [ uid ] , {
2008-07-22 14:24:36 +00:00
' groups_id ' : [ ( 4 , group_ids [ 0 ] ) ]
} , context = context )
2008-06-21 09:54:30 +00:00
res_config_view ( )
2008-09-22 11:13:18 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: