@Test public void saveDescriptorWhenDescriptorDidNotExist() throws Exception { WikiDescriptor descriptor = new WikiDescriptor("wikiId", "wikiAlias"); boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor); assertFalse(result); verify(authorizationManager).hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("mainWiki"))); verify(wikiDescriptorManager, never()).saveDescriptor(descriptor); }
public boolean saveDescriptor(WikiDescriptor descriptor) { XWikiContext context = xcontextProvider.get(); boolean isAllowed; try { WikiDescriptor oldDescriptor = wikiDescriptorManager.getById(descriptor.getId()); WikiReference wikiReference = descriptor.getReference(); if (oldDescriptor != null) { DocumentReference descriptorDocument = wikiDescriptorDocumentHelper.getDocumentReferenceFromId(oldDescriptor.getId()); isAllowed = authorizationManager.hasAccess(Right.EDIT, context.getUserReference(), descriptorDocument); String currentOwner = oldDescriptor.getOwnerId(); if (!isAllowed) { isAllowed = entityReferenceSerializer.serialize(context.getUserReference()).equals(currentOwner); } if (!isAllowed) { String newOwner = descriptor.getOwnerId(); isAllowed = authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), wikiReference) && StringUtils.equals(newOwner, currentOwner); } } else { isAllowed = authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), new WikiReference( wikiDescriptorManager.getMainWikiId())); } if (!isAllowed) { throw new AccessDeniedException(context.getUserReference(), wikiReference); } else { wikiDescriptorManager.saveDescriptor(descriptor); } return true; } catch (Exception e) { error(e); return false; } }
WikiManagerScriptService implements ScriptService { public boolean saveDescriptor(WikiDescriptor descriptor) { XWikiContext context = xcontextProvider.get(); boolean isAllowed; try { WikiDescriptor oldDescriptor = wikiDescriptorManager.getById(descriptor.getId()); WikiReference wikiReference = descriptor.getReference(); if (oldDescriptor != null) { DocumentReference descriptorDocument = wikiDescriptorDocumentHelper.getDocumentReferenceFromId(oldDescriptor.getId()); isAllowed = authorizationManager.hasAccess(Right.EDIT, context.getUserReference(), descriptorDocument); String currentOwner = oldDescriptor.getOwnerId(); if (!isAllowed) { isAllowed = entityReferenceSerializer.serialize(context.getUserReference()).equals(currentOwner); } if (!isAllowed) { String newOwner = descriptor.getOwnerId(); isAllowed = authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), wikiReference) && StringUtils.equals(newOwner, currentOwner); } } else { isAllowed = authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), new WikiReference( wikiDescriptorManager.getMainWikiId())); } if (!isAllowed) { throw new AccessDeniedException(context.getUserReference(), wikiReference); } else { wikiDescriptorManager.saveDescriptor(descriptor); } return true; } catch (Exception e) { error(e); return false; } } }
WikiManagerScriptService implements ScriptService { public boolean saveDescriptor(WikiDescriptor descriptor) { XWikiContext context = xcontextProvider.get(); boolean isAllowed; try { WikiDescriptor oldDescriptor = wikiDescriptorManager.getById(descriptor.getId()); WikiReference wikiReference = descriptor.getReference(); if (oldDescriptor != null) { DocumentReference descriptorDocument = wikiDescriptorDocumentHelper.getDocumentReferenceFromId(oldDescriptor.getId()); isAllowed = authorizationManager.hasAccess(Right.EDIT, context.getUserReference(), descriptorDocument); String currentOwner = oldDescriptor.getOwnerId(); if (!isAllowed) { isAllowed = entityReferenceSerializer.serialize(context.getUserReference()).equals(currentOwner); } if (!isAllowed) { String newOwner = descriptor.getOwnerId(); isAllowed = authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), wikiReference) && StringUtils.equals(newOwner, currentOwner); } } else { isAllowed = authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), new WikiReference( wikiDescriptorManager.getMainWikiId())); } if (!isAllowed) { throw new AccessDeniedException(context.getUserReference(), wikiReference); } else { wikiDescriptorManager.saveDescriptor(descriptor); } return true; } catch (Exception e) { error(e); return false; } }  }
WikiManagerScriptService implements ScriptService { public boolean saveDescriptor(WikiDescriptor descriptor) { XWikiContext context = xcontextProvider.get(); boolean isAllowed; try { WikiDescriptor oldDescriptor = wikiDescriptorManager.getById(descriptor.getId()); WikiReference wikiReference = descriptor.getReference(); if (oldDescriptor != null) { DocumentReference descriptorDocument = wikiDescriptorDocumentHelper.getDocumentReferenceFromId(oldDescriptor.getId()); isAllowed = authorizationManager.hasAccess(Right.EDIT, context.getUserReference(), descriptorDocument); String currentOwner = oldDescriptor.getOwnerId(); if (!isAllowed) { isAllowed = entityReferenceSerializer.serialize(context.getUserReference()).equals(currentOwner); } if (!isAllowed) { String newOwner = descriptor.getOwnerId(); isAllowed = authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), wikiReference) && StringUtils.equals(newOwner, currentOwner); } } else { isAllowed = authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), new WikiReference( wikiDescriptorManager.getMainWikiId())); } if (!isAllowed) { throw new AccessDeniedException(context.getUserReference(), wikiReference); } else { wikiDescriptorManager.saveDescriptor(descriptor); } return true; } catch (Exception e) { error(e); return false; } }  ScriptService get(String serviceName); Exception getLastError(); WikiDescriptor createWiki(String wikiId, String wikiAlias, String ownerId, boolean failOnExist); boolean deleteWiki(String wikiId); boolean canDeleteWiki(String userId, String wikiId); WikiDescriptor getByAlias(String wikiAlias); WikiDescriptor getById(String wikiId); Collection<WikiDescriptor> getAll(); Collection<String> getAllIds(); Boolean exists(String wikiId); Boolean idAvailable(String wikiId); WikiDescriptor getMainWikiDescriptor(); String getMainWikiId(); String getCurrentWikiId(); @Unstable WikiReference getCurrentWikiReference(); WikiDescriptor getCurrentWikiDescriptor(); boolean saveDescriptor(WikiDescriptor descriptor); boolean isPathMode(); String getAliasSuffix(); @Deprecated Exception getLastException(); }
WikiManagerScriptService implements ScriptService { public boolean saveDescriptor(WikiDescriptor descriptor) { XWikiContext context = xcontextProvider.get(); boolean isAllowed; try { WikiDescriptor oldDescriptor = wikiDescriptorManager.getById(descriptor.getId()); WikiReference wikiReference = descriptor.getReference(); if (oldDescriptor != null) { DocumentReference descriptorDocument = wikiDescriptorDocumentHelper.getDocumentReferenceFromId(oldDescriptor.getId()); isAllowed = authorizationManager.hasAccess(Right.EDIT, context.getUserReference(), descriptorDocument); String currentOwner = oldDescriptor.getOwnerId(); if (!isAllowed) { isAllowed = entityReferenceSerializer.serialize(context.getUserReference()).equals(currentOwner); } if (!isAllowed) { String newOwner = descriptor.getOwnerId(); isAllowed = authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), wikiReference) && StringUtils.equals(newOwner, currentOwner); } } else { isAllowed = authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), new WikiReference( wikiDescriptorManager.getMainWikiId())); } if (!isAllowed) { throw new AccessDeniedException(context.getUserReference(), wikiReference); } else { wikiDescriptorManager.saveDescriptor(descriptor); } return true; } catch (Exception e) { error(e); return false; } }  ScriptService get(String serviceName); Exception getLastError(); WikiDescriptor createWiki(String wikiId, String wikiAlias, String ownerId, boolean failOnExist); boolean deleteWiki(String wikiId); boolean canDeleteWiki(String userId, String wikiId); WikiDescriptor getByAlias(String wikiAlias); WikiDescriptor getById(String wikiId); Collection<WikiDescriptor> getAll(); Collection<String> getAllIds(); Boolean exists(String wikiId); Boolean idAvailable(String wikiId); WikiDescriptor getMainWikiDescriptor(); String getMainWikiId(); String getCurrentWikiId(); @Unstable WikiReference getCurrentWikiReference(); WikiDescriptor getCurrentWikiDescriptor(); boolean saveDescriptor(WikiDescriptor descriptor); boolean isPathMode(); String getAliasSuffix(); @Deprecated Exception getLastException(); static final String ROLEHINT; @Deprecated
    static final String CONTEXT_LASTEXCEPTION; }