Custom Form Permissions

Topics: Customizing Orchard
Sep 24, 2013 at 5:03 PM
Edited Sep 24, 2013 at 5:03 PM
My site has several forms for different user types, and I would like a way for the forms' stakeholders to access their form (and the submissions therein) and not other forms.

I've created a different content type for each form, created different users and specified their roles to each form, and also Enabled Content Item access control to each form.

However, the "Manage custom forms" permission under the "Orchard.CustomForms Feature" section when editing the User's Role seems to be an all-or-nothing. Allowing the user this privilege makes either all the Forms visible on the left-side admin panel, or none.

Is there a way to parse these out in the Permissions.cs file so it's form specific?
Coordinator
Sep 24, 2013 at 5:15 PM
Enable content item permissions.
Sep 24, 2013 at 5:49 PM
I see now.

I didnt want the different forms to even appear under the forms section, but turns out the non-stakeholder cant do much with the submissions beyond viewing them, which is an acceptable compromise.

Thanks Bertrand!
Sep 24, 2013 at 6:02 PM
Edited Sep 24, 2013 at 6:07 PM
Apologies for rephrasing this, or if it should be it's own thread, but how then does one allow 'Editor' role to access the Oform module?

I ask because the Custom Form module is great, but there is no ability for user to upload files (mainly pdf applications) to our database, which is a big purpose of the site. And I honestly dont know enough coding to build that feature.

I've created a Permissions.CS and edited the Admin Menu.CS that are identical to what this user posted 1.5 years ago (https://orchard.codeplex.com/discussions/349739), and similar to other module's Permissions.cs files, but the module's permissions do not appear in the Edit Role page. I've emailed the developers and received no response.

Anyone who's figured this out, please let me know!!!
Coordinator
Sep 24, 2013 at 6:53 PM
If the permissions don't appear in the roles editor, then somehow your code is not loading. Did you enable the feature where you defined those permissions?
Sep 24, 2013 at 7:13 PM
Hmm probably not.

Where exactly would I enable that?
Coordinator
Sep 24, 2013 at 7:24 PM
Under Modules
Sep 24, 2013 at 7:31 PM
Edited Sep 24, 2013 at 7:32 PM
Oh, yes, Orchard.ContentPermissions - Version: 1.6 is enabled; which is how I was able to enable Permissions with Custom Forms module.

Here's the code on the oForm Permissions.cs:
using System.Collections.Generic;
using Orchard.Environment.Extensions.Models;
using Orchard.Security.Permissions;

namespace oforms {
    public class Permissions : IPermissionProvider {
        public static readonly Permission Manageoforms = new Permission { Description = "Manage oforms", Name = "Manageoforms" };

        public virtual Feature Feature { get; set; }

        public IEnumerable<Permission> GetPermissions() {
            return new[] {
                Manageoforms,
            };
        }

        public IEnumerable<PermissionStereotype> GetDefaultStereotypes() {
            return new[] {
                new PermissionStereotype {
                    Name = "Administrator",
                    Permissions = new[] {Manageoforms}
                },
                new PermissionStereotype {
                    Name = "Editor",
                    Permissions = new[] {Manageoforms}
                },
                new PermissionStereotype {
                    Name = "Moderator",
                    Permissions = new[] {Manageoforms}
                },
                new PermissionStereotype {
                    Name = "Author",
                },
                new PermissionStereotype {
                    Name = "Contributor",
                },
            };
        }

    }
}
And the Admin Menu.cs
using Orchard.Localization;
using Orchard.Security;
using Orchard.UI.Navigation;

namespace Orchard.CustomForms {
    public class AdminMenu : INavigationProvider {
        public Localizer T { get; set; }
        public string MenuName { get { return "admin"; } }

        public void GetNavigation(NavigationBuilder builder) {
            builder.Add(T("Forms"), "4",
                menu => menu
                    .Add(T("Manage Forms"), "1.0",
                        item => item.Action("Index", "Admin", new { area = "Orchard.CustomForms" }).Permission(Permissions.ManageForms))
            );
        }
    }
}
Is something a bit off somewhere in the code?
Coordinator
Sep 24, 2013 at 7:48 PM
No, I meant enable your module, the one where you wrote your permissions.cs.
Sep 24, 2013 at 7:54 PM
I didn't create a module. As I previously said, I created a Permissions file and added it to the existing oforms module
Coordinator
Sep 25, 2013 at 12:07 AM
Don't do that.