How can we extend the DefaultWorklogService and Override methods that we want?

Hey Folks,

Recently, I wanted to achieve below in the JIRA Server 7.12.0

When issue is not editable (workflow property jira.issue.editable=false) in a workflow state, I still want admins to be able to log time behalf of other developers without changing the state to a editable one.

Options I have tried, make the issue editable for admins using the workflow property jira.permission.edit.projectrole, this worked for enable editing for admins but it also enabled worklog submissions for developers as well :frowning: (when using jira.issue.editable property it disabled editing option of an issue including the worklog submissions)

I have already written some plugin code which exposes and rest API resource which can be used to timelog behalf of the other users, however I just wanted to avoid the default permission check that’s happening inside the DefaultWorklogService and enforce necessary permissions in the plugin code section itself.

Below is the change that I need to do, just to comment out the default permission permission check that’s happening there.

    public WorklogResult validateCreate(JiraServiceContext jiraServiceContext, WorklogInputParameters params) {
        ApplicationUser user = jiraServiceContext.getLoggedInApplicationUser();

        // Does the user have permission to create a worklog
        //if (hasPermissionToCreate(jiraServiceContext, params.getIssue(), params.isEditableCheckRequired())) {
        Worklog worklog = validateParamsAndCreateWorklog(jiraServiceContext, params.getIssue(), user, params.getVisibility(),
                params.getTimeSpent(), params.getStartDate(), null, params.getComment(), null, null, null, params.getErrorFieldPrefix());
        if (worklog != null) {
            return WorklogResultFactory.create(worklog, params.isEditableCheckRequired());
        return null;

However, when you write a code which extends DefaultWorklogService we get the question of how to load this component as we cannot use ComponentAccessor.getComponent for this, is there anyway we can achieve this ?

I thought this is where Devs hangout :slight_smile: , however earlier I got far better responses from

FYI, I have found a way to do this but still, I’m looking for the proper way, if anyone interested in the solution that I have followed will share it.