Im trying to generate permissions by Script. Unfortunatly it works only on entities.
Here is my code:
function main(){
var user1 = Model.Users.GetObjectByName(‘User1’);
var userGroup1 = Model.UserGroups.GetObjectByName(‘UserGroup1’);
var entity1 = Model.Entities.getObject(0);
var view1 = Model.Views.getObject(0);
var mview1 = Model.MaterializedViews.getObject(0);
var func1 = Model.Functions.getObject(0);
var proc1 = Model.Procedures.getObject(0);
Log.Information(user1.name + ’ ’ +userGroup1.name + ’ ’ + entity1.name + ’ ’ + view1.name + ’ ’ + mview1.name + ’ ’ + func1.name + ’ ’ + proc1.name);
Model.lock();
removeRights(entity1);
removeRights(view1);
removeRights(mview1);
removeRights(func1);
removeRights(proc1);
Model.AddUserRight(entity1, userGroup1, ‘SELECT’, ‘Grant’); // works
Model.AddUserRight(view1, userGroup1, ‘SELECT’, ‘Grant’); // don’t work
Model.AddUserRight(mview1, userGroup1, ‘SELECT’, ‘Grant’); // don’t work
Model.AddUserRight(func1, userGroup1, ‘EXECUTE’, ‘Grant’); // don’t work
Model.AddUserRight(proc1, userGroup1, ‘EXECUTE’, ‘Grant’); // don’t work
logPermCount(entity1);
logPermCount(view1);
logPermCount(mview1);
logPermCount(func1);
logPermCount(proc1);
Model.unlock();
}
function removeRights(obj)
{
while (obj.InstanceUserGroupRelations.count > 0)
{
obj.InstanceUserGroupRelations.GetObject(0).Delete();
}
}
function logPermCount(obj)
{
Log.Information(obj.InstanceUserGroupRelations.count + ’ permissions on ’ + obj.Name);
}
What I’m doing wrong?