Пример #1
0
        public static void AssertHasPermission(string loginUserName, string checkUserName,
                                               PermissionObjectType objectType, string objectUid, PermissionType permissionType)
        {
            var userInfo          = new UserInfo(loginUserName);
            var permissionManager = new DBAdapter().Permission;
            var hasPermission     = permissionManager.HasPermission(checkUserName,
                                                                    objectUid, permissionType);

            if (!hasPermission)
            {
                var objectName     = string.Empty;
                var objectTypeName = string.Empty;
                switch (objectType)
                {
                case PermissionObjectType.ProjectSeries:
                    objectTypeName = "产品";
                    objectName     = new DBAdapter().ProjectSeries.GetByGuid(objectUid).Name;
                    break;

                case PermissionObjectType.Project:
                    objectTypeName = "产品";
                    objectName     = new DBAdapter().Project.GetProjectByGuid(objectUid).Name;
                    break;

                case PermissionObjectType.TaskGroup:
                    objectTypeName = "工作组";
                    objectName     = new DBAdapter().TaskGroup.GetByGuid(objectUid).Name;
                    break;

                case PermissionObjectType.Task:
                    objectTypeName = "工作";
                    objectName     = new DBAdapter().Task.GetTask(objectUid).Description;
                    break;

                default:
                    objectTypeName = "未知";
                    objectName     = "未知";
                    break;
                }

                var action = string.Empty;
                switch (permissionType)
                {
                case PermissionType.Read:
                    action = "读取";
                    break;

                case PermissionType.Write:
                    action = "修改";
                    break;

                case PermissionType.Execute:
                    action = "操作";
                    break;

                default:
                    action = "未知";
                    break;
                }

                //var loader = new UserProfileLoader(loginUserName);
                //var checkUserDisplayName = loader.GetDisplayRealNameAndUserName(checkUserName);

                Assert(hasPermission, "用户{0}没有{1}[{2}]的[{3}]权限",
                       checkUserName, objectTypeName, objectName, action);
            }
        }