Serenity: Enable and disable the Add and the Update buttons at run time according to the role

Created on 5 Jan 2017  路  9Comments  路  Source: serenity-is/Serenity

Hi Volkanceylan,

I am developing an application in Serenity. Thanks for developing the senerity framework. It works awesome. But, in my application Add,Update and Delete buttons should be enabled and disabled according to the role provided to the user.

Thanks,
Dinesh H.

Most helpful comment

in yourDialog.ts, override getToolbarButtons()

protected getToolbarButtons() { var buttons = super.getToolbarButtons(); if (!Authorization.hasPermission("Review:Audit:Modify")) { buttons = buttons.slice(2); } if (!Authorization.hasPermission("Review:Audit:Delete")) { buttons = buttons.slice(1); } return buttons; }

All 9 comments

you may use jQuery at yourDialog.ts
inspect browser and get the add/... button css class and get that element by jquery
i mean $('.save-and-close-button').hide()

in yourDialog.ts, override getToolbarButtons()

protected getToolbarButtons() { var buttons = super.getToolbarButtons(); if (!Authorization.hasPermission("Review:Audit:Modify")) { buttons = buttons.slice(2); } if (!Authorization.hasPermission("Review:Audit:Delete")) { buttons = buttons.slice(1); } return buttons; }

Thanks wldkrd1, but when i put above script in Dialog.ts. After compilation, when i refresh the browser it gives blank screen. There is an error in consol of the browser. It would be really helpful, if you provide correction location or whole yourDialog.ts file.

Sorry, that was an example; in my case, I'm checking for specific permissions and removing buttons if they aren't there. You wouldn't have those same permissions, perhaps that's why you are getting an error? What error are you getting?

Thanks wldkrd1.

In my case, after removing protected word from you have suggested. It works for me.

getToolbarButtons() { var buttons = super.getToolbarButtons(); if (!Authorization.hasPermission("Review:Audit:Modify")) { buttons = buttons.slice(2); } if (!Authorization.hasPermission("Review:Audit:Delete")) { buttons = buttons.slice(1); } return buttons; }

Thanks Again.

Amazing job! Thanks to everyone's investment !!
It always returned false for me and I realized that I gave autorisations across roles. If I deliver Autorisation directly to user, it works. How can I test autorisation across roles ?
Thanks by advance !

My mistacke ! I changed permissions in roles (from Modify to Update and Delete separated) and did not check roles again. So roles did have "...:Modify" as I was waiting for "...:Update". It works like a charm! This really is an amazing solution. I really enjoy it a lot!
Many thanks again!

Hi again! I'm sorry but I don't understand how slice property works (particularly start and end numbers).
In a standard Toolbar, we get 3 buttons (update and save, apply changes, delete).
I want to hide the second button (apply changes) depending on some rights.
I did some tests (see below) and I don't find this case.
First column is start and end number. The cross in the 3 columns after is placed when the first, second or third button is hided. I don't reach my case in it.

0 | 聽 | 聽 |

0_0 | x | x | x
0_1 | 聽 | x | x
0_2 | 聽 | 聽 | x
0_3 | 聽 | 聽 | 聽
1 | x | 聽 | 聽
1_0 | x | x | x
1_1 | x | x | x
1_2 | x | 聽 | x
1_3 | x | 聽 | 聽
2 | x | x | 聽
2_1 | x | x | x
2_2 | x | x | x
2_3 | x | x | 聽
2_4 | x | x | 聽
3 | x | x | x
3_0 | x | x | x
3_1 | x | x | x
3_2 | x | x | x
3_3 | x | x | x

Chears

Problem solved here [https://github.com/volkanceylan/Serenity/issues/932]
By the way, it solved mi The hide of the add button.
Many thanks again!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GitHubOrim picture GitHubOrim  路  3Comments

Amitloh picture Amitloh  路  3Comments

ahsansolution picture ahsansolution  路  3Comments

dudeman972 picture dudeman972  路  3Comments

Shraddha996 picture Shraddha996  路  3Comments