コード例 #1
0
ファイル: TradeService.cs プロジェクト: philmiller84/Need4
        public override Task <State> AddTradeUserState(TradeUserInfo request, ServerCallContext context)
        {
            State st = new State();

            if (request.UnauthenticatedUser != null)
            {
                return(Task.FromResult(st));
            }
            try
            {
                var q     = from x in db.States where request.State.Description == x.Description select x;
                var state = q.First();

                var r = from x in db.TradeUsers where x.TradeId == request.TradeId && x.UserId == request.AuthenticatedUserId select x;

                if (r.Count() > 0)
                {
                    r.First().State = state;
                    db.SaveChanges();
                }
                else
                {
                    TradeUser t = new TradeUser {
                        State = state, TradeId = request.TradeId, UserId = request.AuthenticatedUserId
                    };
                    this.GenericCreate(db, t);
                }
            }
            catch
            {
                return(null);
            }

            return(Task.FromResult(st));
        }
コード例 #2
0
ファイル: TradeService.cs プロジェクト: philmiller84/Need4
 private int?GetTradeRelationship(TradeUserInfo request)
 {
     return((from tu in db.TradeUsers
             .Include(d => d.State)
             where tu.TradeId == request.TradeId && tu.UserId == request.AuthenticatedUserId
             select tu).FirstOrDefault()?.Id);
 }
コード例 #3
0
ファイル: TradeService.cs プロジェクト: philmiller84/Need4
        public override Task <State> GetTradeUserState(TradeUserInfo request, ServerCallContext context)
        {
            State st = new State();

            if (request.UnauthenticatedUser != null)
            {
                return(Task.FromResult(st));
            }

            try
            {
                RelationshipType relationshipType = new RelationshipType {
                    Id = (int)_RelationshipType.ID.TRADE_USER
                };
                Relation relation = new Relation {
                    Key1 = request.TradeId, Key2 = request.AuthenticatedUserId
                };
                int relationId = GetRelationId(relationshipType, relation).Result.Value;

                Relationship relationship = new Relationship {
                    Id = relationId, Relation = relation, RelationshipType = relationshipType
                };
                st = GetRelationshipState(relationship, context).Result;
                return(Task.FromResult(st));
            }
            catch
            {
                return(Task.FromResult(st));
            }
        }
コード例 #4
0
ファイル: TradeService.cs プロジェクト: philmiller84/Need4
        private bool CheckTradeExists(TradeUserInfo request)
        {
            var q = from t in db.Trades
                    where t.Id == request.TradeId
                    select t;

            return(q.Count() > 0);
        }
コード例 #5
0
ファイル: TradeService.cs プロジェクト: philmiller84/Need4
        private Trade GetDetailedTradeView(TradeUserInfo request, ServerCallContext context)
        {
            Trade trade = new Trade();
            var   q     = from t in db.Trades
                          .Include(l => l.TradeItemList)
                          .ThenInclude(y => y.TradeItemDetails)
                          .ThenInclude(z => z.Item)
                          where t.Id == request.TradeId
                          select t;

            return(q.First());
        }
コード例 #6
0
ファイル: TradeService.cs プロジェクト: philmiller84/Need4
        public override Task <PermissionSet> GetPermissions(TradeUserInfo request, ServerCallContext context)
        {
            PermissionSet ps = new PermissionSet();

            if (request.UnauthenticatedUser != null)
            {
                return(Task.FromResult(ps));
            }

            try
            {
                RelationshipType tradeUserType = new RelationshipType {
                    Id = (int)_RelationshipType.ID.TRADE_USER
                };
                int?relationId = GetRelationId(tradeUserType, new Relation {
                    Key1 = request.TradeId, Key2 = request.AuthenticatedUserId
                }).Result;

                if (relationId != null)
                {
                    Permission permissionRequest = new Permission {
                        RelationshipType = tradeUserType, RelationId = relationId.Value
                    };
                    var permissionSet = GetPermissionSet(permissionRequest);
                    ps.Permissions.AddRange(permissionSet);
                }
                int memberId    = GetActiveMemberIdForUser(request.AuthenticatedUserId);
                int communityId = GetCommunityForMember(memberId);
                RelationshipType communityMemberType = new RelationshipType {
                    Id = (int)_RelationshipType.ID.COMMUNITY_MEMBER
                };
                relationId = GetRelationId(communityMemberType, new Relation {
                    Key1 = communityId, Key2 = memberId
                }).Result;

                if (relationId != null)
                {
                    Permission permissionRequest = new Permission {
                        RelationshipType = communityMemberType, RelationId = relationId.Value
                    };
                    var permissionSet = GetPermissionSet(permissionRequest);
                    ps.Permissions.AddRange(permissionSet);
                }

                return(Task.FromResult(ps));
            }
            catch
            {
                return(Task.FromResult(ps));
            }
        }
