|
const string groupName = "CandidateSigned"; |
|
|
|
// Creates group |
|
public static void CreateCandidateSignedPermissionGroup(SPWeb web, string groupName, string groupDescription) |
|
{ |
|
SPUserCollection users = web.AllUsers; |
|
SPUser owner = web.SiteAdministrators[0]; |
|
SPMember member = web.SiteAdministrators[0]; |
|
SPGroupCollection groups = web.Groups; |
|
groups.Add(groupName, member, owner, groupDescription); |
|
SPGroup newSPGroup = groups[groupName]; |
|
SPRoleDefinition role = web.RoleDefinitions.GetByType(SPRoleType.Administrator); |
|
SPRoleAssignment roleAssignment = new SPRoleAssignment(newSPGroup); |
|
roleAssignment.RoleDefinitionBindings.Add(role); |
|
web.RoleAssignments.Add(roleAssignment); |
|
web.Update(); |
|
} |
|
|
|
// Deletes group |
|
public static void DeleteCandidateSignedPermissionGroup(SPWeb web, string groupName) |
|
{ |
|
SPGroupCollection groups = web.SiteGroups; |
|
groups.Remove(groupName); |
|
web.Update(); |
|
} |
|
|
|
|
|
// Uncomment the method below to handle the event raised after a feature has been activated. |
|
|
|
public override void FeatureActivated(SPFeatureReceiverProperties properties) |
|
{ |
|
string groupDescription = "Games Lab verified users"; |
|
try |
|
{ |
|
using (SPWeb web = properties.Feature.Parent as SPWeb) |
|
{ |
|
SPRoleDefinition permissionLevel = web.RoleDefinitions.GetByType(SPRoleType.Contributor); |
|
CreateCandidateSignedPermissionGroup(web, groupName, groupDescription); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
//ex.Message; |
|
} |
|
} |
|
|
|
|
|
// Uncomment the method below to handle the event raised before a feature is deactivated. |
|
|
|
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) |
|
{ |
|
try |
|
{ |
|
using (SPWeb web = properties.Feature.Parent as SPWeb) |
|
{ |
|
DeleteCandidateSignedPermissionGroup(web, groupName); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
|
|
} |
|
} |