Data Center to Cloud: The Story of Developing a Niche Jira App on Forge

Every developer has the project. The one that began with an easy concept, but becomes a game of frustrations and ups and downs of technical issues, experiments with design, and learning to live with the peculiarities of the platform that you were to be working with. In my case, such undertaking was the migration of my Data Center app, ASiC Viewer, to the Atlassian Cloud.

Here is the narrative of that trip – a tale of struggling with UI Kit 2, authentication circles, and searching in vain after that native Jira feel.

The Issue: The lack of a Jira capability to recognize/read signatures from ASiC containers

Digital signatures are not only convenient in Europe but a legal obligation. Contracts, official submissions, and legal documents today are often handled in formats such as BDOC, EDOC, ASICS, and others. To check a signature, our users were forced to:

  1. Download the attachment.
  2. Open desktop application or use online validation platform.
  3. Upload the file there.
  4. Analyze the results.

It was cumbersome, bulky and interrupted the process. My Data Center application fixed this by allowing users to see the signatures in Jira. It worked beautifully. However, as Atlassian drove a definite “Cloud-first” strategy, I realized I had to “move” our plugin to Jira Cloud.

The Cloud Imperative: Not Just a Port

Initially, I believed that I would simply be able to port our Java application to the Cloud. I was wrong. Forge is a totally different animal. You are no longer dropping code into Jira, you are creating a sandboxed web app that communicates with Jira through APIs. It was a complete rewrite – Java to Node.js and React. This wasn’t just a port, I had to start from the very beginning.

UI/UX Odyssey: Pursuing the UIKit 2: The Jira Feel

Phase 1: The “Broken” Table
My initial effort of creating good attachment list was a mess. Columns didn’t line up. The Stack and Inline components of UI Kit 2 are not designed to work in hard tables – any attempt to make them do so caused everything to break.

Phase 2: The Over-engineered Accordion.
Then I experimented with an interactive accordion: a row is clicked, and one can expand it inline to read the details. Modern, but disruptive. The layout of the page was moved over-the-top and in order to just check the signature, it felt clunky.

Phase 3: Mimic, Don’t Reinvent
Finally, I asked myself: “How lists look originally in Jira Cloud? ” I abandoned my experiments and reproduced the well-known pattern. The component that came to the rescue of us was the Popup component which was lightweight, contextual and fast. On a single click of the View Signatures button, a nice pop-up was brought up attached to the button.

Agonizing with Forge: The notorious Authentication Loop

Every Forge developer will eventually bump into NEEDS_AUTHENTICATION_ERR. I was no exception. My application was properly using the secure asUser() API calls, but I kept getting the user consent prompt over and over again.

INFO    13:06:47.679  49458f07-ce56-4473-9d22-afa224615b33  [asic-cloud] handler route { action: 'getIssueAttachments', payloadKeys: [ 'issueId' ] }
INFO    13:06:47.679  49458f07-ce56-4473-9d22-afa224615b33  [asic-cloud] doGetIssueAttachments { issueId: '10000' }
INFO    13:06:47.680  49458f07-ce56-4473-9d22-afa224615b33  [asic-cloud] fetchIssueAttachmentsAsUser start { issueId: '10000' }
ERROR   13:06:47.998  49458f07-ce56-4473-9d22-afa224615b33  handler failed [NEEDS_AUTHENTICATION_ERR: Authentication Required] {
  status: 401,
  serviceKey: 'atlassian-token-service-key',
  options: undefined
}

ERROR   13:06:47.998  49458f07-ce56-4473-9d22-afa224615b33  [NEEDS_AUTHENTICATION_ERR: Authentication Required] {
  status: 401,
  serviceKey: 'atlassian-token-service-key',
  options: undefined
}

I chased every rabbit hole. I tried complex workarounds, manually catching and throwing 401 errors, believing it was a logic bug. Religiously repeated the clean uninstall and reinstall process, thinking there was a conflict between my local forge tunnel and the deployed development environment. Nothing worked.

The actual answer was simple and buried in the Forge permission scheme.

The problem wasn’t my code—it was manifest.yml. In my attempt to follow the “Principle of Least Privilege,” I had been too aggressive. I was only using the most granular scopes, like read:attachment:jira. It turns out that for the user consent flow to authorize and remember decisions across the app, a slightly broader scope was required.

permissions:
  scopes:
    - 'read:jira-work' # The key to solving the loop
    - 'read:attachment:jira'
    - 'read:jira-user'

Lessons Learned in the Forge

This trip was not only a code writing exercise, but also an exercise in learning a new way of developing Atlassian apps. Here are my key takeaways:

  1. Accept the Limitations: The limitations that UI Kit 2 has are not bugs; they are features that provide security, consistency and accessibility. Rather than struggling against the framework, application of its components (such as Popup and Grid) to their intended purpose will give the best results.
  2. The Compass is the User Feeling: It was the feeling that the design was a bit broken, or the feeling that the design was not quite right, which led me. The process of endless repetition of spacing, alignment, and micro-interactions is what makes a functional tool a professional product.
  3. Replicate the Native UI: Users are already experts in using Jira.

You can check out the final app on the Atlassian Marketplace here.

Favourite Filters Issue Count Performance problems in large instances (Jira)

As described in this Atlassian ticket there may be performance problems using Favourite Filters gadget in large Jira instances.

In our Jira instance (>2m issues, >10k users) these favfilters?showCounts=true requests where very expensive to CPU load.

