removed doctype event role and fix minor issue

This commit is contained in:
Rohit Waghchaure 2017-02-22 16:18:41 +05:30
parent b424564ad4
commit 8d90eff95d
14 changed files with 34 additions and 143 deletions

View file

@ -71,6 +71,9 @@ class Page(Document):
d[key] = self.get(key)
return d
def on_trash(self):
delete_custom_role('page', self.name)
def is_permitted(self):
"""Returns true if Has Role is not set or the user is allowed."""
from frappe.utils import has_common
@ -140,4 +143,7 @@ class Page(Document):
if js:
self.script += "\n\n" + js
def delete_custom_role(field, docname):
name = frappe.db.get_value('Custom Role', {field: docname}, "name")
if name:
frappe.delete_doc('Custom Role', name)

View file

@ -10,6 +10,7 @@ from frappe.utils import cint
from frappe.model.document import Document
from frappe.modules.export_file import export_to_files
from frappe.modules import make_boilerplate
from frappe.core.doctype.page.page import delete_custom_role
class Report(Document):
def validate(self):
@ -40,11 +41,14 @@ class Report(Document):
def on_update(self):
self.export_doc()
def on_trash(self):
delete_custom_role('report', self.name)
def set_doctype_roles(self):
if self.get('roles'): return
doc = frappe.get_meta(self.ref_doctype)
roles = [{'role': d.role} for d in doc.permissions]
roles = [{'role': d.role} for d in doc.permissions if d.permlevel==0]
self.set('roles', roles)
def is_permitted(self):

View file

@ -15,7 +15,15 @@ frappe.ui.form.on('User Permission for Page and Report', {
},
page: function(frm) {
frappe.call({
frm.trigger("get_roles")
},
report: function(frm){
frm.trigger("get_roles")
},
get_roles: function(frm) {
return frappe.call({
method:"get_custom_roles",
doc: frm.doc,
callback: function(r) {

View file

@ -9,12 +9,16 @@ from frappe.model.document import Document
class UserPermissionforPageandReport(Document):
def get_custom_roles(self):
args = self.get_args()
name = frappe.db.get_value('Custom Role', args, "name")
if not name:
self.set('roles', [])
return
self.set('roles', [])
name = frappe.db.get_value('Custom Role', args, "name")
if name:
doc = frappe.get_doc('Custom Role', name)
else:
doctype = self.set_role_for
docname = self.page if self.set_role_for == 'Page' else self.report
doc = frappe.get_doc(doctype, docname)
doc = frappe.get_doc('Custom Role', name)
self.set('roles', doc.roles)
def set_custom_roles(self):

View file

@ -732,37 +732,6 @@
"unique": 0,
"width": "50%"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "roles",
"fieldtype": "Table",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 1,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Roles",
"length": 0,
"no_copy": 0,
"oldfieldname": "event_roles",
"oldfieldtype": "Table",
"options": "Event Role",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@ -837,7 +806,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-02-17 17:02:18.749886",
"modified": "2017-02-22 16:25:55.420314",
"modified_by": "Administrator",
"module": "Desk",
"name": "Event",

View file

@ -28,11 +28,7 @@ class Event(Document):
def get_permission_query_conditions(user):
if not user: user = frappe.session.user
return """(tabEvent.event_type='Public' or tabEvent.owner='%(user)s'
or exists(select * from `tabEvent Role` where
`tabEvent Role`.parent=tabEvent.name
and `tabEvent Role`.role in ('%(roles)s')))
""" % {
return """(tabEvent.event_type='Public' or tabEvent.owner='%(user)s')""" % {
"user": frappe.db.escape(user),
"roles": "', '".join([frappe.db.escape(r) for r in frappe.get_roles(user)])
}
@ -41,9 +37,6 @@ def has_permission(doc, user):
if doc.event_type=="Public" or doc.owner==user:
return True
if doc.get("roles", {"role":("in", frappe.get_roles(user))}):
return True
return False
@ -87,10 +80,7 @@ def get_events(start, end, user=None, for_reminder=False):
and (event_type='Public' or owner=%(user)s
or exists(select name from `tabDocShare` where
tabDocShare.share_doctype="Event" and `tabDocShare`.share_name=tabEvent.name
and tabDocShare.user=%(user)s)
or exists(select * from `tabEvent Role` where
`tabEvent Role`.parent=tabEvent.name
and `tabEvent Role`.role in ({roles})))
and tabDocShare.user=%(user)s))
order by starts_on""".format(
reminder_condition="and ifnull(send_reminder,0)=1" if for_reminder else "",
roles=", ".join('"{}"'.format(frappe.db.escape(r)) for r in roles)

View file

@ -17,7 +17,6 @@ test_records = frappe.get_test_records('Event')
class TestEvent(unittest.TestCase):
def setUp(self):
frappe.db.sql('delete from tabEvent')
frappe.db.sql('delete from `tabEvent Role`')
make_test_objects('Event', reset=True)
self.test_records = frappe.get_test_records('Event')

View file

@ -1 +0,0 @@
Role with which the event is shared.

View file

@ -1,4 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals

View file

@ -1,69 +0,0 @@
{
"allow_copy": 0,
"allow_import": 0,
"allow_rename": 0,
"autoname": "hash",
"beta": 0,
"creation": "2013-02-22 01:27:33",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "Document",
"editable_grid": 1,
"fields": [
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "role",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Role",
"length": 0,
"no_copy": 0,
"oldfieldname": "role",
"oldfieldtype": "Link",
"options": "Role",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "240px",
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0,
"width": "240px"
}
],
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 1,
"image_view": 0,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-01-30 06:39:06.384904",
"modified_by": "Administrator",
"module": "Desk",
"name": "Event Role",
"owner": "Administrator",
"permissions": [],
"quick_entry": 0,
"read_only": 0,
"read_only_onload": 0,
"track_changes": 0,
"track_seen": 0
}

View file

@ -1,10 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class EventRole(Document):
pass

View file

@ -12,9 +12,6 @@ rename_map = {
"Email Alert": [
["email_alert_recipients", "recipients"]
],
"Event": [
["event_roles", "roles"]
],
"Workflow": [
["workflow_document_states", "states"],
["workflow_transitions", "transitions"]

View file

@ -6,7 +6,7 @@ import frappe
def execute():
changed = (
("desk", ("feed", "event", "event_role", "todo", "note")),
("desk", ("feed", "event", "todo", "note")),
("custom", ("custom_field", "custom_script", "customize_form",
"customize_form_field", "property_setter")),
("email", ("email_queue", "email_alert", "email_alert_recipient", "standard_reply")),

View file

@ -25,7 +25,6 @@ class TestGlobalSearch(unittest.TestCase):
frappe.db.sql('delete from `tabProperty Setter` where doc_type="Event"')
frappe.clear_cache(doctype='Event')
frappe.db.sql('delete from `tabEvent`')
frappe.db.sql('delete from `tabEvent Role`')
frappe.db.sql('delete from __global_search')
make_test_objects('Event')
frappe.db.commit()
@ -92,7 +91,6 @@ class TestGlobalSearch(unittest.TestCase):
def test_insert_child_table(self):
frappe.db.sql('delete from tabEvent')
frappe.db.sql('delete from `tabEvent Role`')
phrases = ['Hydrus is a small constellation in the deep southern sky. ',
'It was first depicted on a celestial atlas by Johann Bayer in his 1603 Uranometria. ',
'The French explorer and astronomer Nicolas Louis de Lacaille charted the brighter stars and gave their Bayer designations in 1756. ',