示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SystemRolePermission"/> class.
        /// </summary>
        /// <param name="systemRole">The system role.</param>
        /// <param name="systemPermission">The system permission.</param>
        protected internal SystemRolePermission( SystemRole systemRole, SystemPermission systemPermission )
        {
            Check.IsNotNull ( systemRole, "System role is required." );
            Check.IsNotNull ( systemPermission, "System permission is required." );

            _systemRole = systemRole;
            _systemPermission = systemPermission;
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SystemRolePermission"/> class.
        /// </summary>
        /// <param name="systemRole">The system role.</param>
        /// <param name="systemPermission">The system permission.</param>
        protected internal SystemRolePermission(SystemRole systemRole, SystemPermission systemPermission)
        {
            Check.IsNotNull(systemRole, "System role is required.");
            Check.IsNotNull(systemPermission, "System permission is required.");

            _systemRole       = systemRole;
            _systemPermission = systemPermission;
        }
示例#3
0
        /// <summary>
        /// Revokes the system permission.
        /// </summary>
        /// <param name="systemPermission">The system permission.</param>
        public virtual void RevokeSystemPermission(SystemPermission systemPermission)
        {
            Check.IsNotNull(systemPermission, "System permission is required.");

            var existingSystemPermission = (from sp in _grantedSystemPermissions where sp.SystemPermission.Key == systemPermission.Key select sp).FirstOrDefault();

            if (existingSystemPermission != null)
            {
                _grantedSystemPermissions.Remove(existingSystemPermission);
                NotifyItemRemoved(() => GrantedSystemPermissions, existingSystemPermission);
            }
        }
示例#4
0
        /// <summary>
        /// Grants the system permission.
        /// </summary>
        /// <param name="systemPermission">The system permission.</param>
        public virtual void GrantSystemPermission(SystemPermission systemPermission)
        {
            Check.IsNotNull(systemPermission, "System permission is required.");

            DomainRuleEngine.CreateRuleEngine <SystemRole, SystemPermission> (this, () => GrantSystemPermission)
            .WithContext(systemPermission)
            .Execute(
                () =>
            {
                var systemRolePermission = new SystemRolePermission(this, systemPermission);
                _grantedSystemPermissions.Add(systemRolePermission);
                NotifyItemAdded(() => GrantedSystemPermissions, systemRolePermission);
            }
                );
        }
        public void CreateSystemPermission_CannotGrantSystemPermissionToJobFunction_ValidationFailureEventIsRaised()
        {
            using ( var serviceLocatorFixture = new ServiceLocatorFixture () )
            {
                // Setup
                SetupServiceLocatorFixture ( serviceLocatorFixture );

                // Register
                var eventRaised = false;
                DomainEvent.Register<RuleViolationEvent> ( p => eventRaised = true );

                var systemRoleRepositoryMock = new Mock<ISystemRoleRepository> ();
                var systemRoleFactory = new SystemRoleFactory ( systemRoleRepositoryMock.Object );

                // Exercise
                var systemRole = systemRoleFactory.CreateSystemRole ( "RoleName", "Role description.", SystemRoleType.JobFunction );

                var systemPermission = new SystemPermission ( "WellKnownName", "MyPermission", "My permission description." );
                systemRole.GrantSystemPermission ( systemPermission );

                // Verify
                Assert.IsTrue ( eventRaised );
            }
        }
示例#6
0
        /// <summary>
        /// Revokes the system permission.
        /// </summary>
        /// <param name="systemPermission">The system permission.</param>
        public virtual void RevokeSystemPermission( SystemPermission systemPermission )
        {
            Check.IsNotNull ( systemPermission, "System permission is required." );

            var existingSystemPermission = ( from sp in _grantedSystemPermissions where sp.SystemPermission.Key == systemPermission.Key select sp ).FirstOrDefault ();
            if ( existingSystemPermission != null )
            {
                _grantedSystemPermissions.Remove ( existingSystemPermission );
                NotifyItemRemoved(() => GrantedSystemPermissions, existingSystemPermission);
            }
        }
示例#7
0
        /// <summary>
        /// Grants the system permission.
        /// </summary>
        /// <param name="systemPermission">The system permission.</param>
        public virtual void GrantSystemPermission( SystemPermission systemPermission )
        {
            Check.IsNotNull ( systemPermission, "System permission is required." );

            DomainRuleEngine.CreateRuleEngine<SystemRole, SystemPermission> ( this, () => GrantSystemPermission )
                .WithContext ( systemPermission )
                .Execute (
                    () =>
                        {
                            var systemRolePermission = new SystemRolePermission ( this, systemPermission );
                            _grantedSystemPermissions.Add ( systemRolePermission );
                            NotifyItemAdded ( () => GrantedSystemPermissions, systemRolePermission );
                        }
                );
        }
        public void CreateSystemPermission_NoDuplicateGrantSystemPermissionWithContext_ValidationFailureEventIsRaised()
        {
            using ( var serviceLocatorFixture = new ServiceLocatorFixture () )
            {
                // Setup
                SetupServiceLocatorFixture ( serviceLocatorFixture );

                // Register
                var eventRaised = false;
                DomainEvent.Register<RuleViolationEvent> ( p => eventRaised = true );

                var systemRoleRepositoryMock = new Mock<ISystemRoleRepository> ();
                var systemRoleFactory = new SystemRoleFactory ( systemRoleRepositoryMock.Object );

                // Exercise
                var systemRole = systemRoleFactory.CreateSystemRole ( "RoleName", "Role description.", SystemRoleType.Task );

                var systemPermission1 = new SystemPermission ( "WellKnownName1", "Permission display name.", "Permission description." );
                systemRole.GrantSystemPermission ( systemPermission1 );

                var systemPermission2 = new SystemPermission ( "WellKnownName1", "Permission display name", "Permission description." );
                systemRole.GrantSystemPermission ( systemPermission2 );

                // Verify
                Assert.IsTrue ( eventRaised );
            }
        }