Hi,
Is it possible change user permissions / make him admin in time of script (macro/report) running ? I need to give to user option to write into the locked group/only for admin group.
Thanks.
The best way to solve this issue is to open the active database again (in and by the script), with an user that has admin rights and use this db object for your admin activities. The name and password of the admin user can be stored in a xml-file or in the script itself.
I tried to open the database with admin, but the script did not respond on it. I still have got the same active user. I used
ArisData.openDatabase(gActiveDB.Name(lng), "user", "password", "filterGUID", lng) function for it. Am I right? Do you have some suggestions? I work with Aris 9.
Thanks.
After you opened the database you have two (2) db objects:
1: oDB1 = ArisData.getActiveDatabase()
2: oDB2 = ArisData.openDatabase(gActiveDB.Name(lng), "user", "password", "filterGUID", lng)
with oDB1 you only have the rights of the actual user (ArisData.getActiveUser())
with oDB2 you have the rights of the (admin)user that opened thi 2nd DB-object.
So if you want to create a model via the first db-object (oDB1) in a goup where the actual user doesn't have rights, it will fail, but via oDB2 you will succeed:
for example:
var oGroup = oDB2.Find(Constants.SEARCH_GROUP, Constants.AT_NAME, gnLoc, "GroupName", Constants.SEARCH_CMP_EQUAL)
var oModel = oGroup.createModel(Constants.MT_EEPC, "ModelName", gnLoc)
etc....
Database.setAutoTouch(boolean p_bEnableTouch)
p_bEnableTouch:
- True: (default behavior): each time a change happens the attributes last modifier (last user)/last modification date are set
- False: attributes last modifier (last user)/last modification date are not set automatically
What you can do is to perform the 'admin like' actions with the autotouch off, in the db(object) that is opened with the 'admin' rights' and after that you save the model (or what object it might be) in the standard db (object).
Or.... (but I don't know if that will be possible), set autotouch off and set the value for attributes for last change date and last user manually with the data of your 'normal' user.
Hi,
The second solution does not seem working, the first one I did not understand. For example: I moved some models into the group with no permissions for active user. How can I update last user attribute? I tried to make change of model name prior the model moving but for some reason nothing happened.
I'm waiting for your advice. Thanks again.
Good day,
After changing the model with the admin user you could open the model with the active user again and use item.Touch() to update last change and last user attributes. I'm not sure if this will work if the active user has limited access to the model or if the model is locked.
Regards.
Hereby a little script that you can run on a model. In my case the active user has only read writes, the admin user has all access rights of course.
With this script you can use each name (not necessarily of an existing user) as last user.
function main(){
var oDB1 = ArisData.getActiveDatabase()
var oModel1 = ArisData.getSelectedModels()[0]
var sGUID = oModel1.GUID()
Dialogs.MsgBox("'Last user name' = " + oModel1.Attribute(Constants.AT_LUSER,-1).getValue())
var oDB2= ArisData.openDatabase(oDB1.Name(-1), "system", "manager", "dd838074-ac29-11d4-85b8-00005a4053ff", -1)
var oModel2 = oDB2.FindGUID(sGUID, Constants.CID_MODEL)
var sLastUserName = Dialogs.InputBox ("Input name to use as 'last user name'", "Test 'last user name'","")
if (sLastUserName>""){
oDB2.setAutoTouch(false)
oModel2.Attribute(Constants.AT_LUSER,-1).setValue(sLastUserName)
oDB2.setAutoTouch(true)
oDB2.close()
}
Context.addActionResult (Constants.ACTION_UPDATE, "", oModel1) // without this line you have to reload the model yourself to see the update
}
main()