Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated role creation #176

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/graphql/resolvers/create_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down Expand Up @@ -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|
@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!
return @new_user
Expand Down
11 changes: 7 additions & 4 deletions app/graphql/resolvers/update_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down Expand Up @@ -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 [email protected]?(role)
@user.roles << role
@user.roles.clear
args["role"].each do |role|
@role = Role.find_by(title: role)
if @role and role != nil
@user.roles << @role
end
end
Authentication::generate_new_header(ctx) if @user.save!
end
Expand Down