private void LazyLoad()
        {
            if (!this.lazyLoaded)
            {
                var strategy = this.Object.Strategy;
                var session  = strategy.Session;

                SecurityToken[] securityTokens;
                if (this.Object is DelegatedAccessControlledObject controlledObject)
                {
                    var delegatedAccess = controlledObject.DelegateAccess();
                    securityTokens = delegatedAccess.SecurityTokens;
                    if (securityTokens != null && securityTokens.Any(v => v == null))
                    {
                        securityTokens = securityTokens.Where(v => v != null).ToArray();
                    }

                    var delegatedAccessDeniedPermissions = delegatedAccess.DeniedPermissions;
                    if (delegatedAccessDeniedPermissions != null && delegatedAccessDeniedPermissions.Length > 0)
                    {
                        this.deniedPermissions = this.Object.DeniedPermissions.Count > 0 ?
                                                 new HashSet <long>(this.Object.DeniedPermissions.Union(delegatedAccessDeniedPermissions).Select(v => v.Id)) :
                                                 new HashSet <long>(delegatedAccessDeniedPermissions.Select(v => v.Id));
                    }
                    else if (this.Object.DeniedPermissions.Count > 0)
                    {
                        this.deniedPermissions = new HashSet <long>(this.Object.DeniedPermissions.Select(v => v.Id));
                    }
                }
                else
                {
                    securityTokens = this.Object.SecurityTokens;

                    if (this.Object.DeniedPermissions.Count > 0)
                    {
                        this.deniedPermissions = new HashSet <long>(this.Object.DeniedPermissions.Select(v => v.Id));
                    }
                }

                if (securityTokens == null || securityTokens.Length == 0)
                {
                    var tokens = new SecurityTokens(session);
                    securityTokens = strategy.IsNewInSession
                                          ? new[] { tokens.InitialSecurityToken ?? tokens.DefaultSecurityToken }
                                          : new[] { tokens.DefaultSecurityToken };
                }

                this.accessControls = securityTokens.SelectMany(v => v.AccessControls)
                                      .Distinct()
                                      .Where(this.AccessControlLists.EffectivePermissionIdsByAccessControl.ContainsKey)
                                      .ToArray();

                this.permissionCache = session.GetCache <PermissionCache, PermissionCache>(() => new PermissionCache(session));
                this.permissionIdByOperationByOperandTypeId = this.permissionCache.PermissionIdByOperationByOperandTypeIdByClassId[this.classId];

                this.lazyLoaded = true;
            }
        }
示例#2
0
        public void CoreOnDerive(ObjectOnDerive method)
        {
            this.UnconfirmedNotifications = this.Notifications.Where(notification => !notification.Confirmed).ToArray();
            this.ConfirmedNotifications   = this.Notifications.Where(notification => notification.Confirmed).ToArray();

            if (!this.ExistSecurityTokens)
            {
                if (this.ExistUserWhereNotificationList)
                {
                    var defaultSecurityToken = new SecurityTokens(this.Session()).DefaultSecurityToken;
                    this.SecurityTokens = new[] { this.UserWhereNotificationList.OwnerSecurityToken, defaultSecurityToken };
                }
            }
        }
示例#3
0
        public static void AssignParticipants(this Task @this, IEnumerable <User> participants)
        {
            var session = @this.Strategy.Session;

            var participantSet = new HashSet <User>(participants.Where(v => v != null).Distinct());

            @this.DerivedRoles.Participants = participantSet.ToArray();

            // Manage Security
            var defaultSecurityToken = new SecurityTokens(session).DefaultSecurityToken;
            var securityTokens       = new HashSet <SecurityToken> {
                defaultSecurityToken
            };
            var ownerSecurityTokens = participantSet.Where(v => v.ExistOwnerSecurityToken).Select(v => v.OwnerSecurityToken);

            securityTokens.UnionWith(ownerSecurityTokens);
            @this.SecurityTokens = securityTokens.ToArray();

            // Manage TaskAssignments
            foreach (var currentTaskAssignement in @this.TaskAssignmentsWhereTask.ToArray())
            {
                var user = currentTaskAssignement.User;
                if (!participantSet.Contains(user))
                {
                    currentTaskAssignement.Delete();
                }
                else
                {
                    participantSet.Remove(user);
                }
            }

            foreach (var user in participantSet)
            {
                new TaskAssignmentBuilder(session)
                .WithTask(@this)
                .WithUser(user)
                .Build();
            }
        }