Name
sn_smd.SMSecurityProfilesAction
Description
No description available
Script
var SMSecurityProfilesAction = Class.create();
SMSecurityProfilesAction.prototype = Object.extendsObject(SMBaseAction, {
doAction: function(params) {
try {
if (!(params.object_id && params.context && params.operation)) {
throw SMErrorHelper.createScriptAPIError(
gs.getMessage("Illegal parameter"),
"SMSecurityProfilesAction.doAction: Undefined object id, object context, and/or operation on security profiles",
null
);
}
var manager = new SMSecurityManager(params.context, params.object_id);
return this._doOperation(manager, params.operation, params.exclude_profiles_from);
} catch(error) {
throw SMErrorHelper.createScriptAPIError(
gs.getMessage("Unable to load profiles"),
"SMSecurityProfilesAction.doAction: profile loading failed",
error
);
}
},
_doOperation: function(manager, operation, excludedProfilesTable) {
var result = {};
var i;
switch(operation) {
case 'share':
var excludedProfiles = [];
if(excludedProfilesTable) {
var gr = new GlideRecord(excludedProfilesTable);
if(gr.isValid()) {
gr.addQuery('context', manager.context);
gr.query();
while(gr.next()) {
excludedProfiles.push(gr.profile+'');
}
}
}
result.profiles = manager.allProfiles();
for(i = 0; i < excludedProfiles.length; i++) {
for(var j = 0; j <= result.profiles.length; j++) {
if(excludedProfiles[i] == result.profiles[j].id) {
result.profiles.splice(j, 1);
break;
}
}
}
return result;
case 'participate':
result.profiles = [];
result.memberships = manager.profileMemberships();
var profiles = manager.activeProfiles();
for(i = 0; i < profiles.length; i++) {
var id = profiles[i].id;
if(result.memberships[id] && result.memberships[id].length) {
result.profiles.push(profiles[i]);
}
}
return result;
default:
throw SMErrorHelper.createScriptAPIError(
gs.getMessage("Unsupported operation on security profiles"),
"SMSecurityProfilesAction._doOperation: Unsupported operation on security profiles",
null
);
}
},
type: 'SMSecurityProfilesAction'
});
Sys ID
a6758f43c3731200e2ddb59af3d3ae26