Dashboard - managing permissions for groups

vincent beudez January 11, 2012

hi,

I would like to prevent some user groups from creating/managing/modifying dashboard. But i cannot find it in the global permissions. Where could i manage these permissions please?

Thanks,

Vincent

11 answers

1 accepted

7 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 11, 2012

How about doing it with some javascript... would not stop direct url access but you can remove the links to configure the dashboard.

Here is a complete example. The only thing not shown is the <script> tags if you choose to put this in the announcement banner.

(function($){
    $(function(){

		$.get(AJS.params.baseURL + "/rest/auth/1/session", function (data) {
			userName = data.name;

			// check groups
			$.get(AJS.params.baseURL + "/rest/api/2.0.alpha1/user", {username: userName, expand: "groups"}, function (data) {
				var groups = data.groups;
				var groupItems = jQuery.map(groups.items, function (val, j) {return val.name});

				// modify group(s) allowed to edit dashboard in the line below
				if (jQuery.inArray("jira-administrators", groupItems) &lt; 0) { 
					$("#dash-options").hide();
					$('ul#dashboard_link_manage').hide();
				}
			});
		});
    });
})(AJS.$);

(https://gist.github.com/2629735)

vincent beudez January 12, 2012

I like your solution, thanks :)

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 12, 2012

upvote then, please!

DOT-COMmunications May 3, 2012

Hi Jamie

I like this solution too as a simple option, is there any chance of a more complete script as not very good with Javascript or REST?

Thanks

Adam

DOT-COMmunications May 4, 2012

Hi @Jamie

I tried to just create one to hide the dashboard stuff from everyone using this:

&lt;script type="text/javascript"&gt;
jQuery(function ()
{
        AJS.$("#dash-options").hide()
});
&lt;/script&gt;

as well as setting the jQuery part to:

