- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 08:19 AM
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.
Solved! Go to Solution.
- Labels:
-
Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 03:37 PM
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'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 07:05 PM
Hi Laurent,
Yep I have used exact same script.
Currently in our system any user can update any Knowledge Article. So we need to restrict that. But after Overriding the canWrite Method it is partially working. User is seeing the Edit button but not able to modify the Article as Fields became grayed Out. (This is happening correctly for those users whom we wanted to restrict.). Even after CanContribute method overridden also working in same way.
But the Problem I am facing is to hiding the Edit Button. Which is still displaying for the users for whom that should not be displayed.
For Example a user(ABC) is not a author/admin/CI Support group member but still he can see the edit button. But after hitting the edit button he can't update the Article, which is working perfectly. So we need to fix the display of edit button.
We are on Istanbul-patch-3 version
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2017 12:01 PM
Hi Laurent,
Any luck regarding this? Still I am struggling.
Thanks,
Arindam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2017 03:00 PM
I've took a look on a Helsinki instance and they did change the design inside Jakarta.
So inside Helsinki (don't know for sure for Istanbul), the UI macro kb_view_common defines showUpdateAction as new SNC.KnowledgeHelper(). This object does not use our overrided functions. So you should update the definition of the helper so it uses our overrided functions:
Replace:
var knowHelp = new SNC.KnowledgeHelper();
With:
var knowHelp = new KBCommon()._knowledgeHelper;
And when you upgrade to Jakarta you shoud be able to revert this UI Macro to OOTB.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 09:31 PM
Hi Laurent,
Thanks for your help. Its working as expected now.
But I have a question, Is there any way, we can avoid updating the OOB UI Macro?
Thanks,
Arindam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 03:49 AM
Not really as of Istanbul. Because the macro is calling a platfom class on which you have no control.
You could however create a new UI Macro with the same name to avoid modifying the OOTB one. Only the latest updated UI Macro will be used. Personnaly I prefer modifying the OOTB one as it allows me to review skipped upgrades after version upgrade and consider reverting to OOTB or merging. Doing a new UI Macro will not give you that review flag. Also the OOTB one might get updated and get precedence over your customized one as it will be more recently updated.