private void btn_rmRolePermission_Save_Click(object sender, EventArgs e) { Program.ExitCode status = Program.ExitCode.Success; if (cb_Permission.Text == "") { MessageBox.Show(this, "Выберите Роль и Permission, которые хотите удалить!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //Создать RolePermission: RolePermission rp = new RolePermission { Role_Id = Convert.ToInt32(cb_Role.SelectedValue), Permission_Id = Convert.ToInt32(cb_Permission.SelectedValue), }; status = RBACManager.RmRolePermission(rp, mainForm.db); if (status == Program.ExitCode.Success) { MessageBox.Show(this, "Permission успешно удален!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } if (status == Program.ExitCode.Error) { MessageBox.Show(this, "Error while submitting deletion to the DataBase", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (status == Program.ExitCode.ElementDoesNotExists) { MessageBox.Show(this, "Permission не авторизован для указанной роли!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
private void btn_addRolePermission_Save_Click(object sender, EventArgs e) { Program.ExitCode status; //Создать RolePermission: RolePermission rp = new RolePermission { Role_Id = Convert.ToInt32(cb_Role.SelectedValue), Permission_Id = Convert.ToInt32(cb_Permission.SelectedValue), }; status = RBACManager.AddRolePermission(rp, mainForm.db); if (status == Program.ExitCode.Success) { MessageBox.Show(this, "Permission успешно авторизован для роли!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } if (status == Program.ExitCode.Error) { MessageBox.Show(this, "Error while submitting deletion to the DataBase", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (status == Program.ExitCode.ElementExists) { MessageBox.Show(this, "Выбранный permission уже авторизован для выбранной роли!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
partial void DeleteRolePermission(RolePermission instance);
partial void UpdateRolePermission(RolePermission instance);
partial void InsertRolePermission(RolePermission instance);
private void detach_RolePermission(RolePermission entity) { this.SendPropertyChanging(); entity.Role = null; }
private void attach_RolePermission(RolePermission entity) { this.SendPropertyChanging(); entity.Role = this; }
public static Program.ExitCode RmRolePermission(RolePermission rp_in, rbacLINQ2SQLDataContext db) { //check if the role exists var query = from rp in db.RolePermission where rp.Role_Id == rp_in.Role_Id && rp.Permission_Id == rp_in.Permission_Id select rp; //if does exist, remove: if (query.Count() != 0) { //here must be checking of role-permission addition posibility within Constraints of RBAC2. //... /* * Без учета Активных ролей. Вообще, эта операция должна выполняться, когда выбранная роль не залогинена ни у одного пользователя * Т.е. когда query.First().Role.ActiveRole.Count == 0 * Более того, когда все роли, лежащие Выше по ролевой иерархии, не залогинены. (чтобы спокойно у них отобрать permission) * */ db.RolePermission.DeleteOnSubmit(query.First()); try { db.SubmitChanges(); return Program.ExitCode.Success; } catch (Exception exc) { return Program.ExitCode.Error; } } //if doesn't exist: else { return Program.ExitCode.ElementExists; } }
public static void AddRolePermission_noTryCatch(RolePermission rp_in, rbacLINQ2SQLDataContext db) { //check if the role exists var query = from rp in db.RolePermission where rp.Role_Id == rp_in.Role_Id && rp.Permission_Id == rp_in.Permission_Id select rp; //if does not exist, add: if (query.Count() == 0) { //here must be checking of role-permission addition posibility within Constraints of RBAC2. //... db.RolePermission.InsertOnSubmit(rp_in); db.SubmitChanges(); System.Diagnostics.Debug.WriteLine("Added RolePermission {0}->{1}:", rp_in.Role_Id, rp_in.Permission_Id); } else { System.Diagnostics.Debug.WriteLine("Existing RolePermission {0}->{1}:", rp_in.Role_Id, rp_in.Permission_Id); } }
public static Program.ExitCode AddRolePermission(RolePermission rp_in, rbacLINQ2SQLDataContext db) { //check if the role exists var query = from rp in db.RolePermission where rp.Role_Id == rp_in.Role_Id && rp.Permission_Id == rp_in.Permission_Id select rp; //if does not exist, add: if (query.Count() == 0) { //here must be checking of role-permission addition posibility within Constraints of RBAC2. //... db.RolePermission.InsertOnSubmit(rp_in); try { db.SubmitChanges(); return Program.ExitCode.Success; } catch (Exception exc) { return Program.ExitCode.Error; } } //if exists: else { return Program.ExitCode.ElementExists; } }
private static bool XMLReadRole(XmlNode roleNode, int pid, rbacLINQ2SQLDataContext db) { Role role; Permission perm; RolePermission rp; int cardinality = 0; if (!Int32.TryParse(roleNode.Attributes["cardinality"].Value, out cardinality)) { return false; }; role = new Role() { Name = roleNode.Attributes["name"].Value, Cardinality = cardinality, Policy_Id = pid, }; RBACManager.AddRole_noTryCatch(role, db); // Depending on our specification we could have to update an existing role //RBACManager.UpdateRole(role,db); // Get this role (just added to the database or existed in it role = db.Role.Single(x => x.Name == role.Name && x.Policy_Id == role.Policy_Id); // If there's no single Permissions block, error: if (roleNode.ChildNodes.Count != 1) { return false; } XmlNode permBlock = roleNode.ChildNodes.Item(0); foreach (XmlNode permNode in permBlock.ChildNodes) { perm = db.Permission.Single(x => x.Name == permNode.Attributes["name"].Value && x.Policy_Id == pid); rp = new RolePermission() { Permission_Id = perm.Id, Role_Id = role.Id }; RBACManager.AddRolePermission_noTryCatch(rp, db); } return true; }