I got a requirement to adjust the visibility of the "Edit" button on Knowledge articles

Arindam Ghosh
Mega Guru

Detail requirement is as below:

The "Edit" button in a knowledge article should only be available to those users, who:

a. Are the author of the respective Knowledge article, OR

b. Are part of the Assignment Group of the Configuration Item used for creating the Knowledge article

----------------------------------------------------------------------------------

While analyzing this I found that in "kb_view_common_header_toolbar" UI Macro the below condition is coded for 'Edit' button.

<j:if test="${showUpdateAction}">

<button id="editArticle" title="${gs.getMessage('Edit content')}" class="btn btn-default navbar-btn snc-article-header-toolbar-button">${gs.getMessage("Edit")}</button>

</j:if>

Here variable showUpdateAction is being set in another UI Macro "kb_view_common"

After that I am lost. Not exactly able to understand how and where the conditions are written and how can I modify to implement my requirements.

Any help is greatly appreciated. Thanks in advance.

1 ACCEPTED SOLUTION

Your question got me to rethink my answer.



I tought instead of doing all these scripts override which are global and override OOTB stuff, you can simply create a scripted user criteria and apply it as the only user criteria for the required knowledge bases. However, these user criteria are somehow cached in the user session, so for example: a user is the author of an article, he changes the author to someone else so that he should no longer have write access, however he keeps the write access because of a weird caching with user criteria. I conclude that user criteria should not be used to be dynamic with the record.



However, your point about the canContribute method is good, you could in fact make this simpler by overriding the canContribute method that is defined in KBCommon. And remove the previous overriding I proposed:



var KBCommon = Class.create();


KBCommon.prototype = Object.extendsObject(KBCommonSNC, {


      initialize: function(){


              this._knowledgeHelper = new SNC.KnowledgeHelper();


              this._knowledgeHelper.canContribute = function(knowledgeGR){


                      var defaultContribute = new SNC.KnowledgeHelper().canContribute(knowledgeGR);


                      if(!defaultContribute){


                              return false;


                      }


                     


                      var isAdmin = gs.hasRole('admin');


                      if(isAdmin){


                              return true;


                      }


                     


                      var isKnowledgeBase = knowledgeGR.getRecordClassName() == 'kb_knowledge_base';


                      if(isKnowledgeBase){


                              return true;


                      }


                     


                      var isAuthor = knowledgeGR.author == gs.getUserID();


                      if(isAuthor){


                              return true;


                      }


                     


                      var isMemberOfCIGroup = gs.getUser().isMemberOf(knowledgeGR.cmdb_ci.support_group);


                      if(isMemberOfCIGroup){


                              return true;


                      }


                     


                      return false;


              };


      },


     


      type: 'KBCommon'


});


View solution in original post

25 REPLIES 25

VaranAwesomenow
Mega Sage

Dear Arindam,



Can you try to control the ability to edit an article using the 'can contribute' option on the knowledgebase, it has a script block which should allow us to implement complex logic.



find_real_file.png



Thanks


Anil


Hello Anil,



Thanks for your quick response. But here we need to restrict the display of edit button of "Knowledge article" not "Knowledge Base". Below is a quick screenshot:



        Knowledge Article.png


LaurentChicoine
Tera Guru

Hi Arindam,



Do you want to prevent others from modifying the article (then you should look at ACL) or are you really simple trying to hide the Edit button? If you simply hide the button that means that you allow users to edit the article when the users are in the normal platform (knowledge.do page).


Hi Laurent,



My goal is to prevent editing of the other that the mentioned users (Authors/Member of CI assignment Group).



As per my understanding, We need to implement the ACL and as well as need to hide the 'Edit' button conditionally.    



Thanks,


Arindam