Remove all roles for Guest user
This commit is contained in:
parent
667d3e16ad
commit
bef7b9740c
4 changed files with 27 additions and 21 deletions
|
|
@ -29,6 +29,7 @@ class User(Document):
|
|||
self.add_system_manager_role()
|
||||
self.check_enable_disable()
|
||||
self.update_gravatar()
|
||||
self.remove_all_roles_for_guest()
|
||||
|
||||
def check_enable_disable(self):
|
||||
# do not allow disabling administrator/guest
|
||||
|
|
@ -48,7 +49,7 @@ class User(Document):
|
|||
self.get("user_roles")]):
|
||||
return
|
||||
|
||||
if self.user_type == "System User" and not self.get_other_system_managers():
|
||||
if self.name not in STANDARD_USERS and self.user_type == "System User" and not self.get_other_system_managers():
|
||||
msgprint(_("Adding System Manager to this User as there must be atleast one System Manager"))
|
||||
self.append("user_roles", {
|
||||
"doctype": "UserRole",
|
||||
|
|
@ -244,6 +245,10 @@ class User(Document):
|
|||
|
||||
self.save()
|
||||
|
||||
def remove_all_roles_for_guest(self):
|
||||
if self.name == "Guest":
|
||||
self.set("user_roles", list(set(d for d in self.get("user_roles") if d.role == "Guest")))
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_languages():
|
||||
from frappe.translate import get_lang_dict
|
||||
|
|
|
|||
|
|
@ -15,20 +15,20 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data
|
|||
all_doctypes = all_doctypes=="Yes"
|
||||
if not parent_doctype:
|
||||
parent_doctype = doctype
|
||||
|
||||
|
||||
column_start_end = {}
|
||||
|
||||
|
||||
if all_doctypes:
|
||||
doctype_parentfield = {}
|
||||
child_doctypes = []
|
||||
for df in frappe.get_meta(doctype).get_table_fields():
|
||||
child_doctypes.append(df.options)
|
||||
doctype_parentfield[df.options] = df.fieldname
|
||||
|
||||
|
||||
def add_main_header():
|
||||
w.writerow(['Data Import Template'])
|
||||
w.writerow([data_keys.main_table, doctype])
|
||||
|
||||
|
||||
if parent_doctype != doctype:
|
||||
w.writerow([data_keys.parent_table, parent_doctype])
|
||||
else:
|
||||
|
|
@ -50,7 +50,7 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data
|
|||
def build_field_columns(dt):
|
||||
meta = frappe.get_meta(dt)
|
||||
|
||||
tablecolumns = filter(None,
|
||||
tablecolumns = filter(None,
|
||||
[(meta.get_field(f[0]) or None) for f in frappe.db.sql('desc `tab%s`' % dt)])
|
||||
|
||||
tablecolumns.sort(lambda a, b: a.idx - b.idx)
|
||||
|
|
@ -59,7 +59,7 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data
|
|||
column_start_end[dt] = frappe._dict({"start": 0})
|
||||
else:
|
||||
column_start_end[dt] = frappe._dict({"start": len(columns)})
|
||||
|
||||
|
||||
append_field_column(frappe._dict({
|
||||
"fieldname": "name",
|
||||
"label": "ID",
|
||||
|
|
@ -68,7 +68,7 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data
|
|||
"idx": 0,
|
||||
"info": "Leave blank for new records"
|
||||
}), True)
|
||||
|
||||
|
||||
for docfield in tablecolumns:
|
||||
append_field_column(docfield, True)
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data
|
|||
tablerow[column_start_end[dt].start + 2] = doctype_parentfield[dt]
|
||||
|
||||
column_start_end[dt].end = len(columns) + 1
|
||||
|
||||
|
||||
def append_field_column(docfield, mandatory):
|
||||
if docfield and ((mandatory and docfield.reqd) or not (mandatory or docfield.reqd)) \
|
||||
and (docfield.fieldname not in ('parenttype', 'trash_reason')) and not docfield.hidden:
|
||||
|
|
@ -93,7 +93,7 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data
|
|||
typerow.append(docfield.fieldtype)
|
||||
inforow.append(getinforow(docfield))
|
||||
columns.append(docfield.fieldname)
|
||||
|
||||
|
||||
def append_empty_field_column():
|
||||
tablerow.append("~")
|
||||
fieldrow.append("~")
|
||||
|
|
@ -114,7 +114,7 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data
|
|||
return 'One of: %s' % ', '.join(filter(None, docfield.options.split('\n')))
|
||||
elif docfield.fieldtype == 'Link':
|
||||
return 'Valid %s' % docfield.options
|
||||
elif docfield.fieldtype in ('Int'):
|
||||
elif docfield.fieldtype == 'Int':
|
||||
return 'Integer'
|
||||
elif docfield.fieldtype == "Check":
|
||||
return "0 or 1"
|
||||
|
|
@ -146,28 +146,28 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data
|
|||
|
||||
if with_data=='Yes':
|
||||
frappe.permissions.can_export(parent_doctype, raise_exception=True)
|
||||
|
||||
|
||||
# get permitted data only
|
||||
data = frappe.get_list(doctype, fields=["*"], limit_page_length=None)
|
||||
for doc in data:
|
||||
# add main table
|
||||
row_group = []
|
||||
|
||||
|
||||
add_data_row(row_group, doctype, doc, 0)
|
||||
|
||||
|
||||
if all_doctypes:
|
||||
# add child tables
|
||||
for child_doctype in child_doctypes:
|
||||
for ci, child in enumerate(frappe.db.sql("""select * from `tab%s`
|
||||
for ci, child in enumerate(frappe.db.sql("""select * from `tab%s`
|
||||
where parent=%s order by idx""" % (child_doctype, "%s"), doc.name, as_dict=1)):
|
||||
add_data_row(row_group, child_doctype, child, ci)
|
||||
|
||||
|
||||
for row in row_group:
|
||||
w.writerow(row)
|
||||
|
||||
|
||||
w = UnicodeWriter()
|
||||
key = 'parent' if parent_doctype != doctype else 'name'
|
||||
|
||||
|
||||
add_main_header()
|
||||
|
||||
w.writerow([''])
|
||||
|
|
@ -184,10 +184,10 @@ def get_template(doctype=None, parent_doctype=None, all_doctypes="No", with_data
|
|||
for d in child_doctypes:
|
||||
append_empty_field_column()
|
||||
build_field_columns(d)
|
||||
|
||||
|
||||
add_field_headings()
|
||||
add_data()
|
||||
|
||||
|
||||
# write out response as a type csv
|
||||
frappe.response['result'] = cstr(w.getvalue())
|
||||
frappe.response['type'] = 'csv'
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ class Document(BaseDocument):
|
|||
def update_single(self, d):
|
||||
frappe.db.sql("""delete from tabSingles where doctype=%s""", self.doctype)
|
||||
for field, value in d.iteritems():
|
||||
if field not in ("doctype"):
|
||||
if field != "doctype":
|
||||
frappe.db.sql("""insert into tabSingles(doctype, field, value)
|
||||
values (%s, %s, %s)""", (self.doctype, field, value))
|
||||
|
||||
|
|
|
|||
|
|
@ -25,3 +25,4 @@ frappe.patches.4_0.remove_old_parent
|
|||
frappe.patches.4_0.update_datetime
|
||||
frappe.patches.4_0.deprecate_control_panel
|
||||
frappe.patches.4_0.file_manager_hooks
|
||||
execute:frappe.get_doc("User", "Guest").save()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue