From adacc17c9cd93634a23e21b1e8a0a0f47815a7d4 Mon Sep 17 00:00:00 2001 From: AndySok Date: Mon, 29 Jun 2020 15:15:22 -0400 Subject: [PATCH 1/2] updated role creation --- app/graphql/resolvers/create_user.rb | 10 ++++++---- app/graphql/resolvers/update_user.rb | 11 +++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/graphql/resolvers/create_user.rb b/app/graphql/resolvers/create_user.rb index 299c299..ac71b36 100644 --- a/app/graphql/resolvers/create_user.rb +++ b/app/graphql/resolvers/create_user.rb @@ -5,7 +5,7 @@ class Resolvers::CreateUser < Resolvers::MutationFunction argument :email, !types.String argument :password, !types.String argument :password_confirmation, !types.String - argument :role, !types.String + argument :role, !types[types.String] argument :profile_picture_b64, as: :attachment do type types.String description 'The base64 encoded version of the profile picture.' @@ -34,9 +34,11 @@ def call(_obj, args, ctx) created_at: Time.now, profile_picture: args["attachment"] || nil, ) - role = Role.find_by(title: args["role"]) - if args["role"] and role != nil and !@new_user.roles.include?(role) - @new_user.roles << role + args["role"].each do |role| + roley = Role.find_by(title: role) + if roley and role != nil and !@new_user.roles.include?(roley) + @new_user.roles << roley + end end Authentication::generate_new_header(ctx) if @new_user.save! return @new_user diff --git a/app/graphql/resolvers/update_user.rb b/app/graphql/resolvers/update_user.rb index e2de371..9d597d9 100644 --- a/app/graphql/resolvers/update_user.rb +++ b/app/graphql/resolvers/update_user.rb @@ -4,7 +4,7 @@ class Resolvers::UpdateUser < Resolvers::MutationFunction argument :first_name, types.String argument :last_name, types.String argument :email, types.String - argument :role, types.String + argument :role, !types[types.String] argument :profile_picture_b64, as: :attachment do type types.String description 'The base64 encoded bersion of the attatchment to upload.' @@ -35,9 +35,12 @@ def call(_obj, args, ctx) save = "" if save =~ /\d/ else save @user.slug = args["first_name"].downcase + "-" + args["last_name"].downcase + save end - role = Role.find_by(title: args["role"]) - if args["role"] and role != nil and !@user.roles.include?(role) - @user.roles << role + @user.roles.clear + args["role"].each do |role| + roley = Role.find_by(title: role) + if roley and role != nil + @user.roles << roley + end end Authentication::generate_new_header(ctx) if @user.save! end From 33c6776ec0b70491b3dfd930045c1cb6e6095ec8 Mon Sep 17 00:00:00 2001 From: AndySok Date: Thu, 2 Jul 2020 18:40:15 -0400 Subject: [PATCH 2/2] fixed varnames --- app/graphql/resolvers/create_user.rb | 6 +++--- app/graphql/resolvers/update_user.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/graphql/resolvers/create_user.rb b/app/graphql/resolvers/create_user.rb index ac71b36..1270fe7 100644 --- a/app/graphql/resolvers/create_user.rb +++ b/app/graphql/resolvers/create_user.rb @@ -35,9 +35,9 @@ def call(_obj, args, ctx) profile_picture: args["attachment"] || nil, ) args["role"].each do |role| - roley = Role.find_by(title: role) - if roley and role != nil and !@new_user.roles.include?(roley) - @new_user.roles << roley + @role = Role.find_by(title: role) + if @role and role != nil and !@new_user.roles.include?(@role) + @new_user.roles << @role end end Authentication::generate_new_header(ctx) if @new_user.save! diff --git a/app/graphql/resolvers/update_user.rb b/app/graphql/resolvers/update_user.rb index 9d597d9..5afabc4 100644 --- a/app/graphql/resolvers/update_user.rb +++ b/app/graphql/resolvers/update_user.rb @@ -37,9 +37,9 @@ def call(_obj, args, ctx) end @user.roles.clear args["role"].each do |role| - roley = Role.find_by(title: role) - if roley and role != nil - @user.roles << roley + @role = Role.find_by(title: role) + if @role and role != nil + @user.roles << @role end end Authentication::generate_new_header(ctx) if @user.save!