コード例 #1
0
ファイル: PermissionService.cs プロジェクト: hsb0307/Nut.NET
        /// <summary>
        /// Authorize permission
        /// </summary>
        /// <param name="permission">Permission record</param>
        /// <param name="customer">Customer</param>
        /// <returns>true - authorized; otherwise, false</returns>
        public virtual bool Authorize(PermissionRecord permission, User user) {
            if (permission == null)
                return false;

            if (user == null)
                return false;

            return Authorize(permission.SystemName, user);
        }
コード例 #2
0
ファイル: PermissionService.cs プロジェクト: hsb0307/Nut.NET
        /// <summary>
        /// Install permissions
        /// </summary>
        /// <param name="permissionProvider">Permission provider</param>
        public virtual 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 userRole = _userService.GetUserRoleBySystemName(defaultPermission.CustomerRoleSystemName);
                        if (userRole == null) {
                            //new role (save it)
                            userRole = new UserRole {
                                Name = defaultPermission.CustomerRoleSystemName,
                                Active = true,
                                SystemName = defaultPermission.CustomerRoleSystemName
                            };
                            _userService.InsertUserRole(userRole);
                        }


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

                    //save new permission
                    InsertPermissionRecord(permission1);

                    //save localization
                    permission1.SaveLocalizedPermissionName(_localizationService, _languageService);
                }
            }
        }
コード例 #3
0
ファイル: PermissionService.cs プロジェクト: hsb0307/Nut.NET
 /// <summary>
 /// Authorize permission
 /// </summary>
 /// <param name="permission">Permission record</param>
 /// <returns>true - authorized; otherwise, false</returns>
 public virtual bool Authorize(PermissionRecord permission) {
     return Authorize(permission, _workContext.CurrentUser);
 }
コード例 #4
0
ファイル: PermissionService.cs プロジェクト: hsb0307/Nut.NET
        /// <summary>
        /// Updates the permission
        /// </summary>
        /// <param name="permission">Permission</param>
        public virtual void UpdatePermissionRecord(PermissionRecord permission) {
            if (permission == null)
                throw new ArgumentNullException("permission");

            _permissionRecordRepository.Update(permission);

            _signals.Trigger(PERMISSIONS_PATTERN_KEY);
        }