Example #1
0
        public IActionResult DelAdminRole(int id)
        {
            AdminRoles entity = AdminRoles.Find(AdminRoles._.Id == id);

            if (entity == null)
            {
                tip.Message = "系统找不到本管理组详情!";
                return(Json(tip));
            }
            if (entity.NotAllowDel == 1)
            {
                tip.Message = "本管理组设定不允许删除,如果需要删除,请先解除限制!";
                return(Json(tip));
            }
            //如果不是超级管理员,不允许删除
            Core.Admin my = Core.Admin.GetMyInfo();
            if (my.Roles.IsSuperAdmin != 1)
            {
                tip.Message = "非超级管理员,不能执行此操作!";
                return(Json(tip));
            }
            //如果只有一个管理组,不允许删除!
            if (AdminRoles.FindCount(null, null, null, 0, 0) == 1)
            {
                tip.Message = "只有一个管理组,不能删除!";
                return(Json(tip));
            }
            //删除管理组,并删除旗下所有管理员
            Core.Admin.WriteLogActions($"执行删除管理组({entity.Id}:{entity.RoleName})详情;");
            entity.Delete();

            tip.Status  = JsonTip.SUCCESS;
            tip.Message = "删除管理组成功";
            return(Json(tip));
        }
Example #2
0
 protected override void OnRemoving()
 {
     base.OnRemoving();
     try
     {
         AdminRoles.Clear(); //foreach thing in AdminRoles en.Remove();
     }
     catch (Exception ex)
     {
         throw new DocException("Failed to delete Team in AdminRoles delete", ex);
     }
     try
     {
         Scopes.Clear(); //foreach thing in Scopes en.Remove();
     }
     catch (Exception ex)
     {
         throw new DocException("Failed to delete Team in Scopes delete", ex);
     }
     try
     {
         Updates.Clear(); //foreach thing in Updates en.Remove();
     }
     catch (Exception ex)
     {
         throw new DocException("Failed to delete Team in Updates delete", ex);
     }
     FlushCache();
 }
Example #3
0
        public AdminRoles GetAdminRolesById(int Id)
        {
            AdminRoles adminRoles = null;

            using (SqlConnection connection = GetConnection())
            {
                SqlCommand command = new SqlCommand("_AdminRolesGetById", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@AdminRolesID", Id);
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    if (reader.Read())
                    {
                        adminRoles = AdminRolesReader(reader);
                    }
                    else
                    {
                        throw new DataAccessException("Khong tim thay gia tri nao");
                    }
                    command.Dispose();
                }
            }
            return(adminRoles);
        }
Example #4
0
        public IActionResult AdminRole()
        {
            IList <AdminRoles> list = AdminRoles.FindAll(AdminRoles._.Id > 0, AdminRoles._.Rank.Asc(), null, 0, 0);

            Core.Admin.WriteLogActions("查看管理组列表;");
            return(View(list));
        }
Example #5
0
        public void UpdateAdminUserPermissions_throws_exception_when_spaces_unavailable_and_user_not_on_role(
            bool newIsTrainer,
            bool newIsContentCreator,
            bool newImportOnly
            )
        {
            // Given
            var currentAdminUser = UserTestHelper.GetDefaultAdminUser(
                isContentCreator: false,
                isTrainer: false,
                importOnly: false,
                isContentManager: false
                );
            var numberOfAdmins = GetFullCentreContractAdminUsage();

            GivenAdminDataReturned(numberOfAdmins, currentAdminUser);
            var adminRoles = new AdminRoles(true, true, newIsContentCreator, newIsTrainer, true, newImportOnly);

            // Then
            Assert.Throws <AdminRoleFullException>(
                () => userService.UpdateAdminUserPermissions(
                    currentAdminUser.Id,
                    adminRoles,
                    0
                    )
                );
            AssertAdminPermissionUpdateMustNotHaveHappened();
        }
Example #6
0
        PromoteDelegateToAdmin_throws_email_in_use_AdminCreationFailedException_if_active_admin_already_exists()
        {
            // Given
            var delegateUser = UserTestHelper.GetDefaultDelegateUser();
            var adminUser    = UserTestHelper.GetDefaultAdminUser();
            var adminRoles   = new AdminRoles(true, true, true, true, true, true, true);

            A.CallTo(() => userDataService.GetDelegateUserById(A <int> ._)).Returns(delegateUser);
            A.CallTo(() => userDataService.GetAdminUserByEmailAddress(A <string> ._)).Returns(adminUser);

            // When
            registrationService.PromoteDelegateToAdmin(adminRoles, 0, 1);

            // Then
            using (new AssertionScope())
            {
                A.CallTo(
                    () => userDataService.UpdateAdminUserPermissions(
                        adminUser.Id,
                        adminRoles.IsCentreAdmin || adminUser.IsCentreAdmin,
                        adminRoles.IsSupervisor || adminRoles.IsSupervisor,
                        adminRoles.IsNominatedSupervisor || adminUser.IsNominatedSupervisor,
                        adminRoles.IsTrainer || adminUser.IsTrainer,
                        adminRoles.IsContentCreator || adminUser.IsContentCreator,
                        adminRoles.IsContentManager || adminUser.IsContentManager,
                        adminRoles.ImportOnly || adminUser.ImportOnly,
                        adminUser.CategoryId
                        )
                    ).MustHaveHappenedOnceExactly();
            }
        }
Example #7
0
        public AdminRoles GetAdminRoles(int rolesId, string username)
        {
            AdminRoles adminRoles = null;

            using (SqlConnection connection = GetConnection())
            {
                SqlCommand command = new SqlCommand("_AdminRolesGet", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@RolesID", rolesId);
                command.Parameters.AddWithValue("@Admin_UserName", username);
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    if (reader.Read())
                    {
                        adminRoles = AdminRolesReader(reader);
                    }
                    else
                    {
                        throw new DataAccessException("Không tìm thấy giá trị");
                    }
                    command.Dispose();
                }
            }
            return(adminRoles);
        }
Example #8
0
        public void PromoteDelegateToAdmin_calls_data_service_with_expected_value()
        {
            // Given
            var delegateUser = UserTestHelper.GetDefaultDelegateUser();
            var adminRoles   = new AdminRoles(true, true, true, true, true, true);

            A.CallTo(() => userDataService.GetDelegateUserById(A <int> ._)).Returns(delegateUser);
            A.CallTo(() => userDataService.GetAdminUserByEmailAddress(A <string> ._)).Returns(null);

            // When
            registrationService.PromoteDelegateToAdmin(adminRoles, 1, 1);

            // Then
            A.CallTo(
                () => registrationDataService.RegisterAdmin(
                    A <AdminRegistrationModel> .That.Matches(
                        a =>
                        a.FirstName == delegateUser.FirstName &&
                        a.LastName == delegateUser.LastName &&
                        a.Email == delegateUser.EmailAddress &&
                        a.Centre == delegateUser.CentreId &&
                        a.PasswordHash == delegateUser.Password &&
                        a.Active &&
                        a.Approved &&
                        a.IsCentreAdmin == adminRoles.IsCentreAdmin &&
                        !a.IsCentreManager &&
                        a.IsContentManager == adminRoles.IsContentManager &&
                        a.ImportOnly == adminRoles.IsCmsAdministrator &&
                        a.IsContentCreator == adminRoles.IsContentCreator &&
                        a.IsTrainer == adminRoles.IsTrainer &&
                        a.IsSupervisor == adminRoles.IsSupervisor
                        )
                    )
                ).MustHaveHappened();
        }
Example #9
0
 public int InsertRole(AdminRoles roles)
 {
     Logging.LogDebugMessage("Method: InsertRole ,MethodType: Post, Layer: RolesController, Parameters: roles = " + JsonConvert.SerializeObject(roles));
     using (RolesBL insertRole = new RolesBL())
     {
         return(insertRole.InsertRole(roles));
     }
 }
Example #10
0
 public bool UpdateRole(AdminRoles role)
 {
     Logging.LogDebugMessage("Method: UpdateRole ,MethodType: Post, Layer: RolesController, Parameters:role = " + JsonConvert.SerializeObject(role));
     using (RolesBL updateRole = new RolesBL())
     {
         return(updateRole.UpdateRole(role));
     }
 }
 public bool IsPoolManager()
 {
     return(EnvironmentResourceGroup.Any(p => ReaderRoles.Contains(p.Role)) &&
            Batch.Any(p => AdminRoles.Contains(p.Role)) &&
            Storage.Any(p => ReaderRoles.Contains(p.Role)) &&
            KeyVault.Any(p => ReaderRoles.Contains(p.Role)) &&
            ApplicationInsights.Any(p => ReaderRoles.Contains(p.Role)) &&
            VNet.Any(p => PoolManagerRoles.Contains(p.Role)));
 }
Example #12
0
        public IActionResult AddAdmin()
        {
            //加载管理组
            IList <AdminRoles> list = AdminRoles.FindAll(AdminRoles._.Id > 0, AdminRoles._.Rank.Asc(), null, 0, 0);

            ViewBag.RoleList = list;
            Core.Admin.WriteLogActions("查看添加管理员页面;");
            return(View());
        }
Example #13
0
        public IActionResult AddAdmin()
        {
            //加载管理组
            IList <AdminRoles> list = AdminRoles.FindAll(AdminRoles._.Id > 0, AdminRoles._.Rank.Asc(), null, 0, 0);

            ViewBag.RoleList    = list;
            ViewBag.passwordTip = Utils.GetPasswordStrengthTip(_systemSetting.PasswordStrength);
            Core.Admin.WriteLogActions("查看添加管理员页面;");
            return(View());
        }
Example #14
0
        private void BuildValidAdminRoleIds(IConfiguration configuration)
        {
            var ar = new AdminRoles();

            configuration.GetSection(Constants.AdminRolesKey).Bind(ar);

            foreach (var item in ar.Roles)
            {
                validAdminRoleIds.Add(item.Id);
            }
        }
Example #15
0
 /// <summary>
 /// Setter method for AdminRole
 /// </summary>
 /// <param name="value"></param>
 /// <remarks>Checks if passed value is defined in AdminRoles</remarks>
 public void SetAdminRole(int value)
 {
     if (Enum.IsDefined(typeof(AdminRoles), value))
     {
         AdminRole = (AdminRoles)value;
     }
     else
     {
         throw new IndexOutOfRangeException("Specified value for accountType is not defined in AdminRoles enum");
     }
 }
Example #16
0
        public string GetPermission(int rolesID, string username)
        {
            string permission = "";

            if (CheckExitPermission(rolesID, username))
            {
                AdminRoles adminRoles = GetAdminRoles(rolesID, username);
                permission = adminRoles.Permission;
            }

            return(permission);
        }
Example #17
0
        private AdminRoles AdminRolesReader(SqlDataReader reader)
        {
            AdminRoles adminRoles = new AdminRoles();

            adminRoles.AdminRolesID  = (int)reader["AdminRolesID"];
            adminRoles.RolesID       = (int)reader["RolesID"];
            adminRoles.AdminUserName = (string)reader["Admin_UserName"];
            adminRoles.Permission    = (string)reader["Permission"];
            adminRoles.Created       = (DateTime)reader["Created"];
            adminRoles.UserName      = (string)reader["UserName"];

            return(adminRoles);
        }
Example #18
0
        public IActionResult EditAdmin(int id)
        {
            //加载管理组
            IList <AdminRoles> list = AdminRoles.FindAll(AdminRoles._.Id > 0, AdminRoles._.Rank.Asc(), null, 0, 0);

            ViewBag.RoleList = list;

            Core.Admin entity = Core.Admin.Find(Core.Admin._.Id == id);
            if (entity == null)
            {
                return(EchoTipPage("系统找不到本记录!"));
            }
            Core.Admin.WriteLogActions($"查看/编辑管理员({entity.UserName});");
            return(View(entity));
        }
Example #19
0
 /// <summary>已重载。在事务保护范围内处理业务,位于Valid之后</summary>
 /// <returns></returns>
 protected override int OnUpdate()
 {
     //是否修改了角色ID串
     if (Dirtys[__.RoleIDs])
     {
         //先删除关联
         if (AdminRoles != null)
         {
             AdminRoles.Delete();
         }
         //再插入关联
         InsertAdminRole();
     }
     return(base.OnUpdate());
 }
