• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Disable <ma-switch

    How-To
    3
    6
    1.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      Phillip Weeks
      last edited by

      Is there a way I can enable or disable a <ma-switch control using an expression such as user permission

      1 Reply Last reply Reply Quote 0
      • ThomasEinastoT
        ThomasEinasto
        last edited by ThomasEinasto

        Sure there is, look in the forums and you have a lot of information based on what object has permissions variable. i.e
        one can use User.current variable to see what user has been logged in and its options.

        Example:

        {"username":"admin","email":"admin@admin.net","oldHashAlgorithm":false,"grantedPermissions":["excelReports.fileStoreWritePermission","graphical.view.addView","internal.status","action.purgeAllPointValues","SNMP_MIB_STORE_READ","alarms.view","reports.view","graphical.view.upload","filestore.user.create","permissionDatasource","action.log4jUtil","excelreports.view","legacypointdetails.view","graphical.view","filestore.docs.read","dataFileDataSourceREST","watchlist.view","haystack.server","action.noSqlBackup","action.noSqlRestore","mailingLists.create","action.purgeAllEvents","datapointdetails.view","users.view","action.purgeUsingSettings","action.sqlRestore","action.excelReportPurge","SNMP_MIB_STORE_WRITE","filestore.docs.write","filestore.public.write","pointlinks.view","action.configurationBackup","action.reloadLinks","dataImport.view","filestore.core.read","action.reportPurge","permissions.user.editSelf","jsonData.create","permissions.superadmin","filestore.core.write","action.sqlBackup","excelReports.fileStoreReadPermission"],"sessionExpirationOverride":false,"sessionExpirationPeriod":null,"lastLogin":"2019-09-26T17:10:17.653+03:00","lastPasswordChange":"2019-04-17T11:15:25.795+03:00","validationMessages":null,"password":"","phone":"","disabled":false,"homeUrl":"/ui/administration/home","receiveAlarmEmails":"IGNORE","timezone":"","systemTimezone":"Europe/Tallinn","admin":true,"receiveOwnAuditEvents":false,"systemLocale":"en-US","passwordLocked":false,"muted":true,"id":1,"permissions":"superadmin","locale":"","name":"Administrator","originalId":"admin"}
        

        You can see that it has permissions variable. You can use this with ng-disabled directive of an md-switch to something like this

        <md-switch ng-disabled="User.current.permissions !== 'superadmin'" ng-model="myPoint.valueFn" ng-model-options="{getterSetter:true}"></md-switch>
        

        This switch is disabled if user does not have superadmin permissions. One can also leverage the ID of an user and use it like this so that you would not have to explicitly set the permissions to your required user.

        Cheers,
        Thomas

        1 Reply Last reply Reply Quote 1
        • Jared WiltshireJ
          Jared Wiltshire
          last edited by Jared Wiltshire

          Thanks @ThomasEinasto , very close.

          I would suggest something more akin to this (as of Mango 3.6.x)

          ng-disabled="!User.current.hasAnyRole('superadmin')"
          

          This will work even if the user has multiple roles assigned.

          Developer at Radix IoT

          1 Reply Last reply Reply Quote 0
          • ThomasEinastoT
            ThomasEinasto
            last edited by

            I wanted to copy this response from years ago by you which I found by search but as Mango has changed over the years this was not working anymore.

            @jared-wiltshire said in User permissions to view pages:

            @shaun
            Phillip's post contains a lot of useful information. As he has indicated the best way to restrict users from seeing data they should not be seeing is to set the permissions on the data points and on the JSON store objects.

            However it is also very useful to hide certain navigation links inside your app so your users can't navigate to a page that they will not be able to access any data on. This can be done for menu items by adding a permission property to an object in the MENU_ITEMS array. If you need to hide something in the content of your page you can add a ng-show or ng-if directive, e.g. ng-show="user.hasPermission('superadmin')"

            But as Mango has changed over the years this function was not working anymore :), hence why I tried to provide the best solution I could leverage.

            Jared WiltshireJ 1 Reply Last reply Reply Quote 1
            • Jared WiltshireJ
              Jared Wiltshire @ThomasEinasto
              last edited by

              @thomaseinasto said in Disable <ma-switch:

              But as Mango has changed over the years this function was not working anymore :), hence why I tried to provide the best solution I could leverage.

              Honestly I appreciate it.

              hasPermission() should still work but is deprecated and will print a warning to the console.

              Developer at Radix IoT

              1 Reply Last reply Reply Quote 0
              • P
                Phillip Weeks
                last edited by

                Thank-you guys .. lots of useful info :)

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post