当用户创建记录时,需要将此记录复制到只读类中。
两个顶点类,一个具有用户的完全访问权限,另一个具有只读访问权限。只要在完整访问类中创建记录,就需要在只读类中创建重复记录。
动态钩子几乎可以工作,但是该函数不会触发,因为用户缺少readOnly类的创建权限。如何创建重复记录?
//from console
CREATE CLASS allRights EXTENDS V, OTriggered;
CREATE CLASS readOnly EXTENDS V;
ALTER CLASS allRights CUSTOM onAfterCreate=createDuplicate
CREATE FUNCTION createDuplicate "db.command(\"CREATE VERTEX readOnly set someField = \\\"\" + doc.field(\'someField\')+\"\\\"\");" LANGUAGE Javascript
INSERT INTO ORole SET name = 'testUser', mode = 0;
UPDATE ORole PUT rules = "database.class.readOnly", 2 WHERE name = "testUser";
UPDATE ORole PUT rules = "database.class.allRights", 15 WHERE name = "testUser"
UPDATE ORole PUT rules = "database.class.*", 15 WHERE name = "testUser"
INSERT INTO OUser SET name = 'testUser', password = 'password', status = 'ACTIVE', roles = (SELECT FROM ORole WHERE name = 'testUser')
答案 0 :(得分:0)
我有2个解决此问题的方法:
db.switchUser('superuser', 'superuser')