コード例 #7
0
        protected virtual void InitializeParameters()
        {
            base.OnParametersSet();
            tradeUserInfo = user != null ?
                            new TradeUserInfo {
                AuthenticatedUserId = user.Id, TradeId = tradeId
            } :
            new TradeUserInfo {
                UnauthenticatedUser = new Empty(), TradeId = tradeId
            };

            actionKeyValuePairs = new Dictionary <string, string> {
                { "tradeId", tradeId.ToString() }
            };
        }
コード例 #8
0
ファイル: TradeService.cs プロジェクト: philmiller84/Need4
        public override Task <ActionList> GetTradeActions(TradeUserInfo request, ServerCallContext context)
        {
            ActionList t = new ActionList();

            if (request.UnauthenticatedUser != null || !CheckTradeExists(request))
            {
                return(Task.FromResult(t));
            }

            request.State = GetTradeUserState(request, context).Result;

            Task <PermissionSet>    permissionSet = GetPermissions(request, context);
            IQueryable <Permission> permissions   = permissionSet.Result.Permissions.AsQueryable <Permission>();

            try
            {
                var stateId    = request.State.Id;
                var nextStates = GetAvailableTradeUserActionsForState(stateId);

                string actionCategory = _Categories.TRADE_ACTION;

                var permissionedActions =
                    from ps in permissions
                    join r in db.Requirements on new { rti = ps.RelationshipTypeId, pti = ps.PermissionTypeId } equals new { rti = r.RelationshipTypeId, pti = r.PermissionTypeId }
                select r.ActionId;

                var nextActions =
                    from ps in permissionedActions
                    join a in db.ActionDetails
                    on ps equals a.Id
                    where a.Category == actionCategory && nextStates.Contains(a.Id)
                    select a;

                t.Actions.AddRange(nextActions);
            }
            catch
            {
                return(null);
            }

            return(Task.FromResult(t));
        }
コード例 #9
0
ファイル: TradeService.cs プロジェクト: philmiller84/Need4
        public override Task <PermissionSet> CheckPermissions(TradeUserInfo request, ServerCallContext context)
        {
            PermissionSet ps = GetPermissions(request, context).Result;

            if (request.UnauthenticatedUser != null)
            {
                return(Task.FromResult(ps));
            }

            if (ps.Permissions.Count == 0)
            {
                Task <State> state = GetTradeUserState(request, context);

                if (state.Result == null)
                {
                    return(Task.FromResult(ps));
                }

                if (state.Result.Id == (int)_States._TradeUser.ID.IOI)
                {
                    RelationshipType relationshipType = new RelationshipType {
                        Name = _Tables.TRADE_USER
                    };
                    PermissionType permissionType = new PermissionType {
                        Name = _Permissions.JOIN
                    };
                    PermissionRequest permissionRequest = new PermissionRequest
                    {
                        PermissionType   = permissionType,
                        RelationshipType = relationshipType,
                        Key1             = request.TradeId,
                        Key2             = request.AuthenticatedUserId
                    };

                    AddPermission(permissionRequest, context);
                }
            }
            return(Task.FromResult(ps));
        }
コード例 #10
0
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, BasicCommunityRequirement requirement, Trade resource)
        {
            string email = Helpers.Claims.GetEmail(context.User.Claims);

            if (email == null)
            {
                return(null);
            }

            Need4Service service = new Need4Service();

            UserService.UserServiceClient userClient = service.GetUserClient();
            Need4Protocol.User            user       = userClient.GetUser(new Need4Protocol.User {
                Email = email
            });

            TradeUserInfo tradeUserInfo = user != null ?
                                          new TradeUserInfo {
                AuthenticatedUserId = user.Id, TradeId = resource.Id
            } :
            new TradeUserInfo {
                UnauthenticatedUser = new Empty(), TradeId = resource.Id
            };

            TradeService.TradeServiceClient tradeClient = service.GetTradeClient();
            PermissionSet permissions = tradeClient.GetPermissions(tradeUserInfo);

            bool hasJoinTradePermission = (from p in permissions.Permissions
                                           where p.PermissionType.Name == _Permissions.BASIC
                                           select p).Any();

            if (hasJoinTradePermission)
            {
                context.Succeed(requirement);
            }

            return(Task.CompletedTask);
        }
コード例 #11
0
ファイル: Joins.cs プロジェクト: philmiller84/Need4
 public TradeUser(TradeUserInfo r)
 {
     TradeId = r.TradeId;
     UserId  = r.AuthenticatedUserId;
     State   = null;
 }