Announcement

Collapse
No announcement yet.

Display field only for admin

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #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


    • #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');
                 }
          },
       });
      });

      Comment


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

        Comment


        • #5
          You can define a field as adminOnly in metadata > entityAcl: https://docs.espocrm.com/development...ta/entity-acl/

          Comment


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

            Comment


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

              Comment


              • #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.

                Comment


                • #9
                  ok cool thanks !

                  Comment


                  • #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

                  • #11
                    thanks for sharing solution

                    Comment


                    • #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


                      • #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.

                        Comment


                        • #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


                          • #15
                            radek 1000 thanks ! solved

                            Comment

                            Working...
                            X