Probably the easiest option is to iterate through all users.
I was afraid to hear this solution (there are approximately 500 users) :-(
Why is that an issue? I'm assuming you want to automate it either way.
yes... I'm automating. My script read a csv file with some devices and update the information in the database.
10 devices X 500 users = 5,000 server requests
My fear is that the number of devices (or users) starts to grow a lot, but I believe it won't.
It is a solution that solves my problem!
Thank you very much Anton
Actually we do have a "bulk" option for permissions:
Thank you Anton. I will check the source code. This "bulk for permissions" is not documented in https://www.traccar.org/api-reference, correct?
Yeah, I don't think it's documented there.
Bulk update is good. Can we have any documents for better use case
Sure, feel free to send a pull request for the API documentation.
not getting this
Anton helps me because I know little about Java.
From what I understand from the source code, I must inform an array of [ {userId: A, deviceId: B}, {userId: C, deviceId: D} ]
, correct?
Example:
$.ajax({
url: 'http://{host}:{port}/api/permissions/bulk',
method: 'DELETE',
headers: {
'content-type': 'application/json',
'authorization': 'Basic ' + btoa(`${USER}:${PASSWORD}`)
},
processData: false,
data: JSON.stringify( [ {userId: 1, deviceId: 1},
{userId: 2, deviceId: 1},
....,
....,
{userId: N, deviceId: 1} ] )
})
src/main/java/org/traccar/api/resource/PermissionsResource.java, line 96:
@DELETE
@Path("bulk")
public Response remove(List<LinkedHashMap<String, Long>> entities) throws StorageException, ClassNotFoundException {
Context.getPermissionsManager().checkReadonly(getUserId());
checkPermissionTypes(entities);
for (LinkedHashMap<String, Long> entity: entities) {
Permission permission = new Permission(entity);
checkPermission(permission, false);
Context.getDataManager().linkObject(permission.getOwnerClass(), permission.getOwnerId(),
permission.getPropertyClass(), permission.getPropertyId(), false);
LogAction.unlink(getUserId(), permission.getOwnerClass(), permission.getOwnerId(),
permission.getPropertyClass(), permission.getPropertyId());
}
if (!entities.isEmpty()) {
Context.getPermissionsManager().refreshPermissions(new Permission(entities.get(0)));
}
return Response.noContent().build();
}
Anton good afternoon! How are you? I imagine you are very busy, but I need your help.
I opened the Java code src/main/java/org/traccar/api/resource/PermissionsResource.java, line 96
(my last post above) but I didn't understand how to make the "permissions/bulk" request using JQuery/Ajax.
Could you guide me on how to tweak my code below or post an example in any language so I can "transcribe" the example to JQuery/Ajax?
$.ajax({
url: 'http://{host}:{port}/api/permissions/bulk',
method: 'DELETE',
headers: {
'content-type': 'application/json',
'authorization': 'Basic ' + btoa(`${USER}:${PASSWORD}`)
},
processData: false,
data: JSON.stringify( [ {userId: 1, deviceId: 1},
{userId: 2, deviceId: 1},
....,
{userId: N, deviceId: 1} ] )
})
I'm coming back with this subject, I really need this feature: "remove access from all users of a certain vehicle".
Thanks again for your attention and congratulations on the project!!!
What's the API response?
Anton, sorry! The example I posted here https://www.traccar.org/forums/topic/remove-access-from-all-users-a-specific-device-api/#post-70135 works yes. It was my mistake while testing the code.
Do you as admin have permission to delete my message from yesterday? If so, please delete it and close the topic as resolved.
Thank you very much and again congratulations on the project!
PS: Do you already have a forecast of when the new version of Traccar will be released?
The example below removes "user 2" access to "device 1":
But suppose "N users" have access to this device and I want to remove access from all these "N users". How should I do?
Can I use some code, like
{userId: 0, deviceId: 1}
or{userId: -1, deviceId: 1}
to indicate ALL users and not a specific one?Note: I don't know the list of users who have permission. If I knew the list, it would be easy. Just call DELETE several times, one for each user.