[minor] [cleanup] add roles in setup control

This commit is contained in:
Anand Doshi
2013-10-07 19:25:50 +05:30
parent 988096e82d
commit 8e65dae35c

View File

@@ -4,17 +4,16 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cint, cstr, getdate, now, nowdate, get_defaults from webnotes.utils import cint, cstr, getdate, nowdate, get_defaults
from webnotes.model.doc import Document, addchild from webnotes.model.doc import Document
from webnotes.model.code import get_obj from webnotes import msgprint
from webnotes import session, form, msgprint
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
def setup_account(self, args): def setup_account(self, args):
import webnotes, json import json
if isinstance(args, basestring): if isinstance(args, basestring):
args = json.loads(args) args = json.loads(args)
webnotes.conn.begin() webnotes.conn.begin()
@@ -175,7 +174,6 @@ class DocType:
system_managers = get_system_managers() system_managers = get_system_managers()
if not system_managers: return if not system_managers: return
from webnotes.model.doc import Document
for company in companies_list: for company in companies_list:
if company and company[0]: if company and company[0]:
edigest = webnotes.bean({ edigest = webnotes.bean({
@@ -216,28 +214,19 @@ class DocType:
abbr = cstr(curr_year)[-2:] + '-' + cstr(curr_year+1)[-2:] abbr = cstr(curr_year)[-2:] + '-' + cstr(curr_year+1)[-2:]
return fy, stdt, abbr return fy, stdt, abbr
def create_profile(self, user_email, user_fname, user_lname, pwd=None): def add_all_roles_to(profile):
pr = Document('Profile') if isinstance(profile, basestring):
pr.first_name = user_fname profile = webnotes.bean("Profile", profile)
pr.last_name = user_lname
pr.name = pr.email = user_email
pr.enabled = 1
pr.save(1)
if pwd:
webnotes.conn.sql("""insert into __Auth (user, `password`)
values (%s, password(%s))
on duplicate key update `password`=password(%s)""",
(user_email, pwd, pwd))
add_all_roles_to(pr.name)
def add_all_roles_to(name):
profile = webnotes.doc("Profile", name)
for role in webnotes.conn.sql("""select name from tabRole"""): for role in webnotes.conn.sql("""select name from tabRole"""):
if role[0] not in ["Administrator", "Guest", "All", "Customer", "Supplier", "Partner"]: if role[0] not in ["Administrator", "Guest", "All", "Customer", "Supplier", "Partner"]:
d = profile.addchild("user_roles", "UserRole") profile.doclist.append({
d.role = role[0] "doctype": "UserRole",
d.insert() "parentfield": "user_roles",
"role": role[0]
})
profile.save()
def create_territories(): def create_territories():
"""create two default territories, one for home country and one named Rest of the World""" """create two default territories, one for home country and one named Rest of the World"""