예제 #1
0
        private async Task <RoleModel> LookupRole(UserCommonController users, string getArgument)
        {
            var roleModels = await users.Roles();

            return(roleModels.FirstOrDefault(x =>
                                             string.Equals(x.Name, getArgument, StringComparison.InvariantCultureIgnoreCase)));
        }
예제 #2
0
        private static async Task <List <string> > Roles(UserCommonController user, List <string> sourceRoles)
        {
            var roles = await user.Roles();

            return(roles.Where(x => sourceRoles.Contains(x.Name))
                   .SelectMany(x => x.Activities)
                   .Distinct()
                   .OrderBy(x => x)
                   .ToList());
        }
예제 #3
0
        public UserSpecification(UserCommonController user)
        {
            var safe = new Safe(_log);

            Name = "User";
            Field(d => d.Id).Description("The id of the user.");
            Field(d => d.Name).Description("The name of the user.");
            Field(d => d.Email).Description("The email of the user.");
            Field(d => d.Roles).Description("The roles of the user.");
            Field <ListGraphType <StringGraphType> >("activities", resolve: context => Roles(user, context.Source?.Roles));
//                .Description("The activities that this user is authorized for.");
            Field(d => d.UpdateDate, true, typeof(OriginalDateGraphType)).Description("The date when the user was last updated.");
            Field(d => d.CreateDate, type: typeof(OriginalDateGraphType)).Description("The date when the user was created.");
        }
예제 #4
0
 public UserController(UserCommonController userCommonController)
 {
     _userCommonController = userCommonController;
 }
예제 #5
0
        public UsersSpecification(UserCommonController users)
        {
            var safe    = new Safe(_log);
            var options = new GraphQlQueryOptions <UserCommonController, UserModel, User>(users);

            Name = "Users";

            Field <UserSpecification>(
                "byId",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> >
            {
                Name        = "id",
                Description = "id of the user"
            }
                    ),
                resolve: safe.Wrap(context => users.GetById(context.GetArgument <string>("id")))
                ).RequirePermission(Activity.ReadUsers);

            Field <ListGraphType <UserSpecification> >(
                "all",
                Description = "all users",
                resolve: context => users.Query(queryable => queryable)
                ).RequirePermission(Activity.ReadUsers);

            Field <ListGraphType <UserSpecification> >(
                "recent",
                Description = "recent modified users",
                new QueryArguments(
                    new QueryArgument <IntGraphType>
            {
                Name        = "first",
                Description = "id of the user"
            }
                    ),
                safe.Wrap(context => users
                          .Query(queryable =>
                                 queryable
                                 .OrderByDescending(x => x.UpdateDate)
                                 .Take(context.HasArgument("first") ? context.GetArgument <int>("first") : 100)
                                 ))
                ).RequirePermission(Activity.ReadUsers);

            Field <QueryResultSpecification>(
                "query",
                Description = "query the projects projects",
                options.GetArguments(),
                safe.Wrap(context => options.Query(context))
                ).RequirePermission(Activity.ReadUsers);


            Field <UserSpecification>(
                "me",
                Description = "Current user",
                resolve: safe.Wrap(context => Me(users))
                ).RequireAuthorization();


            Field <ListGraphType <RoleSpecification> >(
                "roles",
                Description = "All roles",
                resolve: safe.Wrap(context => users.Roles())
                );

            Field <RoleSpecification>(
                "role",
                Description = "All roles",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> >
            {
                Name        = "name",
                Description = "role name"
            }
                    ),
                resolve: safe.Wrap(context => LookupRole(users, context.GetArgument <string>("name")))
                );
        }
예제 #6
0
 private static async Task <UserModel> Me(UserCommonController users)
 {
     return(await users.WhoAmI());
 }
예제 #7
0
        public UsersMutationSpecification(UserCommonController userManager)
        {
            Name = "UsersMutation";
            var safe = new Safe(_log);

            Field <UserSpecification>(
                "insert",
                Description = "add a user",
                new QueryArguments(
                    new QueryArgument <UserCreateUpdateSpecification> {
                Name = Value
            }
                    ), safe.Wrap(context =>
            {
                var user = context.GetArgument <UserCreateUpdateModel>(Name = Value);
                return(userManager.Insert(user));
            })).RequirePermission(Activity.UpdateUsers);

            Field <UserSpecification>(
                "register",
                Description = "register a new user",
                new QueryArguments(
                    new QueryArgument <RegisterSpecification> {
                Name = Value
            }
                    ), safe.Wrap(context =>
            {
                var user = context.GetArgument <RegisterModel>(Name = Value);
                return(userManager.Register(user));
            }));

            Field <UserSpecification>(
                "update",
                Description = "update a user",
                new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id"
            },
                    new QueryArgument <UserCreateUpdateSpecification> {
                Name = Value
            }
                    ), safe.Wrap(context =>
            {
                var id   = context.GetArgument <string>(Name = "id");
                var user = context.GetArgument <UserCreateUpdateModel>(Name = Value);
                return(userManager.Update(id, user));
            })).RequirePermission(Activity.UpdateUsers);

            Field <BooleanGraphType>(
                "delete",
                Description = "permanently remove a user",
                new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id"
            }
                    ), safe.Wrap(context =>
            {
                var id = context.GetArgument <string>(Name = "id");
                return(userManager.Delete(id));
            })).RequirePermission(Activity.DeleteUser);
        }