jQuery(document).ready(function() {

none of which worked, any ideas?

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 2012

That worked for me... where did you put the code? Are you sure it got through to the page source?

what jira version is it?

DOT-COMmunications May 5, 2012

Which one of the 2 worked?

I put it in the annoucement banner at the end of it as we do have content in it as well (text only)

We are using JIRA 4.4.4 and im not sure it got into the page source, im guessing i can just do a simple view source to confirm? If it didnt then how can i get it into the source.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 5, 2012

They're both the same, the second is just a more verbose version of the first. Yes, just look at the page source, and look at the console for any errors.

DOT-COMmunications May 5, 2012

No errors in either stdout, stderr or atlassian-jira log file and the code shows up in the source on the page where it should be.

Doesnt seem to hide anything though

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 5, 2012

It wouldn't be in any of those places. If there are javascript errors it will show in the browser.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 5, 2012

So get Chrome, go to the dash, press F12, click the console tab, and just paste in

AJS.$("#dash-options").hide()

If that doesn't work then there's some other issue to deal with.

DOT-COMmunications May 5, 2012

Ok that worked.

But Firefox and Chrome both show the options unless i run that command manually.

It still also lets users create a dashboard by doing the drop down on dashboards and then doing manage and then create but i can always add into the javascript once it works to remove the links by adding

AJS.$('ul#dashboard_link_manage').hide()

To the code and that hides the Manage Dashboard link and text

DOT-COMmunications May 6, 2012

Turns out i had a syntax error in the javascript - too many { compared to } but that didnt fix it when using document.ready

When i ran an alert after the code it was before the dashboard had even started to load so how could it hide something that wasnt displayed. I changed it to window.load instead and although it took longer before the alert was displayed the code actually worked okay so i will be using that for the moment.

Next problem now is how to make it exclude the jira-administrators group from the code, any ideas?

My current code is below:

jQuery(window).load(function() {
        AJS.$("#dash-options").hide();
        AJS.$('ul#dashboard_link_manage').hide()
});

You can also do it using document.ready by inducing a timeout to delay the page long enough for the data you want to hide to be displayed, i have found that this works okay for me but you might need to adjust the timeout for your server, it also hides the drop down link at the side of dashboards header so that you cant go to manage dashboards page and create on there, although it might be better to just hide the create dashboard link on that page so that you can still manage dashboards

jQuery(document).ready(function() {
  function hideme() {
        AJS.$("#dash-options").hide();
        AJS.$('a#home_link_drop').hide();
  }
  setTimeout (hideme, 2000);
});

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 7, 2012

I've updated the answer with a complete, tested, working example for hiding the dashboard options unless the user is in jira-admins. PS - try to avoid setTimeout.

> When i ran an alert after the code it was before the dashboard had even started to load so how could it hide something that wasnt displayed

The point about using the DOM ready function is that the whole dom is present, parsed and ready for action.

DOT-COMmunications May 7, 2012

Hi Jamie

Thanks for updating with an example, it will be a great help to many users im sure.

Just out of interest why is setTimeout such a bad thing? If i should avoid setTimeout then would window.load be better as when i used document.ready it just didnt work?

DOT-COMmunications May 7, 2012

Hi @Jamie

Your example works perfectly thank you for providing it. It was a great help and i suspect it will be for others too. I just changed the ul#dashboard_link_manage line to ul.operations a#create_page instead so that it hides the create dashboard link rather than the manage dashboard link.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 8, 2012

Hi @Adam,

> Your example works perfectly

Cool, feel free to vote up my answer/comments ;-)

> Just out of interest why is setTimeout such a bad thing

The problem is, you have a timeout of 2 seconds. Either that's too long, in which case it's just time wasted, and the user can see the link which then disappears causing confusion, or it's too short and it doesn't work. Sometimes it's unavoidable but I don't see the need for it in this case, if you write the event handlers correctly.

> If i should avoid setTimeout then would window.load be better as when i used document.ready it just didnt work

I don't know why it didn't work when you used it... my code above uses document.ready, $() is just a shorthand for that. The window.load event happens after all resources are loaded, possible a long time after doc.ready, so again it's just time wasted. And time is money after all.

cheers, jamie

Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 21, 2012

Hi @jamie,

I tried your script in an announcement banner (including the script tags) but it won't work. I get the following error:

  1. GET http://www.c-p-systems.de/jiratest/rest/api/2.0.alpha1/user?username=demouser&expand=groups&_=1337679880568 404 (Not Found) batch.js:1
    1. d.support.ajax.d.ajaxTransport.sendbatch.js:1
    2. d.extend.ajaxbatch.js:1
    3. d.each.d.(anonymous function)batch.js:1
    4. (anonymous function)Dashboard.jspa:357
    5. d.extend._Deferred.f.resolveWithbatch.js:1
    6. d.support.ajax.d.ajaxTransport.send.cbatch.js:1

Launching the script "AJS.$("#dash-options").hide()" mannually works fine...

Any ideas? Maybe I am missing something. (I'm working with JIRA 5.0)

Thanks for your help.

Cheers Christian

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 3, 2012

Try using "latest" instead of "2.0.alpha.1". The api url changed in recent versions of jira. If that doesn't work you could check the rest api docs.

0 votes
Trent Murray May 11, 2015

All,

The solution I used was slightly different. I didn't like the fact that the element showed up for a split second. So, by default I hide the element in CSS first, then I just the JQuery to display it when the user HAS permission to view it.

&lt;style&gt;
/** Get rid of the dashboard link by default **/
#home_link {display: none;}
&lt;/style&gt;

&lt;script type="text/javascript"&gt;
(function($){
    $(function(){
  
        $.get(AJS.params.baseURL + "/rest/auth/1/session", function (data) {
            userName = data.name;
  
            // check groups
            $.get(AJS.params.baseURL + "/rest/api/2/user", {username: userName, expand: "groups"}, function (data) {
                var groups = data.groups;
                var groupItems = jQuery.map(groups.items, function (val, j) {return val.name});
  
                // modify group(s) allowed to edit dashboard in the line below
                if (jQuery.inArray("THE-GROUP-YOU-WANT-TO-VIEW-DASHBOARDS", groupItems) &gt; 0) {
                    $("#home_link").show();
                }
            });
        });
    });
})(AJS.$);
&lt;/script&gt;
0 votes
olai-web June 10, 2014

is there a possibility for 6.2?

0 votes
Support RDI April 30, 2013

Hi Guys..

I can get this Script working very well in the 5.2.6, but i have a doubt.

How can I use more than one group? I would like insert multiple groups to create/manage the Dashboard.

Anyone can help me please?

Thx

Alexandre

0 votes
Kerem Caglar [Solveka]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 13, 2012

On Adam's JS you need to modify user REST url as follows:

/rest/api/2/user

0 votes
Darren Pegg December 3, 2012

Thanks Adam,

I would so prefer non admins to create dashboards.

I'm fairly new to fiddling with code, in the script were advises to edit the groups/users. On which part of the code would i edit these?

I have just tried and now I have a blank JIRA qnd cannot edit the announcement banner through JIRA itself.

Now I'm re-installing and restoring from a back up. Luckily it's DEV

Many thanks

Darren

DOT-COMmunications December 4, 2012

Hi Darren

To edit the groups that the hiding applies to you need to edit where it says:

if (jQuery.inArray("jira-administrators", groupItems) &lt; 0) {

Just change jira-administrators to the group you want to apply this to and to change the page elements that hide just add these to the following lines

$("#dash-options").hide();
$('ul.operations a#create_page').hide();


0 votes
Darren Pegg December 3, 2012

Hi Adam,

Thanks for your reply, Did you add this into the anouncement banner? Or will be editing a file sat within the installation of JIRA?

I have placed it within the A.Banner section and used a non admin account to test and the options are still visible.

I'm assuming I'm doing something else incorrect?

Do I need any developer apps installed within JIRA in the way of addons?

Regards

Darren

DOT-COMmunications December 3, 2012

Hi Darren

The script above was placed in the annoucement banner as we wanted to do the same as you and hide creating a dashboard from our non-admin users as i prefer to create the dashboards and then share them with the users that need access to them.

We were running JIRA 4.4 when we tried this originally and to be honest i havent tried this since we upgrade through 5.0.6 to 5.1 as the plugins we use got updated.

I dont think it requires any addons and that the jQuery library is built into JIRA by default as that is what it uses to do the hiding.


*UPDATE*

I have checked on JIRA 5.1 and it seems to hide the Add Gadget links and Edit Layout links, i am assuming the other options have had their CSS tags changed so the script would require some editing to hide those but you should be able to find those using your web browser and or an addon for your browser and then just add those along with the others

Adam

0 votes
DOT-COMmunications December 3, 2012

Hi Darren

I managed to get it to work using this...

&lt;script type="text/javascript"&gt;
(function($){
    $(function(){
 
        $.get(AJS.params.baseURL + "/rest/auth/1/session", function (data) {
            userName = data.name;
 
            // check groups
            $.get(AJS.params.baseURL + "/rest/api/2.0.alpha1/user", {username: userName, expand: "groups"}, function (data) {
                var groups = data.groups;
                var groupItems = jQuery.map(groups.items, function (val, j) {return val.name});
 
                // modify group(s) allowed to edit dashboard in the line below
                if (jQuery.inArray("jira-administrators", groupItems) &lt; 0) {
                    $("#dash-options").hide();
                    $('ul.operations a#create_page').hide();
                }
            });
        });
    });
})(AJS.$);
&lt;/script&gt;

Hope that helps

Adam

0 votes
Darren Pegg December 3, 2012

Did anyone get this to work in the announcement banner? Manually running this works fine..

Regards

Darren

0 votes
Neal Applebaum
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 11, 2012

See this enhancement request:

https://jira.atlassian.com/browse/JRA-8689

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 11, 2012

There's no functionality for stopping people from customising their dashboards. I think there's a global hack in code which would let you stop everyone, but even that isn't group-aware, it's everyone or nobody.

vincent beudez January 11, 2012

uuuurg, thanks for the answer. This will be a problem :s

i'll try to see with the devs what they can do with it.

DOT-COMmunications May 5, 2012

@Nic Brough

I dont suppose you know what this hack is or a link to it?

Suggest an answer

Log in or Sign up to answer