I have created a piece of code which will check if your on addanapp.aspx page and if so it will read your permissions on a list and if you have EditList perms it shows 'Custom List' app only on add an app page, and if you dont have EditList perms it shows 'Mailbox' app only on add an app page. This works fine in internet explorer but it does not work in Chrome. In Chrome it will show the alert the user you doesnt have edit permisisons and then it will give the user the apps that you have if you had edit permissions. I cannot seem to figure out why its doing this but its good on INTERNET EXPLORER. I know this is a big post but most would be aweseome.
Here is the code.
<script type="text/javascript">
if (window.location.href.indexOf("addanapp.aspx") > -1) {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
getCurrentUserPermission('backfoot');
});
}
function getCurrentUserPermission(listName)
{
var web,clientContext,currentUser,list;
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
currentUser = web.get_currentUser();
list = web.get_lists().getByTitle(listName);
clientContext.load(list,'EffectiveBasePermissions');
clientContext.load(currentUser);
clientContext.load(web);
clientContext.executeQueryAsync(function(){
if (list.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems)){
alert("user has edit permission");
CGAlterStorefront();
}else{
alert("user doesn't have edit permission");
CGAlterStorefrontZeroAccess()
}
}, function(sender, args){
console.log('request failed ' + args.get_message() + '\n'+ args.get_stackTrace());
});
}
function CGAlterStorefront() {
if (SP.Storefront != undefined) {
var listedApps = SP.Storefront.StorefrontApp.get_currentView();
if (listedApps == undefined || listedApps.$2b_3 == null || listedApps.$M_3 == null) { setTimeout(CGAlterStorefront, 300); return; }
listedApps.spProxy.add_getAppsCompleted(CGRefreshUI);
CGRefreshUI();
}
}
function CGAlterStorefrontZeroAccess() {
if (SP.Storefront != undefined) {
var listedApps = SP.Storefront.StorefrontApp.get_currentView();
if (listedApps == undefined || listedApps.$2b_3 == null || listedApps.$M_3 == null) { setTimeout(CGAlterStorefront, 300); return; }
listedApps.spProxy.add_getAppsCompleted(CGRefreshUI);
CGRefreshUIZeroAccess();
}
}
function CGRefreshUI() {
var listedApps = SP.Storefront.StorefrontApp.get_currentView();
//remove Noteworthy
listedApps.$2b_3.length = 0;
//remove all except List templates starting with 'CG_'
for (var i = listedApps.$M_3.length-1; i--;) {
if (listedApps.$M_3[i].$2R_0.Title.indexOf("Custom List") < 0 ) {
listedApps.$M_3.splice(i, 1);
}
}
SP.Storefront.StorefrontApp.get_currentView().updateUI();
}
function CGRefreshUIZeroAccess() {
var listedApps = SP.Storefront.StorefrontApp.get_currentView();
//remove Noteworthy
listedApps.$2b_3.length = 0;
//remove all except List templates starting with 'CG_'
for (var i = listedApps.$M_3.length-1; i--;) {
if (listedApps.$M_3[i].$2R_0.Title.indexOf("Mailbox") < 0 ) {
listedApps.$M_3.splice(i, 1);
}
}
SP.Storefront.StorefrontApp.get_currentView().updateUI();
}
</script>