3 Replies Latest reply on Mar 4, 2010 11:28 AM by kminKeller-si5I0P

    Display buttons based on some role


      I have user log into the app with some roles ex admin, user, manager etc. When they login, they come to a list page. there on the top of the page there is a button which will take to a report page. when you click on that button will take you to the report page where I have several buttons to run reports. Now I need to restrict user to view some buttons. example, admin can view all the buttons and run them. manager can run only some report and so does users. how can i do this easy way?


      Any sample, suggestion or help is appreciated.

        • 1. Re: Display buttons based on some role
          Gregory Lafrance Level 6

          You could create a roles object that is basically an associative array, with the keys being the role name and the value being a number, like 1, 2, 3, 4, 5.


          Then test their access using the roles object using their role name, and only show that area of the UI if the value is >= the required number for that area of the UI.


          If this post answers your question or helps, please mark it as such.

          Greg Lafrance - Flex 2 and 3 ACE certified


          Flex / AIR Development, Training, and Support Services

          • 2. Re: Display buttons based on some role
            Ansury Level 3

            Lots of ways you could do this, depending on your exact requirements.


            You could set visible/includeInLayout individually on each button via the same bindings method.  The bindings could take the form of a long (and ugly) string of OR conditionals within the mxml tag attributes, or it could be a variable set to true or false via some actionscript function triggered by an event such as show().


            You could try looking into http://www.gorillalogic.com/chimp which says it allows you to set client permissions via metadata.  (I don't use this yet so I've no idea how it is, but it looks nice.)  I'd recommend at least looking into this if there is any level of complexity to your app - for a simple application, you can get away with doing this stuff manually pretty easy too so it might be easier.  Chimp looks pretty nice though, it reminds me of the Swiz flex framework (same principles), which is great.

            • 3. Re: Display buttons based on some role
              kminKeller-si5I0P Level 1

              Thanks for the reply guys.


              I am trying to do visible and includeLayout = {model.isAdmin}. But the issue is when should I actually trigger this assignment when I click on the reports button.


              Maybe I am not understanding something. I need to verify this when the reports page loads up. But CreationComplete or initialize happens even before those you log in. Please help me understand. Thanks.