// TODO This is assigning new users default claims to the group, to be moved to its own table
        /// <summary>
        /// Assign the user claims to resources for a newly created relationship with a group
        /// </summary>
        /// <param name="relation">the user/group relationship</param>
        private void AssignUserResourceClaims(ActorRelationship relation)
        {
            relation.Requestor = _actorController.Get(relation.RequestorId);
            relation.Acceptor  = _actorController.Get(relation.AcceptorId);
            // Group to user relationship
            if (relation.Requestor.ActorType == ActorType.Group && relation.Acceptor.ActorType == ActorType.User || relation.Acceptor.ActorType == ActorType.Group && relation.Requestor.ActorType == ActorType.User)
            {
                // Get user
                var user = relation.Requestor.ActorType == ActorType.User
                                    ? relation.Requestor
                                    : relation.Acceptor;

                var group = relation.Requestor.ActorType == ActorType.Group
                                    ? relation.Requestor
                                    : relation.Acceptor;

                var GetClaim    = _claimController.Get(ClaimScope.Group, "Get-Resource");
                var CreateClaim = _claimController.Get(ClaimScope.Group, "Create-Resource");
                var UpdateClaim = _claimController.Get(ClaimScope.Group, "Update-Resource");
                if (GetClaim != null)
                {
                    var getActorClaim = new ActorClaim
                    {
                        ActorId  = user.Id,
                        ClaimId  = GetClaim.Id,
                        EntityId = group.Id,
                    };
                    _actorClaimController.Create(getActorClaim);
                }
                if (UpdateClaim != null)
                {
                    var updateActorClaim = new ActorClaim
                    {
                        ActorId  = user.Id,
                        ClaimId  = UpdateClaim.Id,
                        EntityId = group.Id,
                    };
                    _actorClaimController.Create(updateActorClaim);
                }
                if (CreateClaim != null)
                {
                    var createActorClaim = new ActorClaim
                    {
                        ActorId  = user.Id,
                        ClaimId  = CreateClaim.Id,
                        EntityId = group.Id,
                    };
                    _actorClaimController.Create(createActorClaim);
                }
            }
        }
예제 #2
0
        public Actor Get(int actorId, ActorVisibilityFilter actorVisibilityFilter = ActorVisibilityFilter.Public)
        {
            var actor = _actorDbController.Get(actorId);

            return(actor.FilterVisibility(actorVisibilityFilter));
        }