/** * Tells the caller whether or not the current user is an owner of the current page. * * @return true if the user is the owner of the current page. */ private boolean isUserCurrentPageOwner(PortalPage currentPortalPage) { return currentPortalPage != null && currentPortalPage.getOwner() != null && currentPortalPage.getOwner().equals(getLoggedInUser()); }
public String getOwnerUserName() { final ApplicationUser owner = portalPage.getOwner(); if (owner != null) { return userFormatManager.formatUserkey(owner.getKey(), UserNameUserFormat.TYPE, "portal_page"); } return null; }
public boolean isCurrentOwner() { final ApplicationUser owner = portalPage.getOwner(); return (owner != null) && owner.equals(authCtx.getUser()); }
public String getOwnerFullName() { final ApplicationUser owner = portalPage.getOwner(); if (owner != null) { return userFormatManager.formatUserkey(owner.getKey(), FullNameUserFormat.TYPE, "portal_page"); } return null; }
public int getOtherFavouriteCount() { if (otherFavouriteCount == null) { final PortalPage dashboard = getDashboard(); // We want to know how many times it has been favourited by OTHER people ApplicationUser dashboardOwner = dashboard.getOwner(); final boolean isFavourite = favouriteService.isFavourite(dashboardOwner, dashboard); final int count = isFavourite ? dashboard.getFavouriteCount().intValue() - 1 : dashboard.getFavouriteCount().intValue(); otherFavouriteCount = (long) count; } return otherFavouriteCount.intValue(); }
public PortalPage update(final PortalPage portalPage) { Assertions.notNull("portalPage", portalPage); Assertions.notNull("portalPage.id", portalPage.getId()); final ApplicationUser newOwner = portalPage.getOwner(); if (!portalPage.isSystemDefaultPortalPage()) { Assertions.notNull("portalPage.owner", newOwner); } PortalPage returnPage = null; PortalPage oldPortalPage = null; try { oldPortalPage = delegateStore.getPortalPage(portalPage.getId()); returnPage = delegateStore.update(portalPage); } finally { cacheById.remove(portalPage.getId()); if (portalPage.getOwner() != null && (oldPortalPage == null || portalPage.getOwner() != oldPortalPage.getOwner())) { cacheByUser.remove(portalPage.getOwner().getKey()); } if (oldPortalPage != null && oldPortalPage.getOwner() != portalPage.getOwner()) { cacheByUser.remove(oldPortalPage.getOwner().getKey()); } } return returnPage; }
public void delete(final Long portalPageId) { notNull("portalPageId", portalPageId); PortalPage oldPage = null; try { oldPage = delegateStore.getPortalPage(portalPageId); delegateStore.delete(portalPageId); } finally { cacheById.remove(portalPageId); if (oldPage != null && oldPage.getOwner() != null) { cacheByUser.remove(oldPage.getOwner().getKey()); } } }
private void assertCreate(final PortalPage portalPage) { notNull("portalPage", portalPage); if (!portalPage.isSystemDefaultPortalPage()) { notNull("portalPage.owner", portalPage.getOwner()); } notNull("portalPage.pageName", portalPage.getName()); } }
protected JiraServiceContext getJiraServiceContext(long id) { JiraServiceContext ctx; final PortalPage dashboard = getDashboard(id); if (permissionManager.hasPermission(ADMINISTER, getLoggedInUser())) { ctx = new JiraServiceContextImpl(dashboard.getOwner()); } else { ctx = getJiraServiceContext(); } return ctx; }
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="UL_UNRELEASED_LOCK_EXCEPTION_PATH", justification="This appears to be doing exactly the right thing with the finally-clause to release the lock") public PortalPage create(final PortalPage portalPage) { Assertions.notNull("portalPage", portalPage); Assertions.notNull("portalPage.name", portalPage.getName()); Assertions.notNull("portalPage.owner", portalPage.getOwner()); PortalPage returnPage = null; try { returnPage = delegateStore.create(portalPage); } finally { if (returnPage != null) { cacheByUser.remove(portalPage.getOwner().getKey()); cacheById.remove(returnPage.getId()); } } return copyPortalPage(returnPage); }
private boolean checkOwnership(final JiraServiceContext serviceCtx, final PortalPage portalPage) { // check the null user. final ApplicationUser user = serviceCtx.getLoggedInApplicationUser(); final ErrorCollection errorCollection = serviceCtx.getErrorCollection(); if (user == null) { errorCollection.addErrorMessage(serviceCtx.getI18nBean().getText("admin.errors.portalpages.owned.anonymous.user")); } else { if (portalPage.getOwner() == null || !portalPage.getOwner().equals(user)) { errorCollection.addErrorMessage(serviceCtx.getI18nBean().getText("admin.errors.portalpages.must.be.owner")); } } return !errorCollection.hasAnyErrors(); }
public Builder portalPage(PortalPage page) { id = page.getId(); name = page.getName(); description = page.getDescription(); isSystemDashboard = page.isSystemDefaultPortalPage(); favouriteCount = page.getFavouriteCount(); permissions = page.getPermissions(); layout = page.getLayout(); owner = page.getOwner(); version = page.getVersion(); return this; }
public PortalPage create(final PortalPage portalPage) { Assertions.notNull("portalPage", portalPage); Assertions.notNull("portalPage.name", portalPage.getName()); Assertions.notNull("portalPage.owner", portalPage.getOwner()); final GenericValue gv = delegator.createValue(Table.NAME, MapBuilder.<String, Object>newBuilder(). add(Column.PAGENAME, portalPage.getName()). add(Column.DESCRIPTION, portalPage.getDescription()). add(Column.USERNAME, portalPage.getOwner().getKey()). add(Column.FAVCOUNT, 0L). add(Column.LAYOUT, portalPage.getLayout().name()). add(Column.VERSION, 0L). toMap()); return gvToPortalPage(gv); }
public PortalPage update(final PortalPage portalPage) { Assertions.notNull("portalPage", portalPage); Assertions.notNull("portalPage.id", portalPage.getId()); if (!portalPage.isSystemDefaultPortalPage()) { Assertions.notNull("portalPage.owner", portalPage.getOwner()); } final GenericValue gv = findByPrimaryKey(portalPage.getId()); gv.setString(Column.PAGENAME, portalPage.getName()); gv.setString(Column.DESCRIPTION, portalPage.getDescription()); if (!portalPage.isSystemDefaultPortalPage()) { gv.setString(Column.USERNAME, portalPage.getOwner().getKey()); } else { gv.remove(Column.USERNAME); } gv.remove(Column.FAVCOUNT); gv.setString(Column.LAYOUT, portalPage.getLayout().name()); delegator.store(gv); return getPortalPage(portalPage.getId()); }
public boolean validateForDelete(final JiraServiceContext serviceCtx, final Long portalPageId) { Assertions.notNull("serviceCtx", serviceCtx); Assertions.notNull("portalPageId", portalPageId); final ApplicationUser user = serviceCtx.getLoggedInApplicationUser(); final ErrorCollection errorCollection = serviceCtx.getErrorCollection(); if (user == null) { errorCollection.addErrorMessage(serviceCtx.getI18nBean().getText("admin.errors.portalpages.owned.anonymous.user")); } else { final PortalPage page = portalPageManager.getPortalPageById(portalPageId); if (page == null) { errorCollection.addErrorMessage(serviceCtx.getI18nBean().getText("admin.errors.portalpages.nonexistent")); } else if (page.isSystemDefaultPortalPage()) { errorCollection.addErrorMessage(serviceCtx.getI18nBean().getText("admin.errors.portalpages.not.delete.system.default")); } else if (!user.equals(page.getOwner())) { errorCollection.addErrorMessage(serviceCtx.getI18nBean().getText("admin.errors.portalpages.must.be.owner")); } } return !errorCollection.hasAnyErrors(); }