0

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?

  • are you able to access url/_layouts/settings.aspx link? – Hardik Kothari Sep 30 '14 at 13:19
  • yes i can see this – john Gu Sep 30 '14 at 13:29
  • try copying the the base permissions for "Contribute" role and remove "EditListItems" and "DeleteListItems" from it. – Unnie Sep 30 '14 at 15:40
  • what will this do ? i mean what is the difference from my approach ? – john Gu Sep 30 '14 at 15:53
  • also contributors will be able to read item and view list views such as "My submission view" & "Approve/reject" view.. which in my case i want to avoid ... so seems coping from contributor is too much in my case.. – john Gu Sep 30 '14 at 15:54
1

try the below solution:

  1. Go to Central Admin. Click on the “Application Management” heading.

  2. Click on “Manage services on server”.

  3. Stop the service “Microsoft SharePoint Foundation Web Application”. This will take a little while to stop.

  4. Start the above service again.

This should resolve the problem.

  • why do i need to do so ? – john Gu Sep 30 '14 at 13:40
  • it keeps showing stopping , and i am unable to start it agian ? – john Gu Sep 30 '14 at 13:49
  • so there is some problm there in the configuration. if its not starting try IIS reset or restart the machine – Hardik Kothari Sep 30 '14 at 13:51
  • 1
    i don't think so. – Hardik Kothari Sep 30 '14 at 14:54
  • 1
    just let me check will update you – Hardik Kothari Sep 30 '14 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.