Permissions: Hide/Show List Items in Dropdown | Community
Skip to main content
October 16, 2015
Solved

Permissions: Hide/Show List Items in Dropdown

  • October 16, 2015
  • 8 replies
  • 1664 views

I have a component and I would like to use a dropdown menu. However, I want to hide certain options for the Author user group.

Admin should see:

  • Brown 
  • Yellow
  • Purple
  • Blue

But an author should only see:

  • Brown
  • Yellow

How can I incorporate the access controls at the script level for a specific tab inside a component?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by PaulMcMahon

Take a look at /libs/cq/personalization/components/traits/percentile for an example of a dynamically generated  selection list. The dialog sets the options property of the select widget to be $PATH.options.json. There is a JSP that is responsible for generating the select options - /libs/cq/personalization/components/traits/percentile/options.json.jsp. So in your case your JSP would check the user's group membership and return the correct JSON based on the group membership. You could also use a OSGI Sling servlet instead of a JSP if desired. 

8 replies

Sham_HC
Level 10
October 16, 2015

It deponds where you are retrieving the drop down options. If the options are generating Or hard coded Or coming from external system. Then the servlet rendering the dropdown list in cq should implement the logic based on the user member to output right option.

October 16, 2015

The list options would be hardcoded. When the user makes their selection and presses OK in the component to Save, the associated action would take place. Example - Author user selects Yellow from the list (could also use radio buttons). When Author clicks Yes, the background of the header turns yellow.

PaulMcMahonAccepted solution
Level 8
October 16, 2015

Take a look at /libs/cq/personalization/components/traits/percentile for an example of a dynamically generated  selection list. The dialog sets the options property of the select widget to be $PATH.options.json. There is a JSP that is responsible for generating the select options - /libs/cq/personalization/components/traits/percentile/options.json.jsp. So in your case your JSP would check the user's group membership and return the correct JSON based on the group membership. You could also use a OSGI Sling servlet instead of a JSP if desired. 

October 16, 2015

I don't seem to have the percentile folder under traits. Can you paste the code or is there another example?

Sham_HC
Level 10
October 16, 2015

which version of aem you are using?

October 16, 2015

My apologies, I'm using CQ5. (CRXDE Lite 2.3.15).

Level 8
October 16, 2015

I think the question was 5.5 or 5.6. 

At the core what you need is code that will generate a JSON response in this format:

[
     {"value":"0-10","text":"0% - 10%"},
     {"value":"10-20","text":"10% - 20%"},
     {"value":"20-30","text":"20% - 30%"},
     {"value":"30-40","text":"30% - 40%"},
     {"value":"40-50","text":"40% - 50%"},
     {"value":"50-60","text":"50% - 60%"},
     {"value":"60-70","text":"60% - 70%"},
     {"value":"70-80","text":"70% - 80%"},
     {"value":"80-90","text":"80% - 90%"},
     {"value":"90-100","text":"90% - 100%"}
]

You can do that with either a JSP or a Servlet. Doing a selector based JSP (like putting a JSP named options.json.jsp under your component is the simplest way to accomplish this. 

Then you set your options property on your select widget to be $PATH.options.json.  

October 16, 2015

( I'm using Version 5.5 )

Ok. I'm just a beginner so some of this seems foreign but I think I have enough to play around with.

Any additional comments/alternative solutions are welcome!

I'll leave this item "open" for a few days while I try to work through it.