Ejemplo n.º 1
0
        private void CreateDefaultStructure()
        {
            using (var transaction = Database.BeginTransaction())
            {
                if (!Database.Query <Feed>().Any())
                {
                    var feed = new Feed(Guid.NewGuid());
                    feed.Name.Value[Language.English] = "Default Feed";
                    Database.Save(feed);

                    var group = new Group(Guid.NewGuid());
                    group.Name.Value[Language.English] = "Default Group";
                    group.Feed.Value = feed;
                    Database.Save(group);

                    var role = new Role(Guid.NewGuid());
                    role.Name.Value[Language.English] = "Default Role";
                    role.Group.Value = group;
                    Database.Save(role);

                    foreach (var masterRole in Database.Query <MasterRole>())
                    {
                        var roleAssingment = new RoleAssignment(Guid.NewGuid());
                        roleAssingment.Role.Value       = role;
                        roleAssingment.MasterRole.Value = masterRole;
                        Database.Save(roleAssingment);
                    }

                    AddPermission(role, SubjectAccess.SystemWide, PartAccess.CustomDefinitions, AccessRight.Write);
                    AddPermission(role, SubjectAccess.SystemWide, PartAccess.Structure, AccessRight.Write);
                    AddPermission(role, SubjectAccess.SystemWide, PartAccess.Contact, AccessRight.Write);
                    AddPermission(role, SubjectAccess.SystemWide, PartAccess.Subscription, AccessRight.Write);
                    AddPermission(role, SubjectAccess.SystemWide, PartAccess.RoleAssignments, AccessRight.Write);
                    AddPermission(role, SubjectAccess.SystemWide, PartAccess.TagAssignments, AccessRight.Write);
                    AddPermission(role, SubjectAccess.SystemWide, PartAccess.Demography, AccessRight.Write);
                    AddPermission(role, SubjectAccess.SystemWide, PartAccess.Documents, AccessRight.Write);
                    AddPermission(role, SubjectAccess.SystemWide, PartAccess.Mailings, AccessRight.Write);
                    AddPermission(role, SubjectAccess.SystemWide, PartAccess.Anonymous, AccessRight.Write);
                    AddPermission(role, SubjectAccess.SystemWide, PartAccess.Journal, AccessRight.Write);
                    AddPermission(role, SubjectAccess.SystemWide, PartAccess.Crypto, AccessRight.Write);
                }

                transaction.Commit();
            }
        }
Ejemplo n.º 2
0
 public RoleAssignmentListItemViewModel(Translator translator, RoleAssignment roleAssignment)
 {
     Id         = roleAssignment.Id.Value.ToString();
     MasterRole = roleAssignment.MasterRole.Value.Name.Value[translator.Language].EscapeHtml();
 }
