public void Update(SPList list, SPListItem listItem, [Documentation(Name = "PermissionLevelIds", Type = typeof(string), Description = "Permission level id or ifs"), Documentation(Name = "GroupIds", Type = typeof(string), Description = "Group id or ids, separated by comma ','"), Documentation(Name = "UserNames", Type = typeof(string), Description = "User login name or names, separated by comma ','"), Documentation(Name = "IsGranted", Type = typeof(bool), Default = false, Description = "Not removes existing role assignments, when true")] IDictionary options) { var updateInfo = new AdditionalInfo(); Validate(updateInfo.Errors, list, listItem); if (!updateInfo.Errors.Any()) { var updateOptions = new PermissionsUpdateOptions(list.Id, listItem.ContentId) { CopyRoleAssignments = true, ClearSubscopes = true, Url = list.SPWebUrl }; if (options["PermissionLevelIds"] != null && !String.IsNullOrEmpty(options["PermissionLevelIds"].ToString())) { updateOptions.Levels = options["PermissionLevelIds"].ToString().Split(',').Select(int.Parse).ToArray(); } bool isGranted; if (options["IsGranted"] != null && !String.IsNullOrEmpty(options["IsGranted"].ToString()) && bool.TryParse(options["IsGranted"].ToString(), out isGranted)) { updateOptions.Overwrite = !isGranted; } if (options["GroupIds"] != null && !String.IsNullOrEmpty(options["GroupIds"].ToString())) { updateOptions.GroupIds = options["GroupIds"].ToString().Split(',').Select(int.Parse).ToArray(); } if (options["UserNames"] != null && !String.IsNullOrEmpty(options["UserNames"].ToString())) { updateOptions.LoginNames = options["UserNames"].ToString().Split(','); } try { ClientApi.Permissions.Update(updateOptions); } catch (SPInternalException ex) { updateInfo.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointPermissionsExtension.Translations.ListItemNotFound))); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the WidgetApi.V1.SharePointPermissions.Update() method for ContentId: {1} ListId: {2}. The exception message is: {3}", ex.GetType(), listItem.ContentId, list.Id, ex.Message); SPLog.UnKnownError(ex, message); updateInfo.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointPermissionsExtension.Translations.UnknownError))); } } }
public AdditionalInfo Update(Guid contentId, [Documentation(Name = "PermissionLevelIds", Type = typeof(string), Description = "Permission level id or ifs"), Documentation(Name = "GroupIds", Type = typeof(string), Description = "Group id or ids, separated by comma ','"), Documentation(Name = "UserNames", Type = typeof(string), Description = "User login name or names, separated by comma ','"), Documentation(Name = "IsGranted", Type = typeof(bool), Default = false, Description = "Not removes existing role assignments, when true")] IDictionary options) { var updateOptions = new PermissionsUpdateOptions(EnsureListId(contentId), contentId) { CopyRoleAssignments = true, ClearSubscopes = true }; if (options["PermissionLevelIds"] != null && !String.IsNullOrEmpty(options["PermissionLevelIds"].ToString())) { updateOptions.Levels = options["PermissionLevelIds"].ToString().Split(',').Select(int.Parse).ToArray(); } bool isGranted; if (options["IsGranted"] != null && !String.IsNullOrEmpty(options["IsGranted"].ToString()) && bool.TryParse(options["IsGranted"].ToString(), out isGranted)) { updateOptions.Overwrite = !isGranted; } if (options["GroupIds"] != null && !String.IsNullOrEmpty(options["GroupIds"].ToString())) { updateOptions.GroupIds = options["GroupIds"].ToString().Split(',').Select(int.Parse).ToArray(); } if (options["UserNames"] != null && !String.IsNullOrEmpty(options["UserNames"].ToString())) { updateOptions.LoginNames = options["UserNames"].ToString().Split(','); } try { ClientApi.Permissions.Update(updateOptions); return(new AdditionalInfo()); } catch (SPInternalException ex) { return(new AdditionalInfo(GetItemNotFoundError(ex))); } catch (Exception ex) { SPLog.UnKnownError(ex, string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointPermissions.Update() method for ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message)); return(new AdditionalInfo(GetUnknownError(ex))); } }