Free Support Forum - groupdocs.com

Modiying Access Rights in GD.Annotation 1.8.0


#1

Hi,

We were able to modify user’s existing Access Rights in GD.Annotation 1.7.x using the Connector framework (of the Java Annotation Library).

Sometimes we need to allow user to enjoy more rights or downgrade the rights for the same doc (e.g., someone was only allowed to view the doc, however we now need to allow him/her to annotate the same doc). However, in version 1.8.0, our existing code is not working and GD.Annotation 1.8.0 introduces new collaborator callback framework to deal with access rights (Pavel directed me to this link for this a couple of weeks back).

Could you please point me to some examples using which we could assign a certain access right for a doc to a user and later could upgrade (or downgrade) the rights for the same doc?

Thanks in advance for the help.

Azam


#2
Hello Azam,

Thank you for interest in the GroupDocs. Yes, indeed, the way to set user access rights was changed in the 1.8.0 version of the GroupDocs.Annotation for Java library. In the given code sample (https://github.com/groupdocs/groupdocs-annotation-java-spring-sample/blob/master/src/main/java/com/groupdocs/HomeControllerBase.java#L178) you actually can check that collaborator rights now are defined in the callback. If you run the sample in the debug mode, you can see that user rights are checked per every request. It means that you have two options for changing user access rights on the fly:

1) Create a code that will decide what rights to give depending on some parameter, for example:
annotationHandler.setCollaboratorCallback(new ICallback<Pair, Pair>() {
@Override
public Pair onCallback(Pair param) {
/*
IUser user = param.one;
IDocument document = param.two;
*/
// User collaborator for document will be created with returned access rights and color
// Default CollaboratorCallback is made similarly
switch (param.one.getUserName()) {
case "John":
return new Pair(AccessRights.from(
AccessRights.CAN_VIEW,
AccessRights.CAN_ANNOTATE,
AccessRights.CAN_REDACT), Color.red);
case "Bill":
return new Pair(AccessRights.from(
AccessRights.CAN_VIEW,
AccessRights.CAN_ANNOTATE,
AccessRights.CAN_REDACT,
AccessRights.CAN_DELETE), Color.red);
}
return new Pair(AccessRights.All.value(), Color.red);
}
});

2) Do the same but in more OOP way - reuse the setCollaboratorCallback method to set another ICallback<Pair, Pair> object which will define another access rights. You can reset collaborator callback on-the-fly.