Display field only for admin

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yberges
    Senior Member
    • Jul 2022
    • 174

    Display field only for admin

    hello i see we can display a filed only for assigned user but it possible to allow display only for admin group ? and how ?
    regards
  • victor
    Active Community Member
    • Aug 2022
    • 727

    #2
    Hi yberges,

    Go to Administration -> Entity Manager -> Your_Entity_Name -> Fields -> YOUR_FIELDNAME -> Conditions making field visiblepress -> Edit and select a condition. For example, to make this field visible when Team = Top Management, or Role = Admin. Of course, before that, the field must be displayed on the desired Layout.
    Attached Files
    Last edited by victor; 12-12-2022, 07:15 PM.

    Comment

    • rabii
      Active Community Member
      • Jun 2016
      • 1250

      #3
      You can't select a condition like (role=admin) that is not available. you can only set an assigneduser e.g (assignedUser=admin). otherwsie is to create a custom view for your entity and there you can check if the user isAdmin then show the field otherwise hide the file. see example code below:

      Code:
      define('custom:views/your-entity-type/record/detail', ['views/record/detail'], function (Dep) {
        return Dep.extend({
           setup: function () {
                   Dep.prototype.setup.call(this);
                   this.showField('name');
           },
          afterRender: function () {
                  Dep.prototype.afterRender.call(this);
      
                  if (!this.getUser().isAdmin()) {
                     this.hideField('name');
                 }
          },
       });
      });
      Rabii
      Web Dev

      Comment

      • yberges
        Senior Member
        • Jul 2022
        • 174

        #4
        victori try it but doesn't work field is aleady hidden ...
        => maybe adding css style depend of user ?

        Comment

        • yuri
          Member
          • Mar 2014
          • 8440

          #5
          You can define a field as adminOnly in metadata > entityAcl: https://docs.espocrm.com/development...ta/entity-acl/
          If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

          Comment

          • yberges
            Senior Member
            • Jul 2022
            • 174

            #6
            in custom/resources/metadata i didn't have entiAcl folder i need to create it and add my file ?

            Comment

            • yberges
              Senior Member
              • Jul 2022
              • 174

              #7
              yuri can you explain more about this intégration ?

              Comment

              • rabii
                Active Community Member
                • Jun 2016
                • 1250

                #8
                yberges

                Yes you need to create this new folder if not exist, do these steps:

                Create a new folder under custom\Espo\Custom\Resources\metadata\entityAcl\yo u_entity.json

                Code:
                {
                    "fields": {
                         "yourField":
                               { "adminOnly": true }
                    },
                   "links": {
                         "yourLink":
                              { "nonAdminReadOnly": true }
                    }
                }
                This should do the job.
                Rabii
                Web Dev

                Comment

                • yberges
                  Senior Member
                  • Jul 2022
                  • 174

                  #9
                  ok cool thanks !

                  Comment

                  • Jakub Grufik
                    Senior Member
                    • Aug 2022
                    • 361

                    #10
                    I am just guessing but you can try - Administration->Entity->Field->Condition making field visible-> env\userAttribute('type') == 'admin'

                    Comment


                    • Jakub Grufik
                      Jakub Grufik commented
                      Editing a comment
                      damn I just noticed that you are not able to use formula in this type of condition
                  • yberges
                    Senior Member
                    • Jul 2022
                    • 174

                    #11
                    thanks for sharing solution

                    Comment

                    • yberges
                      Senior Member
                      • Jul 2022
                      • 174

                      #12
                      hello i try it but strange that doesn't works
                      my entity name Etablisssement
                      url : /custom/Espo/Custom/Resources/metadata/entityAcl/Etablissement.json
                      this is my code
                      Code:
                      {
                          "fields": {
                               "informationsPourLeBadge":
                                     { "adminOnly": true },
                               "codecomptable":
                                     { "adminOnly": true }
                            }
                       }​
                      but user (basic) can add a a value in codecomptable field when he create an entity in small panel (edit)
                      regards

                      Comment

                      • yuri
                        Member
                        • Mar 2014
                        • 8440

                        #13
                        This is back-end only. It won't hide the field in the frontend. You can utilize a dynamic logic to hide the field from frontend.
                        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

                        Comment

                        • radek
                          Junior Member
                          • Feb 2024
                          • 8

                          #14
                          There is another simpler solution.

                          While yes you can use dynamic logic to hide the field depending on team this will actually not hide it from API.

                          Assuming your goal is that only admin/specific role can see the field you can go to:

                          Administration > Roles > Select/create role for non admin user > scroll down to field scopes > select entity and click the (+) > select field you want to make admin only > set read to no

                          Any user with this role will not be able to see the field, while admin user (or other Roles where read=yes) will be able to see it.

                          Disallowing read will also automatically hide the field from layout so you do not need to set additional dynamic logic.

                          Comment

                          • yberges
                            Senior Member
                            • Jul 2022
                            • 174

                            #15
                            radek 1000 thanks ! solved

                            Comment

                            Working...