Example #20
0
    protected void btn_add_Click(object sender, EventArgs e)
    {
        Admin admin = ReceiveHtml();

        try
        {
            AdminBSO adminBSO = new AdminBSO();
            if (adminBSO.CheckExist(admin.AdminName))
            {
                error.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Tài khoản đã được đăng ký. Vui lòng đăng ký lại !</div>";
            }
            else
            if (adminBSO.CheckExistEmail(admin.AdminEmail))
            {
                error.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Địa chỉ Email đã được đăng ký. Vui lòng đăng ký lại !</div>";
            }
            else
            {
                if (CheckedList().Equals(""))
                {
                    error.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Lỗi: Phải lựa chọn ít nhất 1 quyền !</div>";
                }
                else
                {
                    int id = adminBSO.CreateAdmin(admin);

                    RolesBSO      rolesBSO      = new RolesBSO();
                    IRoles        roles         = rolesBSO.GetRolesByName("Guest");
                    AdminRolesBSO adminRolesBSO = new AdminRolesBSO();
                    AdminRoles    adminRoles    = new AdminRoles();

                    adminRoles.AdminUserName = admin.AdminName;
                    adminRoles.RolesID       = roles.RolesID;
                    adminRoles.UserName      = Session["Admin_UserName"].ToString();
                    adminRoles.Permission    = "";
                    adminRoles.Created       = DateTime.Now;
                    adminRolesBSO.CreateAdminRoles(adminRoles);

                    error.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Thêm mới thành công !</div>";
                    initControl(id);
                }
            }
        }
        catch (Exception ex)
        {
            error.Text = ex.Message.ToString();
        }
    }
Example #21
0
        public void PromoteDelegateToAdmin_throws_AdminCreationFailedException_if_delegate_has_no_email()
        {
            // Given
            var delegateUser = UserTestHelper.GetDefaultDelegateUser(emailAddress: null);
            var adminRoles   = new AdminRoles(true, true, true, true, true, true);

            A.CallTo(() => userDataService.GetDelegateUserById(A <int> ._)).Returns(delegateUser);

            // When
            var result = Assert.Throws <AdminCreationFailedException>(
                () => registrationService.PromoteDelegateToAdmin(adminRoles, 1, 1)
                );

            // Then
            result.Error.Should().Be(AdminCreationError.UnexpectedError);
        }
Example #22
0
    private void VierUserRoles()
    {
        //PermissionBSO permissionBSO = new PermissionBSO();
        //DataTable table = permissionBSO.GetPermissionAll();
        //DataView dataView = new DataView(table);
        //dataView.Sort = "PermissionID ASC";
        //DataTable dataTable = dataView.ToTable();
        //commonBSO commonBSO = new commonBSO();

        AdminRolesBSO adminRolesBSO = new AdminRolesBSO();
        AdminRoles    adminRoles    = new AdminRoles();


        foreach (GridViewRow rows in grvRoles.Rows)
        {
            //CheckBoxList chklist = (CheckBoxList)dataItem.FindControl("chklist");
            CheckBox chkId = (CheckBox)rows.Cells[0].FindControl("chkId");

            //commonBSO.FillToCheckBoxList(chklist, dataTable, "PermissionName", "Value");

            if (adminRolesBSO.CheckExitRolesUser(Convert.ToInt32(rows.Cells[0].Text), hddUserName.Value))
            {
                //Permission
                //adminRoles = adminRolesBSO.GetAdminRoles(Convert.ToInt32(dataItem["Roles_ID"].Text), hddUserName.Value);

                //if (adminRoles != null)
                //{
                //    string sPermission = adminRoles.Permission;
                //    if (!sPermission.Equals(""))
                //    {
                //        string[] sSlip = sPermission.Split(new char[] { ',' });
                //        foreach (string s in sSlip)
                //        {
                //            foreach (ListItem items in chklist.Items)
                //            {
                //                if (items.Value == s)
                //                    items.Selected = true;
                //            }
                //        }
                //    }
                //}

                //Admin_ID
                chkId.Checked = true;
            }
        }
    }
