Toad World® Forums

How do I generate permissions by script for other objects than entities?


#1

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?


#2

Hello Jens,
your code is correct, but there is probably bug in Toad Data Modeler. I’ve created the issue in our bugtracker (TDM-4833) and we will look into it.
Thanks for reporting this issue.

Best regards.
Michal


#3

Hi Jens,
please see the attached script with the workaround. There is added a new function AddUserRightScript which is used for other objects than entities (but you can use it for entities too).

Regards,
Dave
UserRightOK.txt (5.9 KB)


#4

Hi Dave,

I tried the workaround and it solved immediately my problems.
Thanks a lot for this fast solution.

Regards
Jens