commit
5cd757c349
5 changed files with 122 additions and 0 deletions
0
frappe/core/doctype/role_replication/__init__.py
Normal file
0
frappe/core/doctype/role_replication/__init__.py
Normal file
18
frappe/core/doctype/role_replication/role_replication.js
Normal file
18
frappe/core/doctype/role_replication/role_replication.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (c) 2024, Frappe Technologies and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on("Role Replication", {
|
||||
refresh(frm) {
|
||||
frm.disable_save();
|
||||
frm.page.set_primary_action(__("Replicate"), ($btn) => {
|
||||
$btn.text(__("Replicating..."));
|
||||
frappe.run_serially([
|
||||
() => frappe.dom.freeze("Replicating..."),
|
||||
() => frm.call("replicate_role"),
|
||||
() => frappe.dom.unfreeze(),
|
||||
() => frappe.msgprint(__("Replication completed.")),
|
||||
() => $btn.text(__("Replicate")),
|
||||
]);
|
||||
});
|
||||
},
|
||||
});
|
||||
52
frappe/core/doctype/role_replication/role_replication.json
Normal file
52
frappe/core/doctype/role_replication/role_replication.json
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"actions": [],
|
||||
"creation": "2024-06-24 18:25:23.163914",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"existing_role",
|
||||
"column_break_ydyj",
|
||||
"new_role"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "existing_role",
|
||||
"fieldtype": "Link",
|
||||
"label": "Existing Role",
|
||||
"options": "Role"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_ydyj",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"description": "Input existing role name if you would like to extend it with access of another role.",
|
||||
"fieldname": "new_role",
|
||||
"fieldtype": "Data",
|
||||
"label": "New Role"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2024-06-24 19:26:54.279801",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Core",
|
||||
"name": "Role Replication",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
||||
43
frappe/core/doctype/role_replication/role_replication.py
Normal file
43
frappe/core/doctype/role_replication/role_replication.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# Copyright (c) 2024, Frappe Technologies and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.core.page.permission_manager.permission_manager import get_permissions
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class RoleReplication(Document):
|
||||
# begin: auto-generated types
|
||||
# This code is auto-generated. Do not modify anything in this block.
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from frappe.types import DF
|
||||
|
||||
existing_role: DF.Link | None
|
||||
new_role: DF.Data | None
|
||||
# end: auto-generated types
|
||||
|
||||
@frappe.whitelist()
|
||||
def replicate_role(self):
|
||||
frappe.only_for("System Manager")
|
||||
|
||||
new_role = frappe.db.get_value("Role", self.new_role, "name")
|
||||
if not new_role:
|
||||
new_role = frappe.get_doc({"doctype": "Role", "role_name": self.new_role}).insert().name
|
||||
|
||||
perms = get_permissions(role=self.existing_role)
|
||||
for perm in perms:
|
||||
perm.update(
|
||||
{
|
||||
"name": None,
|
||||
"creation": None,
|
||||
"modified": None,
|
||||
"modified_by": None,
|
||||
"owner": None,
|
||||
"linked_doctypes": None,
|
||||
"role": new_role,
|
||||
}
|
||||
)
|
||||
frappe.get_doc({"doctype": "Custom DocPerm", **perm}).insert()
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# Copyright (c) 2024, Frappe Technologies and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
|
||||
class TestRoleReplication(FrappeTestCase):
|
||||
pass
|
||||
Loading…
Add table
Reference in a new issue