Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Want to hide Archive & Delete option from Board

Aisha M
Contributor
September 27, 2024

In our Jira Board, when we right click an issue card, it shows options to Archive or Delete the issue. 

Is it possible to hide these options using Scriptrunner Fragments or something ?

The reason is because, we currently have a condition where only completed issues can be archived. But, this Board option defies that condition and enables users to archive any issue irrespective of its status. So, want to limit that.

4 answers

3 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Tuncay Senturk
Community Champion
September 30, 2024

Hi @Aisha M 

Thanks for mentioning me.

Yes, you can hide the "Archive" and "Delete" options using ScriptRunner Fragments.

- Go to ScriptRunner in your Jira instance.

- Navigate to Scripted Fragments and create a new fragment

- Select Hide UI element

- select "com.atlassian.jira.plugin.system.issueoperations:archive-issue"

and "com.atlassian.jira.plugin.system.issueoperations:delete-issue" options.

 

Please let me know if you have further questions

Best,

Tuncay

Aisha M
Contributor
September 30, 2024

@Tuncay Senturk  Thank you sooo much for getting back ! 

Actually we do have a fragment to hide the 'Archive" option from issues. Basically, archive option will be available only when an issue is in the resolved status.

But despite having this fragment, I observed users can still archive an issue from the Board context menu. 

So, even if I hide the archive element with  com.atlassian.jira.plugin.system.issueoperations:archive-issue the issue can still be archived by right clicking the issue from the board and selecting "archive"

Like Tuncay Senturk likes this
Tuncay Senturk
Community Champion
September 30, 2024

Sorry for the misunderstanding.

I think the actions that come with the board are not selectable in the fragment so I cannot offer any solution on this.

I'm not entirely sure if this is a good approach, but you could create a listener that checks for the Archive action and prevents it when the issue's status doesn't meet your criteria. Please take this suggestion with a pinch of salt, as I haven't personally tried it. However, if I were in your position, I would give it a try with a code something like below.

def issue = event.issue as Issue
def status = issue.getStatus().getName()

if (status != "Resolved") {
log.warn("Archiving is only allowed for issues in 'Resolved' status. Action blocked.")

// throw an exception to prevent the action
throw new IllegalStateException("Cannot archive issue as it is not in Resolved status.")
}

 

Aisha M
Contributor
September 30, 2024

@Tuncay Senturk  Let me try the approach with the listener. Unable to reply to your latest comment (not sure why)

But this also means there is not guarantee that the archive action will be prevented from the Board context menu, right ? :)

 

Tuncay Senturk
Community Champion
September 30, 2024

Using a listener to prevent actions is the back-end solution. This listener will stop users from archiving or deleting an issue, whether they are using a UI button, a REST service, or any other method. You can remove the link from UI but users may still call the back-end service using REST or do some hacking via UI. Think of it as insurance - if you forget to remove a link, the listener will take care of it.

But, like I said, this might not be the best approach.

Aisha M
Contributor
September 30, 2024

I tried it with the below listener. But, unfortunately, it runs AFTER the issue is archived from the context menu and shows as failed in the logs . I have tried it with events - Issue updated & all issue events

 

def log1 = Logger.getLogger("PreventArchiving")

def event1 = event as IssueEvent

log1.info("Listener executed for event: ${event1.eventTypeId}")

def issue = event1.issue as MutableIssue

if (issue) {

ArchivedIssueService archivedIssueService = ComponentAccessor.getComponent(ArchivedIssueService)

    def status = issue.status.name

    log1.info("Attempting to archive issue ${issue.key} with status ${status}")

    if (status != 'Resolved') {

        log1.warn("Preventing archive action for issue ${issue.key} with status ${status}")

        throw new Exception("Issue ${issue.key} cannot be archived because it is not in a resolved state.")

    }

}
Like Tuncay Senturk likes this
Tuncay Senturk
Community Champion
September 30, 2024

Hmm, that's bad news. I was thinking that it might have worked as an interceptor.

Sorry, I wasn't helpful on this one. Let me think about it and write back if I find something useful.

Aisha M
Contributor
September 30, 2024

No no, you were super helpful in giving me suggestion to think outside the box :):)

Thank you ! But I must add, I also come across this ticket https://jira.atlassian.com/browse/JSWSERVER-9557 - Looks like there isn't must flexibility with the context menu

Like Tuncay Senturk likes this
Tuncay Senturk
Community Champion
September 30, 2024

Yeah, Looks like so :( 

Tuncay Senturk
Community Champion
October 1, 2024

Hello @Aisha M 

I could not find a better solution but to limit/restrict users as @Antoine Berry mentioned. Sorry!

Aisha M
Contributor
October 1, 2024

Thank you for checking back :)

