public void InsertRoleAndPermissions(string roleName, string creatorUserName, string description, List <string> generalPermissionList)
        {
            using (var conn = GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        if (generalPermissionList != null && generalPermissionList.Count > 0)
                        {
                            var permissionsInRolesInfo = new PermissionsInRolesInfo(0, roleName, TranslateUtils.ObjectCollectionToString(generalPermissionList));
                            DataProvider.PermissionsInRolesDao.InsertWithTrans(permissionsInRolesInfo, trans);
                        }

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }
                }
            }
            DataProvider.RoleDao.InsertRole(roleName, creatorUserName, description);
        }
Beispiel #2
0
        public void UpdateRoleAndGeneralPermissions(string roleName, string description, ArrayList generalPermissionArrayList)
        {
            using (var conn = GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        BaiRongDataProvider.PermissionsInRolesDao.DeleteWithTrans(roleName, trans);
                        if (generalPermissionArrayList != null && generalPermissionArrayList.Count > 0)
                        {
                            var permissionsInRolesInfo = new PermissionsInRolesInfo(roleName, TranslateUtils.ObjectCollectionToString(generalPermissionArrayList));
                            BaiRongDataProvider.PermissionsInRolesDao.InsertWithTrans(permissionsInRolesInfo, trans);
                        }

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }
                }
            }
            BaiRongDataProvider.RoleDao.UpdateRole(roleName, description);
        }
        public void InsertWithTrans(PermissionsInRolesInfo info, IDbTransaction trans)
        {
            var insertParms = new IDataParameter[]
            {
                GetParameter(ParmRoleRoleName, DataType.VarChar, 255, info.RoleName),
                GetParameter(ParmGeneralPermissions, DataType.Text, info.GeneralPermissions)
            };

            ExecuteNonQuery(trans, SqlInsert, insertParms);
        }
        public void Insert(PermissionsInRolesInfo info)
        {
            var parameters = new IDataParameter[]
            {
                GetParameter(ParamRoleRoleName, DataType.VarChar, 255, info.RoleName),
                GetParameter(ParamGeneralPermissions, DataType.Text, info.GeneralPermissions)
            };

            ExecuteNonQuery(SqlInsert, parameters);
        }
        private PermissionsInRolesInfo GetPermissionsInRolesInfo(string roleName)
        {
            PermissionsInRolesInfo info = null;

            var parms = new IDataParameter[]
            {
                GetParameter(ParmRoleRoleName, DataType.VarChar, 255, roleName)
            };

            using (var rdr = ExecuteReader(SqlSelect, parms))
            {
                if (rdr.Read())
                {
                    var i = 0;
                    info = new PermissionsInRolesInfo(GetInt(rdr, i++), GetString(rdr, i++), GetString(rdr, i));
                }
                rdr.Close();
            }
            return(info);
        }
Beispiel #6
0
        public IHttpActionResult UpdateRole(int roleId)
        {
            try
            {
                var request = new AuthenticatedRequest();
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.SettingsPermissions.Admin))
                {
                    return(Unauthorized());
                }

                var roleName                       = request.GetPostString("roleName");
                var description                    = request.GetPostString("description");
                var generalPermissionList          = request.GetPostObject <List <string> >("generalPermissions");
                var sitePermissionsInRolesInfoList =
                    request.GetPostObject <List <SitePermissionsInfo> >("sitePermissions");

                var roleInfo = DataProvider.RoleDao.GetRoleInfo(roleId);
                if (roleInfo.RoleName != roleName)
                {
                    if (EPredefinedRoleUtils.IsPredefinedRole(roleName))
                    {
                        return(BadRequest($"角色添加失败,{roleName}为系统角色!"));
                    }
                    if (DataProvider.RoleDao.IsRoleExists(roleName))
                    {
                        return(BadRequest("角色名称已存在,请更换角色名称!"));
                    }
                }

                DataProvider.PermissionsInRolesDao.Delete(roleInfo.RoleName);
                DataProvider.SitePermissionsDao.Delete(roleInfo.RoleName);

                if (generalPermissionList != null && generalPermissionList.Count > 0)
                {
                    var permissionsInRolesInfo = new PermissionsInRolesInfo(0, roleName,
                                                                            TranslateUtils.ObjectCollectionToString(generalPermissionList));
                    DataProvider.PermissionsInRolesDao.Insert(permissionsInRolesInfo);
                }

                if (sitePermissionsInRolesInfoList != null && sitePermissionsInRolesInfoList.Count > 0)
                {
                    foreach (var sitePermissionsInfo in sitePermissionsInRolesInfoList)
                    {
                        sitePermissionsInfo.RoleName = roleName;
                        DataProvider.SitePermissionsDao.Insert(sitePermissionsInfo);
                    }
                }

                roleInfo.RoleName    = roleName;
                roleInfo.Description = description;

                DataProvider.RoleDao.UpdateRole(roleInfo);

                PermissionsImpl.ClearAllCache();

                request.AddAdminLog("修改管理员角色", $"角色名称:{roleName}");

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }