I have created the following custom permission, to allow users to be able to add items to a Issue Tracking list, but without being able to edit, read, search them:-
$spweb=Get-SPWeb -Identity "Site URL";
$spRoleDefinition = New-Object Microsoft.SharePoint.SPRoleDefinition;
$spRoleDefinition.Name = "Submit only";
$spRoleDefinition.Description = "Can submit/add forms/files/items into library or list but cannot view/edit them.";
$spRoleDefinition.BasePermissions = "AddListItems, ViewPages, ViewFormPages, Open";
$spweb.RoleDefinitions.Add($spRoleDefinition);
$spweb.Dispose();
But users having this permission level are unable to create new item, and if they click on create item link , they will get the following message:-
"This site has not been shared with you" ?
Can anyone advice please? Thanks
EDIT
I have the following web part inside my visual studio :-
[ToolboxItemAttribute(false)]
public partial class VisualWebPart1 : WebPart
{
// Uncomment the following SecurityPermission attribute only when doing Performance Profiling using
// the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
// for production. Because the SecurityPermission attribute bypasses the security check for callers of
// your constructor, it's not recommended for production purposes.
// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
public VisualWebPart1()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPGroup group = web.Groups["Risk Issue Managers"];
bool isUser = web.IsCurrentUserMemberOfGroup(group.ID);
if (!isUser)
{
SPList myList = web.Lists.TryGetList("Risk & Issue Management");
SPField titleField = myList.Fields.GetField("Item Type");
titleField.Hidden = true;
titleField.ShowInEditForm = false;
titleField.ShowInNewForm = false;
titleField.ShowInDisplayForm = false;
titleField.Update();
SPField titleField2 = myList.Fields.GetField("Estimated Resolution Date");
titleField2.Hidden = true;
titleField2.ShowInEditForm = false;
titleField2.ShowInNewForm = false;
titleField2.ShowInDisplayForm = false;
titleField2.Update();
SPField titleField3 = myList.Fields.GetField("Project/s No");
titleField3.Hidden = true;
titleField3.ShowInEditForm = false;
titleField3.ShowInNewForm = false;
titleField3.ShowInDisplayForm = false;
titleField3.Update();
SPField titleField4 = myList.Fields.GetField("Current Status");
titleField4.Hidden = true;
titleField4.ShowInEditForm = false;
titleField4.ShowInNewForm = false;
titleField4.ShowInDisplayForm = false;
titleField4.Update();
SPField titleField5 = myList.Fields.GetField("Priority");
titleField5.Hidden = true;
titleField5.ShowInEditForm = false;
titleField5.ShowInNewForm = false;
titleField5.ShowInDisplayForm = false;
titleField5.Update();
SPField titleField6 = myList.Fields.GetField("Related Issues");
titleField6.Hidden = true;
titleField6.ShowInEditForm = false;
titleField6.ShowInNewForm = false;
titleField6.ShowInDisplayForm = false;
titleField6.Update();
myList.Update();
// web.AllowUnsafeUpdates = false;
}
else
{
SPList myList = web.Lists.TryGetList("Risk & Issue Management");
SPField titleField = myList.Fields.GetField("Item Type");
titleField.Hidden = false;
titleField.ShowInEditForm = true;
titleField.ShowInNewForm = true;
titleField.ShowInDisplayForm = true;
titleField.Update();
SPField titleField2 = myList.Fields.GetField("Estimated Resolution Date");
titleField2.Hidden = false;
titleField2.ShowInEditForm = true;
titleField2.ShowInNewForm = true;
titleField2.ShowInDisplayForm = true;
titleField2.Update();
SPField titleField3 = myList.Fields.GetField("Project/s No");
titleField3.Hidden = false;
titleField3.ShowInEditForm = true;
titleField3.ShowInNewForm = true;
titleField3.ShowInDisplayForm = true;
titleField3.Update();
SPField titleField4 = myList.Fields.GetField("Current Status");
titleField4.Hidden = false;
titleField4.ShowInEditForm = true;
titleField4.ShowInNewForm = true;
titleField4.ShowInDisplayForm = true;
titleField4.Update();
SPField titleField5 = myList.Fields.GetField("Priority");
titleField5.Hidden = false;
titleField5.ShowInEditForm = true;
titleField5.ShowInNewForm = true;
titleField5.ShowInDisplayForm = true;
titleField5.Update();
SPField titleField6 = myList.Fields.GetField("Related Issues");
titleField6.Hidden =false;
titleField6.ShowInEditForm = true;
titleField6.ShowInNewForm = true;
titleField6.ShowInDisplayForm = true;
titleField6.Update();
myList.Update();
// //web.AllowUnsafeUpdates = false;
}
web.AllowUnsafeUpdates = false;
}
});
}
protected void Page_Load(object sender, EventArgs e)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPGroup group = web.Groups["Risk Issue Managers"];
bool isUser = web.IsCurrentUserMemberOfGroup(group.ID);
if (!isUser)
{
SPList myList = web.Lists.TryGetList("Risk & Issue Management");
SPField titleField = myList.Fields.GetField("Item Type");
titleField.Hidden = true;
titleField.ShowInEditForm = false;
titleField.ShowInNewForm = false;
titleField.ShowInDisplayForm = false;
titleField.Update();
SPField titleField2 = myList.Fields.GetField("Estimated Resolution Date");
titleField2.Hidden = true;
titleField2.ShowInEditForm = false;
titleField2.ShowInNewForm = false;
titleField2.ShowInDisplayForm = false;
titleField2.Update();
SPField titleField3 = myList.Fields.GetField("Project/s No");
titleField3.Hidden = true;
titleField3.ShowInEditForm = false;
titleField3.ShowInNewForm = false;
titleField3.ShowInDisplayForm = false;
titleField3.Update();
SPField titleField4 = myList.Fields.GetField("Current Status");
titleField4.Hidden = true;
titleField4.ShowInEditForm = false;
titleField4.ShowInNewForm = false;
titleField4.ShowInDisplayForm = false;
titleField4.Update();
SPField titleField5 = myList.Fields.GetField("Priority");
titleField5.Hidden = true;
titleField5.ShowInEditForm = false;
titleField5.ShowInNewForm = false;
titleField5.ShowInDisplayForm = false;
titleField5.Update();
SPField titleField6 = myList.Fields.GetField("Related Issues");
titleField6.Hidden = true;
titleField6.ShowInEditForm = false;
titleField6.ShowInNewForm = false;
titleField6.ShowInDisplayForm = false;
titleField6.Update();
myList.Update();
// web.AllowUnsafeUpdates = false;
}
else
{
SPList myList = web.Lists.TryGetList("Risk & Issue Management");
SPField titleField = myList.Fields.GetField("Item Type");
titleField.Hidden = false;
titleField.ShowInEditForm = true;
titleField.ShowInNewForm = true;
titleField.ShowInDisplayForm = true;
titleField.Update();
SPField titleField2 = myList.Fields.GetField("Estimated Resolution Date");
titleField2.Hidden = false;
titleField2.ShowInEditForm = true;
titleField2.ShowInNewForm = true;
titleField2.ShowInDisplayForm = true;
titleField2.Update();
SPField titleField3 = myList.Fields.GetField("Project/s No");
titleField3.Hidden = false;
titleField3.ShowInEditForm = true;
titleField3.ShowInNewForm = true;
titleField3.ShowInDisplayForm = true;
titleField3.Update();
SPField titleField4 = myList.Fields.GetField("Current Status");
titleField4.Hidden = false;
titleField4.ShowInEditForm = true;
titleField4.ShowInNewForm = true;
titleField4.ShowInDisplayForm = true;
titleField4.Update();
SPField titleField5 = myList.Fields.GetField("Priority");
titleField5.Hidden = false;
titleField5.ShowInEditForm = true;
titleField5.ShowInNewForm = true;
titleField5.ShowInDisplayForm = true;
titleField5.Update();
SPField titleField6 = myList.Fields.GetField("Related Issues");
titleField6.Hidden = false;
titleField6.ShowInEditForm = true;
titleField6.ShowInNewForm = true;
titleField6.ShowInDisplayForm = true;
titleField6.Update();
myList.Update();
// //web.AllowUnsafeUpdates = false;
}
web.AllowUnsafeUpdates = false;
}
});
}
}
}
but i am facing these issues:-
- if a user inside the "Risk Issue Manager" group click on create , he will see all the fields, which will be fine.
- but if i remove him from the "Risk Issue Manager" group, then he can still see the fields !!, although inside the web part i mentioned to hide these fields ...
so can anyone advice what is causing this and how to solve it ? could this be related to caching problem? baring in mind that i am displaying the Create form inside a dialog box ? and when the web part is going to run ? each time the user click on Create button?