Actually my org just recently gave EVERY USER the right to archive resolved issues . . lol

But I also came across this after some digging, https://community.atlassian.com/t5/Jira-questions/Hide-entrys-from-scrum-kanban-board-context-menu-via-javascript/qaq-p/1431344  . . Maybe will test this out :D

Tuncay Senturk
Community Champion
October 1, 2024

Yeah, you can also perform that trick, but you need to check it every time you update Jira because they might change the CSS class or the identifier that you use to hide the web element.

Like Antoine Berry likes this
Aisha M
Contributor
October 3, 2024

I was able to successfully hide Archive by using javascript in the announcement banner *yayyy* 

But, when you say the identifier might change, it means we might have to update the script only when we upgrade the version of Jira, right ? Also, do you think this method might hamper any other functionality within Jira . .  We have a hugeeee number of projects & users, so just want to make sure I'm not overlooking anything else that might break because of this minor change :)

Like Antoine Berry likes this
Tuncay Senturk
Community Champion
October 3, 2024

I'm glad you figured that out, @Aisha! That's great news. The impact of the script depends on the selector you use. For example, the script in the thread you mentioned (below I copied a snippet) uses an id (starts with #), and id values are unique, so it won't impact other HTML elements.

$("#ghx-issue-ctx-action-flag-toggle").css("display", "none");

However, sometimes people use selectors with CSS classes (starting with .) that can be applied to various elements. As a result, all elements that use that class would be affected.

$(".a-css-class").css("display", "none");

Also, these are the design values that Jira developers use. They may change them in the upcoming releases. In those circumstances, you need to check and update the scripts accordingly after upgrading your Jira.

If you share your code, I might be a little more helpful, I guess.

I hope that helps.

Best

Like Antoine Berry likes this
Aisha M
Contributor
October 3, 2024

Oooh makes sense . . I used the chrome inspect tool to find the element for the context menu archive option. 

<script>
if (document.URL.indexOf("RapidBoard.jspa") >= 0) {
AJS.$ (document).on("showLayer", function() {
$("#ghx-issue-ctx-action-archive").css("display", "none") ;
});
}
</script>

 

Like Tuncay Senturk likes this
Tuncay Senturk
Community Champion
October 3, 2024
#ghx-issue-ctx-action-archive

this is good, it's the id value :) 

Like Aisha M likes this
0 votes
Answer accepted
Aisha M
Contributor
October 9, 2024

SOLUTION -

Adding a javascript to the Announcement banner

 

<script>
if (document.URL.indexOf("RapidBoard.jspa") >= 0) {
AJS.$ (document).on("showLayer", function() {
$("#ghx-issue-ctx-action-archive").css("display", "none") ;
});
}
</script>

 

0 votes
Answer accepted
Antoine Berry
Community Champion
October 1, 2024

Hello @Aisha M ,

Have you considered restricting the Archive and Delete permissions to only the project admins ? That would also be in line with best practices. That would prevent your users to delete an issue by mistake, and then it is gone forever.

Aisha M
Contributor
October 1, 2024

Hellooo :) Actually our org have given every user the permission to archive any resolved issue. For the other statuses, the Archive option will be hidden. Now, they want to understand if users can archive issues from the board context menu. And from my testing, I can conclude anybody can archive issues from the context menu irrespective of the status .

I also came across this old question https://community.atlassian.com/t5/Jira-questions/Hide-entrys-from-scrum-kanban-board-context-menu-via-javascript/qaq-p/1431344  This person had hidden an option from the context menu through the announcement banner. Curious to see how this goes. 

Like Antoine Berry likes this
0 votes
Aisha M
Contributor
September 30, 2024

@Tuncay Senturk  Hellooo, Hope you are well and good :) Can you please help me with your suggestion/

I am just looking for ways to hide elements from the Board context menu (Right click on the card) . . Is it possible to hide the Archive & Delete options from them ? 

Aisha M
Contributor
October 9, 2024

Thank you so much @Tuncay Senturk  & @Antoine Berry  for your suggestions. It really helped me think of other perspectives for figuring out a solution. Also, I have accepted both your answers since, both of them contained solution that could be used for similar scenario :):)  

On a side note, my team has dropped this request and hence I have now moved on to a different problem related to workflows . .  ;( 

Like Tuncay Senturk likes this
Tuncay Senturk
Community Champion
October 9, 2024

You are more than welcome @Aisha M 

I'm happy to have been of help in any way.

Like Aisha M likes this
Aisha M
Contributor
October 9, 2024
TAGS
AUG Leaders

Atlassian Community Events