Ejemplo n.º 3
0
        public RoleAssignmentModule()
        {
            this.RequiresAuthentication();

            Get["/roleassignment/{id}"] = parameters =>
            {
                string idString = parameters.id;
                var    role     = Database.Query <Role>(idString);

                if (role != null)
                {
                    if (HasAccess(role.Group.Value, PartAccess.RoleAssignments, AccessRight.Read))
                    {
                        return(View["View/roleAssignment.sshtml",
                                    new RoleAssignmentViewModel(Translator, CurrentSession, role)]);
                    }
                }

                return(null);
            };
            Get["/roleassignment/list/{id}"] = parameters =>
            {
                string idString = parameters.id;
                var    role     = Database.Query <Role>(idString);

                if (role != null)
                {
                    if (HasAccess(role.Group.Value, PartAccess.RoleAssignments, AccessRight.Read))
                    {
                        return(View["View/roleAssignmentlist.sshtml",
                                    new RoleAssignmentListViewModel(Translator, Database, CurrentSession, role)]);
                    }
                }

                return(null);
            };
            Get["/roleassignment/add/{id}"] = parameters =>
            {
                string idString = parameters.id;
                var    role     = Database.Query <Role>(idString);

                if (role != null)
                {
                    if (HasAccess(role.Group.Value, PartAccess.RoleAssignments, AccessRight.Write))
                    {
                        return(View["View/roleAssignmentedit_role.sshtml",
                                    new RoleAssignmentEditByRoleViewModel(Translator, Database, CurrentSession, role)]);
                    }
                }

                var contact = Database.Query <Contact>(idString);

                if (contact != null)
                {
                    if (HasAccess(contact, PartAccess.RoleAssignments, AccessRight.Write))
                    {
                        return(View["View/roleAssignmentedit_contact.sshtml",
                                    new RoleAssignmentEditByContactViewModel(Translator, Database, CurrentSession, contact)]);
                    }
                }

                return(null);
            };
            Post["/roleassignment/add/{id}"] = parameters =>
            {
                string idString = parameters.id;
                var    role     = Database.Query <Role>(idString);
                var    status   = CreateStatus();

                if (role != null)
                {
                    if (status.HasAccess(role.Group.Value, PartAccess.RoleAssignments, AccessRight.Write))
                    {
                        var model          = JsonConvert.DeserializeObject <RoleAssignmentEditByRoleViewModel>(ReadBody());
                        var roleAssignment = new RoleAssignment(Guid.NewGuid());
                        status.AssignObjectIdString("MasterRole", roleAssignment.MasterRole, model.MasterRole);
                        roleAssignment.Role.Value = role;

                        if (status.IsSuccess)
                        {
                            if (IsAssingmentPermitted(roleAssignment.Role.Value))
                            {
                                Database.Save(roleAssignment);
                                Global.Log.Notice("{0} added role assingment from {1} to {2}",
                                                  CurrentSession.User.UserName.Value,
                                                  roleAssignment.Role.Value.Name.Value[Translator.Language],
                                                  roleAssignment.MasterRole.Value.Name.Value[Translator.Language]);
                            }
                            else
                            {
                                status.SetErrorAccessDenied();
                            }
                        }
                    }
                }
                else
                {
                    var masterRole = Database.Query <MasterRole>(idString);

                    if (masterRole != null)
                    {
                        var model          = JsonConvert.DeserializeObject <RoleAssignmentEditByContactViewModel>(ReadBody());
                        var roleAssignment = new RoleAssignment(Guid.NewGuid());
                        status.AssignObjectIdString("Role", roleAssignment.Role, model.Role);
                        roleAssignment.MasterRole.Value = masterRole;

                        if (status.HasAccess(roleAssignment.Role.Value.Group.Value, PartAccess.RoleAssignments, AccessRight.Write))
                        {
                            if (status.IsSuccess)
                            {
                                if (IsAssingmentPermitted(roleAssignment.Role.Value))
                                {
                                    Database.Save(roleAssignment);
                                    Global.Log.Notice("{0} added role assingment from {1} to {2}",
                                                      CurrentSession.User.UserName.Value,
                                                      roleAssignment.Role.Value.Name.Value[Translator.Language],
                                                      roleAssignment.MasterRole.Value.Name.Value[Translator.Language]);
                                }
                                else
                                {
                                    status.SetErrorAccessDenied();
                                }
                            }
                        }
                    }
                    else
                    {
                        status.SetError("Error.Object.NotFound", "Error message when object not found", "Object not found.");
                    }
                }

                return(status.CreateJsonData());
            };
            Get["/roleassignment/delete/{id}"] = parameters =>
            {
                string idString       = parameters.id;
                var    roleAssignment = Database.Query <RoleAssignment>(idString);
                var    status         = CreateStatus();

                if (status.ObjectNotNull(roleAssignment))
                {
                    if (status.HasAccess(roleAssignment.Role.Value.Group.Value, PartAccess.RoleAssignments, AccessRight.Write))
                    {
                        if (IsAssingmentPermitted(roleAssignment.Role.Value))
                        {
                            Database.Delete(roleAssignment);
                            Global.Log.Notice("{0} removed role assingment from {1} to {2}",
                                              CurrentSession.User.UserName.Value,
                                              roleAssignment.Role.Value.Name.Value[Translator.Language],
                                              roleAssignment.MasterRole.Value.Name.Value[Translator.Language]);
                        }
                        else
                        {
                            status.SetErrorAccessDenied();
                        }
                    }
                }

                return(status.CreateJsonData());
            };
        }