@Override public List<IssueAction> getActions(Issue issue, ApplicationUser remoteUser) { JiraServiceContextImpl context = new JiraServiceContextImpl(remoteUser, new SimpleErrorCollection()); List<Worklog> userWorklogs = worklogService.getByIssueVisibleToUser(context, issue); List<IssueAction> worklogs = Lists.newArrayListWithCapacity(userWorklogs.size()); final Locale userLocale = context.getI18nBean().getLocale(); for (Worklog userWorklog : userWorklogs) { boolean canEditWorklog = worklogService.hasPermissionToUpdate(context, userWorklog); boolean canDeleteWorklog = worklogService.hasPermissionToDelete(context, userWorklog); worklogs.add(new WorklogAction(descriptor, userWorklog, jiraDurationUtils, canEditWorklog, canDeleteWorklog, fieldLayoutManager, rendererManager, userLocale, userFormats)); } // This is a bit of a hack to indicate that there are no comments to display if (worklogs.isEmpty()) { IssueAction action = new GenericMessageAction(descriptor.getI18nBean().getText("viewissue.nowork")); return Lists.newArrayList(action); } Collections.sort(worklogs, IssueActionComparator.COMPARATOR); return worklogs; }
public boolean hasPermissionToUpdateWorklog(User user, String worklogId) throws RemoteException, RemoteValidationException { JiraServiceContext serviceContext = new JiraServiceContextImpl(user, new SimpleErrorCollection()); Long id = SoapUtils.toLongRequired(worklogId); Worklog worklog = worklogService.getById(serviceContext, id); // getById does not currenty return errors but it might so we do this code checkAndThrowValidationException(serviceContext.getErrorCollection()); return worklog != null && worklogService.hasPermissionToUpdate(serviceContext, worklog); }
public String doDefault() throws Exception { // Retrieve the worklog worklog = worklogService.getById(getJiraServiceContext(), getWorklogId()); if (worklog == null) { addErrorMessage(getText("logwork.error.update.invalid.id", (getWorklogId() == null) ? null : getWorklogId().toString())); return ERROR; } if (!worklogService.hasPermissionToUpdate(getJiraServiceContext(), worklog)) { //user doesn't have permission to run this action return "securitybreach"; } //pre-populate the fields final BigDecimal hoursPerDay = getHoursPerDay(); final BigDecimal daysPerWeek = getDaysPerWeek(); final BigDecimal secondsPerHour = BigDecimal.valueOf(DateUtils.Duration.HOUR.getSeconds()); final long secondsPerDay = hoursPerDay.multiply(secondsPerHour).longValueExact(); final long secondsPerWeek = daysPerWeek.multiply(hoursPerDay).multiply(secondsPerHour).longValueExact(); setTimeLogged(DateUtils.getDurationStringSeconds(worklog.getTimeSpent(), secondsPerDay, secondsPerWeek)); setStartDate(getFormattedStartDate(worklog.getStartDate())); setComment(worklog.getComment()); setCommentLevel(CommentVisibility.getCommentLevelFromLevels(worklog.getGroupLevel(), worklog.getRoleLevelId())); return super.doDefault(); }