goldstift's blogspot my 2 cent

Posts mit dem Label atlassian werden angezeigt. Alle Posts anzeigen
Posts mit dem Label atlassian werden angezeigt. Alle Posts anzeigen

03 Juni 2011

How to Set Default Comment Security Level in Atlassian JIRA

Atlassian JIRA in my humble opinion one of the greatest issue tracking systems around. Nevertheless there are still many missing features, one of them may be "setting the default comment security level".

There is a nice little confluence wiki page which describes some kind of dirty hack to solve or at least work around this problem. The URL to that page is: http://confluence.atlassian.com/display/JIRA/How+to+Set+Default+Comment+Security+Level

Unfortunately the workaround works only for JIRA 4.1 and lower as Atlassian completely rewrote there UI for version 4.2 onwards. Therefore the <select>-element for the "comment security level" is hidden and the user gets to see a HTML dropdown which is much more beautiful and nicer to work with. But it breaks the above mentioned hack as the HTML dropdown doesn't really care about the state of the <select>-element, as it holds the state inside of its own "model".
There is already a JIRA issue describing the problem: JRA-23365

I couldn't solve the problem completely as I have absolutely no knowledge about the inner workings of "AJS", Atlassians Javascript Library, but I somehow could extend the above mentioned workaround.

Here's the code I put into my "announcement banner" field:
<script language="JavaScript">
    <!--
    jQuery.noConflict();
    var defaultRoleName = 'role:10030'
    window.onload = function() {
        var commentLevelSelect = document.getElementById("commentLevel");
        if (commentLevelSelect) {
            for (var i = 1; i < commentLevelSelect.options.length; i++) {
                if (commentLevelSelect.options[i].value == defaultRoleName) {
                    commentLevelSelect.options[i].selected;
                    commentLevelSelect.value = defaultRoleName;
                    jQuery("a.drop span.icon").removeClass("icon-unlocked").addClass("icon-locked");

                    var htmlEscapedLabel = AJS.$("<div/>").text(commentLevelSelect.options[i].text).html();
                    jQuery("span.current-level").html(AJS.format(AJS.params.securityLevelViewableRestrictedTo, htmlEscapedLabel))

                    break;
                }
            }
        }
    }
    //-->
</script>
<style>
   .alertHeader{display:none;}
</style>
Any comments and suggestions on this are very much appreciated!

Update 2012-02-02: I updated the code and tested it with JIRA 4.3.4