Example #23
0
 public IActionResult ConfirmNominateSupervisor(SupervisorDelegateViewModel supervisorDelegate)
 {
     if (ModelState.IsValid && supervisorDelegate.ActionConfirmed)
     {
         var categoryId = User.GetAdminCourseCategoryFilter();
         var supervisorDelegateDetail = supervisorService.GetSupervisorDelegateDetailsById(supervisorDelegate.Id, GetAdminID(), 0);
         var adminRoles = new AdminRoles(false, false, true, false, false, false, false);
         if (supervisorDelegateDetail.CandidateID != null)
         {
             registrationService.PromoteDelegateToAdmin(adminRoles, (categoryId ?? 0), (int)supervisorDelegateDetail.CandidateID);
         }
         return(RedirectToAction("MyStaffList"));
     }
     else
     {
         return(View("NominateSupervisor", supervisorDelegate));
     }
 }
Example #24
0
        public void PromoteDelegateToAdmin_throws_email_in_use_AdminCreationFailedException_if_admin_already_exists()
        {
            // Given
            var delegateUser = UserTestHelper.GetDefaultDelegateUser();
            var adminUser    = UserTestHelper.GetDefaultAdminUser();
            var adminRoles   = new AdminRoles(true, true, true, true, true, true);

            A.CallTo(() => userDataService.GetDelegateUserById(A <int> ._)).Returns(delegateUser);
            A.CallTo(() => userDataService.GetAdminUserByEmailAddress(A <string> ._)).Returns(adminUser);

            // When
            var result = Assert.Throws <AdminCreationFailedException>(
                () => registrationService.PromoteDelegateToAdmin(adminRoles, 1, 1)
                );

            // Then
            result.Error.Should().Be(AdminCreationError.EmailAlreadyInUse);
        }
Example #25
0
        public void PromoteDelegateToAdmin_updates_existing_admin_if_inactive_admin_at_same_centre_already_exists()
        {
            // Given
            const int categoryId   = 1;
            var       delegateUser = UserTestHelper.GetDefaultDelegateUser();
            var       adminUser    = UserTestHelper.GetDefaultAdminUser(active: false);
            var       adminRoles   = new AdminRoles(true, true, true, true, true, true, true);

            A.CallTo(() => userDataService.GetDelegateUserById(A <int> ._)).Returns(delegateUser);
            A.CallTo(() => userDataService.GetAdminUserByEmailAddress(A <string> ._)).Returns(adminUser);

            // When
            registrationService.PromoteDelegateToAdmin(adminRoles, categoryId, 1);

            // Then
            using (new AssertionScope())
            {
                A.CallTo(() => userDataService.ReactivateAdmin(adminUser.Id)).MustHaveHappenedOnceExactly();
                A.CallTo(
                    () => userDataService.UpdateAdminUser(
                        delegateUser.FirstName !,
                        delegateUser.LastName,
                        delegateUser.EmailAddress !,
                        delegateUser.ProfileImage,
                        adminUser.Id
                        )
                    ).MustHaveHappenedOnceExactly();
                A.CallTo(() => passwordDataService.SetPasswordByAdminId(adminUser.Id, delegateUser.Password !))
                .MustHaveHappenedOnceExactly();
                A.CallTo(
                    () => userDataService.UpdateAdminUserPermissions(
                        adminUser.Id,
                        adminRoles.IsCentreAdmin,
                        adminRoles.IsSupervisor,
                        adminRoles.IsNominatedSupervisor,
                        adminRoles.IsTrainer,
                        adminRoles.IsContentCreator,
                        adminRoles.IsContentManager,
                        adminRoles.ImportOnly,
                        categoryId
                        )
                    ).MustHaveHappenedOnceExactly();
            }
        }
