Пример #1
0
        public void DeletePermissionRecord(PermissionRecord permission)
        {
            if (permission == null)
                throw new ArgumentNullException("permission");

            _permissionPecordRepository.Delete(permission);
            //这个是干嘛的  
            _cacheManager.RemoveByPattern(PERMISSIONS_PATTERN_KEY);
        }
Пример #2
0
 public bool Authorize(PermissionRecord permission)
 {
     return Authorize(permission, _workContext.CurrentUser);
 }
Пример #3
0
        public bool Authorize(PermissionRecord permission, User user)
        {
            if (permission == null)
                return false;

            if (user == null)
                return false;
            return Authorize(permission.SystemName, user);
        }
Пример #4
0
        public void InstallPermissions(IPermissionProvider permissionProvider)
        {
            //install new permissions
            var permissions = permissionProvider.GetPermissions();
            foreach (var permission in permissions)
            {
                var permission1 = GetPermissionRecordBySystemName(permission.SystemName);
                if (permission1 == null)
                {
                    //new permission (install it)
                    permission1 = new PermissionRecord
                    {
                        Name = permission.Name,
                        SystemName = permission.SystemName,
                        Category = permission.Category,
                    };

                    //这里有点不合理 难道每次都要循环一次?
                    //default customer role mappings
                    var defaultPermissions = permissionProvider.GetDefaultPermissions();
                    foreach (var defaultPermission in defaultPermissions)
                    {
                        var customerRole = _userService.GetUserRoleBySystemName(defaultPermission.UserRoleSystemName);
                        if (customerRole == null)
                        {
                            //new role (save it)
                            customerRole = new UserRole
                            {
                                Name = defaultPermission.UserRoleSystemName,
                                Active = true,
                                SystemName = defaultPermission.UserRoleSystemName
                            };
                            _userService.InsertUserRole(customerRole);
                        }


                        var defaultMappingProvided = (from p in defaultPermission.PermissionRecords
                                                      where p.SystemName == permission1.SystemName
                                                      select p).Any();
                        var mappingExists = (from p in customerRole.PermissionRecords
                                             where p.SystemName == permission1.SystemName
                                             select p).Any();
                        if (defaultMappingProvided && !mappingExists)
                        {
                            permission1.UserRoles.Add(customerRole);
                        }
                    }

                    //save new permission
                    InsertPermissionRecord(permission1);

                    //save localization 本地化
                   // permission1.SaveLocalizedPermissionName(_localizationService, _languageService);
                }
            }
        }