Notifications
Clear all

[Solved] In Java, check whether a user has permission to do an action on the model

4 Posts
2 Users
0 Reactions
920 Views
0
Topic starter

In Java, how can I check whether a user has permission to do an action on the model. This should be something similar to javascript - SPT.getModel("modelname")...

1 Answer
0

If you have the model object (i.e. you know which row), the best option is probably com.onenetwork.platform.data.model.ModelDataService.validateWritePermission(ModelWriteRequest<m>, PlatformUserContext). You create a ModelWriteRequest and give the model you want to execute the action on, along with the action to be executed. This API will perform all checks, including role type checks, state checks, etc, without actually writing.

If you have just the model type (but don't know which "row") then the answer may be a bit different, so let us know.

svarghese Topic starter 2017-03-23 10:03:00

I think it is model type. The rest request send each Id and the corresponding ModelName to Java JSONArray.

GregMerrill 2017-03-23 10:03:00

In this case, you can lookup those models by their IDs using ModelDataService.readByIds(). Then create a ModelList with those models on it, and put the desired action on it. When you execute, it will come back with errors on models you're not allowed to execute that action on.

Again, the answer here could be different if you're looking to get a list of all possible actions. Do you need a list of all possible actions on those models, or just a "yes or no, can i execute this particular action?"

svarghese Topic starter 2017-03-23 13:03:00

Just a 'Yes or no' on for that specific action.