@Test void unlikeNotAuthorized() { EntityReference entityReference = new DocumentReference("xwiki", "Foo", "Foo"); assertFalse(this.likeScriptService.unlike(entityReference).isPresent()); assertEquals("[xwiki:XWiki.User] is not authorized to unlike [xwiki:Foo.Foo].", logCapture.getMessage(0)); }
public Optional<Long> unlike(EntityReference entityReference) { XWikiContext xWikiContext = this.contextProvider.get(); DocumentReference currentUser = xWikiContext.getUserReference(); if (entityReference instanceof DocumentReference) { DocumentReference documentReference = (DocumentReference) entityReference; if (this.isAuthorized(documentReference)) { UserReference userReference = this.userReferenceResolver.resolve(currentUser); try { this.likeManager.removeLike(userReference, entityReference); return Optional.of(this.likeManager.getEntityLikes(entityReference)); } catch (LikeException e) { this.logger.warn("Error while unliking [{}] by [{}]", documentReference, currentUser, ExceptionUtils.getRootCause(e)); } } else { this.logger.warn("[{}] is not authorized to unlike [{}].", currentUser, documentReference); } } else { this.logger.warn("Unlike is only implemented for document for now. (Called with [{}])", entityReference); } return Optional.empty(); }
LikeScriptService implements ScriptService { public Optional<Long> unlike(EntityReference entityReference) { XWikiContext xWikiContext = this.contextProvider.get(); DocumentReference currentUser = xWikiContext.getUserReference(); if (entityReference instanceof DocumentReference) { DocumentReference documentReference = (DocumentReference) entityReference; if (this.isAuthorized(documentReference)) { UserReference userReference = this.userReferenceResolver.resolve(currentUser); try { this.likeManager.removeLike(userReference, entityReference); return Optional.of(this.likeManager.getEntityLikes(entityReference)); } catch (LikeException e) { this.logger.warn("Error while unliking [{}] by [{}]", documentReference, currentUser, ExceptionUtils.getRootCause(e)); } } else { this.logger.warn("[{}] is not authorized to unlike [{}].", currentUser, documentReference); } } else { this.logger.warn("Unlike is only implemented for document for now. (Called with [{}])", entityReference); } return Optional.empty(); } }
LikeScriptService implements ScriptService { public Optional<Long> unlike(EntityReference entityReference) { XWikiContext xWikiContext = this.contextProvider.get(); DocumentReference currentUser = xWikiContext.getUserReference(); if (entityReference instanceof DocumentReference) { DocumentReference documentReference = (DocumentReference) entityReference; if (this.isAuthorized(documentReference)) { UserReference userReference = this.userReferenceResolver.resolve(currentUser); try { this.likeManager.removeLike(userReference, entityReference); return Optional.of(this.likeManager.getEntityLikes(entityReference)); } catch (LikeException e) { this.logger.warn("Error while unliking [{}] by [{}]", documentReference, currentUser, ExceptionUtils.getRootCause(e)); } } else { this.logger.warn("[{}] is not authorized to unlike [{}].", currentUser, documentReference); } } else { this.logger.warn("Unlike is only implemented for document for now. (Called with [{}])", entityReference); } return Optional.empty(); }  }
LikeScriptService implements ScriptService { public Optional<Long> unlike(EntityReference entityReference) { XWikiContext xWikiContext = this.contextProvider.get(); DocumentReference currentUser = xWikiContext.getUserReference(); if (entityReference instanceof DocumentReference) { DocumentReference documentReference = (DocumentReference) entityReference; if (this.isAuthorized(documentReference)) { UserReference userReference = this.userReferenceResolver.resolve(currentUser); try { this.likeManager.removeLike(userReference, entityReference); return Optional.of(this.likeManager.getEntityLikes(entityReference)); } catch (LikeException e) { this.logger.warn("Error while unliking [{}] by [{}]", documentReference, currentUser, ExceptionUtils.getRootCause(e)); } } else { this.logger.warn("[{}] is not authorized to unlike [{}].", currentUser, documentReference); } } else { this.logger.warn("Unlike is only implemented for document for now. (Called with [{}])", entityReference); } return Optional.empty(); }  boolean isAuthorized(EntityReference entityReference); boolean displayButton(EntityReference entityReference); Optional<Long> like(EntityReference entityReference); Optional<Long> unlike(EntityReference entityReference); Optional<Long> getLikes(EntityReference entityReference); List<EntityReference> getUserLikes(UserReference userReference, int offset, int limit); boolean isLiked(EntityReference entityReference); @Unstable List<UserReference> getLikers(EntityReference target, int offset, int limit); void cleanCacheUIX(); }
LikeScriptService implements ScriptService { public Optional<Long> unlike(EntityReference entityReference) { XWikiContext xWikiContext = this.contextProvider.get(); DocumentReference currentUser = xWikiContext.getUserReference(); if (entityReference instanceof DocumentReference) { DocumentReference documentReference = (DocumentReference) entityReference; if (this.isAuthorized(documentReference)) { UserReference userReference = this.userReferenceResolver.resolve(currentUser); try { this.likeManager.removeLike(userReference, entityReference); return Optional.of(this.likeManager.getEntityLikes(entityReference)); } catch (LikeException e) { this.logger.warn("Error while unliking [{}] by [{}]", documentReference, currentUser, ExceptionUtils.getRootCause(e)); } } else { this.logger.warn("[{}] is not authorized to unlike [{}].", currentUser, documentReference); } } else { this.logger.warn("Unlike is only implemented for document for now. (Called with [{}])", entityReference); } return Optional.empty(); }  boolean isAuthorized(EntityReference entityReference); boolean displayButton(EntityReference entityReference); Optional<Long> like(EntityReference entityReference); Optional<Long> unlike(EntityReference entityReference); Optional<Long> getLikes(EntityReference entityReference); List<EntityReference> getUserLikes(UserReference userReference, int offset, int limit); boolean isLiked(EntityReference entityReference); @Unstable List<UserReference> getLikers(EntityReference target, int offset, int limit); void cleanCacheUIX();  }