In Atlassian ticket there is workaround provided how to turn off this feature in proxy level, but what to do if no proxy is used in front of Jira?

In our case we used Tuckey UrlRewriteFilter which is built in Jira by default. Open /jira_install_dir/atlassian-jira/WEB-INF/urlrewrite.xml and add this code before closing </urlrewrite> tag:

<rule enabled="true">
    <name>Disables Favourite Filters Issue Count</name>
    <condition type="parameter" name="showCounts" operator="equal">true</condition>
    <from>^/rest/gadget/1.0/favfilters</from>
    <to type="permanent-redirect">/rest/gadget/1.0/favfilters?showCounts=false</to>
</rule>

After Jira restart users will see “UNDEFINED” result if they turn on Issue Count functionality.

Rename attachments in Jira using Groovy

While Atlassian is “GATHERING INTEREST” to implement file renaming feature in Jira, it is possible to rename attachments using Groovy.

If you use JMWE, Scriptrunner, etc.  in Jira, you can use following Groovy script:

import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.ofbiz.OfBizDelegator
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.Attachment

def attachmentManager = ComponentAccessor.getAttachmentManager()

OfBizDelegator delegator = ComponentAccessor.getComponentOfType(OfBizDelegator.class)
issue.get("attachment")?.each {
  for(GenericValue attachment : delegator.findByField("FileAttachment", "id", it.id)){ 
      attachment.setString("filename", "no_klienta_"+it.filename)
      attachment.store()
  } 
}

 

Update Jira issues from MS Excel spreadsheet using Powershell script (updated: 13.05.2019.)

I have created Powershell script which allows to set values in Jira issues using data from MS Excel spreadsheet.

Script is based on following Powershell modules:

Usage:

  1. Set Jira server address in “update_issues.ps1” file.
  2. Update data in “data_for_issues.xlsx”
  3. Set custom field configuration according to your needs in “update_issues.ps1”
  4. Launch “update_issues.bat”, enter your Jira credentials and wait for script to complete.
  5. Log file is created next to “update_issues.ps1” file.

Download (updated: 13.05.2019.): update_issues_PS_script_V2.zip

update_issues.ps1 (updated: 13.05.2019.):

$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path .\script\update_issues.log -append

Import-Module .\script\JiraPS
Import-Module .\script\PSExcel

####### Define some variables below ########

#Excel data file
$path = ".\data_for_issues.xlsx"

#Jira adresss
Set-JiraConfigServer -Server "https://jira-server.com"

############################################

$issues = new-object System.Collections.ArrayList

foreach ($field in (Import-XLSX -Path $path -RowStart 1))
 
{
    $issues.add($field) | out-null
}

$issuesfull = @()

foreach ($issue in $issues | Where { $_.key -and $_.key.Trim() })
{
    $i++
    $issuesfull += ($issue.key)
}

Write-Host "Pieteikumi: " $issuesfull  -ForegroundColor yellow
Write-Host "Dati tiks rakstīti" $i "pieteikumos. Tiklīdz ievadīsies lietotāja datus, tā sāksies datu rakstīšana." -ForegroundColor green
Write-Host "--------------------------------------" -ForegroundColor green

$cred = Get-Credential

foreach ($issue in $issues | Where { $_.key -and $_.key.Trim() })
{
    write-host "`n"
    $a++
    Write-Host "Izpildes statuss: " $a "/" $i -ForegroundColor gray
    Write-Host "Raksta datus pieteikumā: " $issue.key -ForegroundColor green
    Write-Host "Investīciju gads: " $issue.ig
    Write-Host "Projekta uzsākšanas gads: " $issue.pug
    Write-Host "Ranga datums: " $issue.rd.ToString('yyyy-MM-dd')
    Write-Host "Ranga vieta: " $issue.vr

## Custom field configuration

    $fields = @{
        customfield_11758 = @{
            value = [string]$issue.ig
        }
        customfield_12031 = @{
            value = [string]$issue.pug
        }
        customfield_24240 = $issue.rd.ToString('yyyy-MM-dd')
        customfield_24241 = [int]$issue.vr
    }

    Try
    {
        Set-JiraIssue -Issue $issue.key -Fields $fields -Credential $cred
        Write-Host "Dati ierakstīti pieteikumā: " $issue.key -ForegroundColor green
    }
    Catch
    {
        $ErrorMessage = $_.Exception.Message
        $FailedItem = $_.Exception.ItemName
        Write-Host "Error: $ErrorMessage" -ForegroundColor red
    }
    
}

Write-Host -NoNewLine "Datu rakstīšana pieteikumos beigusies. Nospiediet jebkuru taustiņu, lai izietu..." -ForegroundColor yellow
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
Stop-Transcript

How to disable the PDF Preview feature in JIRA 7

  • Copy locally and extract Jira bundled plugin jira-fileviewer-plugin-7.2.1.jar located at ./atlassian-jira/WEB-INF/atlassian-bundled-plugins
  • In extracted folder open file-service.js and delete (or wrap in comment) following lines:
if (!featureManager.isFeatureEnabled("jira.fileviewer.disable.pdf")) {
    selectors.document.push("a[file-preview-type=document]");
}
addDocumentSelector: function addDocumentSelector(sel) {
    pushSingleOrArray(selectors.document, sel);
}
  • Remove same lines from minified file-service-min.js.  You can use JS prettify and minify tools to do this.
  • Save files. Put folder content in ZIP. Rename file to jira-fileviewer-plugin-7.2.1.jar, copy to server and restart Jira.