2011-06-08 09:07:15 +00:00
|
|
|
import webnotes
|
|
|
|
|
|
|
|
from webnotes.utils import cint, load_json, cstr
|
|
|
|
|
|
|
|
try: import json
|
|
|
|
except: import simplejson as json
|
|
|
|
|
|
|
|
def get_account_settings_url(arg=''):
|
2011-07-06 05:08:03 +00:00
|
|
|
import server_tools.gateway_utils
|
|
|
|
return server_tools.gateway_utils.get_account_settings_url()
|
2011-06-08 09:07:15 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# set max users
|
|
|
|
#
|
|
|
|
def get_max_users(arg=''):
|
2011-07-06 05:08:03 +00:00
|
|
|
from server_tools.gateway_utils import get_max_users_gateway
|
2011-06-08 09:07:15 +00:00
|
|
|
return {
|
|
|
|
'max_users': get_max_users_gateway(),
|
|
|
|
'enabled': cint(webnotes.conn.sql("select count(*) from tabProfile where ifnull(enabled,0)=1 and name not in ('Administrator', 'Guest')")[0][0])
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# enable profile in local
|
|
|
|
#
|
|
|
|
def enable_profile(arg=''):
|
|
|
|
webnotes.conn.sql("update tabProfile set enabled=1 where name=%s", arg)
|
|
|
|
return 1
|
|
|
|
|
|
|
|
#
|
|
|
|
# disable profile in local
|
|
|
|
#
|
|
|
|
def disable_profile(arg=''):
|
|
|
|
if arg=='Administrator':
|
|
|
|
return 'Cannot disable Administrator'
|
|
|
|
|
|
|
|
webnotes.conn.sql("update tabProfile set enabled=0 where name=%s", arg)
|
2012-01-02 10:55:05 +00:00
|
|
|
login_manager = LoginManager()
|
2012-01-03 10:30:03 +00:00
|
|
|
login_manager.logout(user=arg)
|
2011-06-08 09:07:15 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
#
|
|
|
|
# delete user
|
|
|
|
#
|
|
|
|
def delete_user(args):
|
|
|
|
args = json.loads(args)
|
|
|
|
webnotes.conn.sql("update tabProfile set enabled=0, docstatus=2 where name=%s", args['user'])
|
|
|
|
# erpnext-saas
|
|
|
|
if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
|
2011-07-06 05:08:03 +00:00
|
|
|
from server_tools.gateway_utils import remove_user_gateway
|
2011-06-08 09:07:15 +00:00
|
|
|
remove_user_gateway(args['user'])
|
|
|
|
|
|
|
|
#
|
|
|
|
# add user
|
|
|
|
#
|
|
|
|
def add_user(args):
|
|
|
|
args = json.loads(args)
|
|
|
|
# erpnext-saas
|
|
|
|
if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
|
2011-07-06 05:08:03 +00:00
|
|
|
from server_tools.gateway_utils import add_user_gateway
|
2011-06-08 09:07:15 +00:00
|
|
|
add_user_gateway(args['user'])
|
|
|
|
|
2011-12-14 11:42:12 +00:00
|
|
|
add_profile(args)
|
2011-07-13 11:44:38 +00:00
|
|
|
|
2011-06-08 09:07:15 +00:00
|
|
|
#
|
|
|
|
# add profile record
|
|
|
|
#
|
2011-12-14 11:42:12 +00:00
|
|
|
def add_profile(args):
|
2011-06-08 09:07:15 +00:00
|
|
|
from webnotes.utils import validate_email_add
|
|
|
|
from webnotes.model.doc import Document
|
2011-12-14 11:42:12 +00:00
|
|
|
email = args['user']
|
2011-06-08 09:07:15 +00:00
|
|
|
|
|
|
|
sql = webnotes.conn.sql
|
|
|
|
|
|
|
|
if not email:
|
|
|
|
email = webnotes.form_dict.get('user')
|
|
|
|
if not validate_email_add(email):
|
|
|
|
raise Exception
|
|
|
|
return 'Invalid Email Id'
|
|
|
|
|
|
|
|
if sql("select name from tabProfile where name = %s", email):
|
|
|
|
# exists, enable it
|
|
|
|
sql("update tabProfile set enabled = 1, docstatus=0 where name = %s", email)
|
|
|
|
webnotes.msgprint('Profile exists, enabled it')
|
|
|
|
else:
|
|
|
|
# does not exist, create it!
|
|
|
|
pr = Document('Profile')
|
|
|
|
pr.name = email
|
|
|
|
pr.email = email
|
2011-12-14 11:42:12 +00:00
|
|
|
pr.first_name = args.get('first_name')
|
|
|
|
pr.last_name = args.get('last_name')
|
|
|
|
pr.enabled = 1
|
|
|
|
pr.user_type = 'System User'
|
|
|
|
pr.save(1)
|
|
|
|
|
|
|
|
if args.get('password'):
|
|
|
|
sql("""
|
|
|
|
UPDATE tabProfile
|
|
|
|
SET password = PASSWORD(%s)
|
|
|
|
WHERE name = %s""", (args.get('password'), email))
|
2011-06-08 09:07:15 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# post comment
|
|
|
|
#
|
|
|
|
def post_comment(arg):
|
|
|
|
arg = load_json(arg)
|
|
|
|
|
|
|
|
from webnotes.model.doc import Document
|
|
|
|
d = Document('Comment Widget Record')
|
|
|
|
d.comment_doctype = 'My Company'
|
|
|
|
d.comment_docname = arg['uid'] # to
|
|
|
|
d.owner = webnotes.user.name
|
|
|
|
d.comment = arg['comment']
|
|
|
|
d.save(1)
|
|
|
|
|
|
|
|
if cint(arg['notify']):
|
|
|
|
fn = webnotes.conn.sql('select first_name, last_name from tabProfile where name=%s', webnotes.user.name)[0]
|
|
|
|
if fn[0] or f[1]:
|
|
|
|
fn = cstr(fn[0]) + (fn[0] and ' ' or '') + cstr(fn[1])
|
|
|
|
else:
|
|
|
|
fn = webnotes.user.name
|
|
|
|
|
|
|
|
message = '''A new comment has been posted on your page by %s:
|
|
|
|
|
|
|
|
<b>Comment:</b> %s
|
|
|
|
|
|
|
|
To answer, please login to your erpnext account!
|
2012-01-12 08:16:46 +00:00
|
|
|
|
|
|
|
<a href='https://signin.erpnext.com'>https://signin.erpnext.com</a>
|
2011-06-08 09:07:15 +00:00
|
|
|
''' % (fn, arg['comment'])
|
|
|
|
|
2012-01-12 08:16:46 +00:00
|
|
|
from webnotes.model.code import get_obj
|
|
|
|
note = get_obj('Notification Control')
|
|
|
|
email_msg = note.prepare_message({
|
|
|
|
'type': 'New Comment',
|
|
|
|
'message': message
|
|
|
|
})
|
|
|
|
|
|
|
|
sender = webnotes.user.name!='Administrator' and webnotes.user.name or 'support+admin_post@erpnext.com'
|
|
|
|
|
|
|
|
from webnotes.utils.email_lib import sendmail
|
|
|
|
sendmail([arg['uid']], sender, email_msg, fn + ' has posted a new comment')
|
2011-06-08 09:07:15 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# update read messages
|
|
|
|
#
|
|
|
|
def set_read_all_messages(arg=''):
|
|
|
|
webnotes.conn.sql("""UPDATE `tabComment Widget Record`
|
|
|
|
SET docstatus = 1
|
|
|
|
WHERE comment_doctype = 'My Company'
|
|
|
|
AND comment_docname = %s
|
|
|
|
""", webnotes.user.name)
|
2011-08-25 09:45:25 +00:00
|
|
|
|
|
|
|
def update_security(args=''):
|
|
|
|
import json
|
|
|
|
args = json.loads(args)
|
|
|
|
webnotes.conn.set_value('Profile', args['user'], 'restrict_ip', args.get('restrict_ip'))
|
|
|
|
webnotes.conn.set_value('Profile', args['user'], 'login_after', args.get('login_after'))
|
|
|
|
webnotes.conn.set_value('Profile', args['user'], 'login_before', args.get('login_before'))
|
|
|
|
|
|
|
|
if 'new_password' in args:
|
|
|
|
if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
|
|
|
|
import server_tools.gateway_utils
|
2011-11-30 09:53:37 +00:00
|
|
|
res = server_tools.gateway_utils.change_password('', args['new_password'], args['user'], args['sys_admin_pwd'])
|
|
|
|
if 'Traceback' not in res['message']:
|
|
|
|
webnotes.msgprint(res['message'])
|
2011-08-25 09:45:25 +00:00
|
|
|
else:
|
|
|
|
webnotes.conn.sql("update tabProfile set password=password(%s) where name=%s", (args['new_password'], args['user']))
|
2011-11-30 09:53:37 +00:00
|
|
|
else: webnotes.msgprint('Settings Updated')
|