Example #26
0
 private void AssertAdminPermissionsCalledCorrectly(
     int adminId,
     AdminRoles adminRoles,
     int categoryId
     )
 {
     A.CallTo(
         () => userDataService.UpdateAdminUserPermissions(
             adminId,
             adminRoles.IsCentreAdmin,
             adminRoles.IsSupervisor,
             adminRoles.IsTrainer,
             adminRoles.IsContentCreator,
             adminRoles.IsContentManager,
             adminRoles.ImportOnly,
             categoryId
             )
         ).MustHaveHappened();
 }
Example #27
0
        public void UpdateAdminUserPermissions_edits_roles_when_spaces_available()
        {
            // Given
            var currentAdminUser = UserTestHelper.GetDefaultAdminUser(
                isContentCreator: false,
                isTrainer: false,
                importOnly: false,
                isContentManager: false
                );
            var numberOfAdmins = CentreContractAdminUsageTestHelper.GetDefaultNumberOfAdministrators();

            GivenAdminDataReturned(numberOfAdmins, currentAdminUser);
            var adminRoles = new AdminRoles(true, true, true, true, true, true);

            // When
            userService.UpdateAdminUserPermissions(currentAdminUser.Id, adminRoles, 0);

            // Then
            AssertAdminPermissionsCalledCorrectly(currentAdminUser.Id, adminRoles, 0);
        }
Example #28
0
        /// <summary>Get the roles by name.</summary>
        /// <param name="roleName">The String Object.</param>
        /// <returns>Roles Object.</returns>
        public AdminRoles GetRolesByName(string roleName)
        {
            Logging.LogDebugMessage("Method: GetRolesByName, MethodType: Get, Layer: RolesDAL, Parameters: roleName = " + roleName);
            var        dataSet = new DataSet();
            AdminRoles roles   = new AdminRoles();

            try
            {
                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection  = new SqlConnection(this.connectionString);
                    command.CommandText = "USP_RoleSelect";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@RoleName", Value = roleName
                    });

                    using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                    {
                        adapter.Fill(dataSet);
                        if (dataSet != null && dataSet.Tables.Count > 0)
                        {
                            roles = EntityCollectionHelper.ConvertTo <AdminRoles>(dataSet.Tables[0]).FirstOrDefault();
                            Logging.LogDebugMessage("Method: GetRolesByName, MethodType: Get, Layer: RolesDAL, returnRolesList:" + JsonConvert.SerializeObject(roles));
                        }
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                Logging.LogErrorMessage("Method: GetRolesByName, Layer: RolesDAL, Stack Trace: " + sqlEx.ToString());
                throw;
            }
            catch (Exception ex)
            {
                Logging.LogErrorMessage("Method: GetRolesByName, Layer: RolesDAL, Stack Trace: " + ex.ToString());
                throw;
            }
            return(roles);
        }
Example #29
0
        /// <summary>已重载。删除关联数据</summary>
        /// <returns></returns>
        protected override int OnDelete()
        {
            if (AdminRoles != null)
            {
                AdminRoles.Delete();
            }
            if (RoleDataPermissions != null)
            {
                RoleDataPermissions.Delete();
            }
            if (RoleMenus != null)
            {
                RoleMenus.Delete();
            }
            if (RoleMenuButtons != null)
            {
                RoleMenuButtons.Delete();
            }

            return(base.OnDelete());
        }
Example #30
0
 /// <summary>Upadte The Role Details.</summary>
 /// <param name="role">The AdminRole Object.</param>
 /// <returns>The Boolean Value.</returns>
 public bool UpdateRole(AdminRoles role)
 {
     Logging.LogDebugMessage("Method: UpdateRole, MethodType: Post, Layer: RolesBL, Parameters: role = " + JsonConvert.SerializeObject(role));
     using (RolesDAL updateRole = new RolesDAL())
     {
         try
         {
             return(updateRole.UpdateRole(role));
         }
         catch (SqlException sqlEx)
         {
             Logging.LogErrorMessage("Method: UpdateRole, Layer: RolesBL, Stack Trace: " + sqlEx.ToString());
             throw;
         }
         catch (Exception ex)
         {
             Logging.LogErrorMessage("Method: UpdateRole, Layer: RolesBL, Stack Trace: " + ex.ToString());
             throw;
         }
     }
 }