This is my first stackoverflow question, so please be careful. I am writing a client portal to the repository using MVC4, Entity Framework and SimpleMembership. The repository stores content for several companies. Each company has divisions and departments. Users will have different access to information for their company, departments and departments. I am looking for an elegant access control solution. So far, my model looks like this:
public class UserProfile { UserProfile() { this.AccessControl = new HashSet<AccessControl>(); } [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } public Nullable<int> CompanyId { get; set; } public virtual ICollection<AccessControl> { get; set; } public virtual Company Company { get; set; } } public class AccessControl { public int AccessControlId { get; set; } public int UserId { get; set; } public int CompanyId { get; set; } public Nullable<int> DivisionId { get; set; } public Nullable<int> DepartmentId { get; set; } public Boolean ReadAccess { get; set; } public Boolean WriteAccess { get; set; } // other properties for access control public virtual UserProfile UserProfile { get; set; } public virtual Company Company { get; set; } public virtual Division Division { get; set; } public virtual Department Department { get; set; } } public class Content { public int ContentId { get; set; } public int CompanyId { get; set; } public int DivisionId { get; set; } public int DepartmentId { get; set; } // Various other properties public virtual Company Company { get; set; } public virtual Division Division { get; set; } public virtual Department { get; set; } }
My thought was that a NULL department means all departments, and a NULL Department means all departments. My questions:
- What is an elegant way to write a repository method to retrieve a list of Content objects for a user based on their access control list, and populate the department and department selection lists in CRUD views?
- Is there a better way to simulate this access control list?
source share