Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

add new routes for frontend authentication and user flow #473

Open
wants to merge 9 commits into
base: master
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
223 changes: 201 additions & 22 deletions apiary.apib
Original file line number Diff line number Diff line change
Expand Up @@ -1713,16 +1713,39 @@ API endpoints that Operation Code's Rails backend makes available to its React f
{
errors: "Some error message"
}
## User | Create [/api/v1/users{?first_name,last_name,email,zip,password,mentor}]
## User | Create [/api/v1/users{?first_name,last_name,email,zip,password,bio,verified,state,address1,address2,city,username,volunteer,branch_of_service,years_of_service,pay_grade,military_occupational_speciality,github,twitter,linked_in,mentor,employment_status,education,military_status,company_role,company_name,education_level,scholarship_info,interests}]

+ Parameters

+ first_name (string, required) - First Name of the user in the form of an string
+ last_name (string, required) - Last Name of the user in the form of an string
+ email (string, required) - Email of the User in the form of a string
+ zip (string, required) - Zipcode of the User in the form of a string
+ first_name (string, required) - First Name of the user in the form of an string
+ last_name (string, required) - Last Name of the user in the form of an string
+ mentor (string, optional) - in the form of a string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a boolean

+ password (string, required) - Password of the User in the form on a string
+ mentor (boolean, optional) - Is User requesting mentor in the form of a boolean
+ bio (string, optional) - in the form of a string
+ verified (string, optional) - in the form of a string
+ state (string, optional) - in the form of a string
+ address1 (string, optional) - in the form of a string
+ address2 (string, optional) - in the form of a string
+ city (string, optional) - in the form of a string
+ username (string, optional) - in the form of a string
+ volunteer (string, optional) - in the form of a string
+ branch_of_service (string, optional) - in the form of a string
+ years_of_service (string, optional) - in the form of a string
+ pay_grade (string, optional) - in the form of a string
+ military_occupational_speciality (string, optional) - in the form of a string
+ github (string, optional) - in the form of a string
+ twitter (string, optional) - in the form of a string
+ linked_in (string, optional) - in the form of a string
+ employment_status (string, optional) - in the form of a string
+ education (string, optional) - in the form of a string
+ military_status (string, optional) - in the form of a string
+ company_role (string, optional) - in the form of a string
+ company_name (string, optional) - in the form of a string
+ education_level (string, optional) - in the form of a string
+ scholarship_info (boolean, optional) - in the form of a string
+ interests (string, optional) - in the form of a string

### Create new user record [POST]

Expand All @@ -1731,11 +1754,37 @@ API endpoints that Operation Code's Rails backend makes available to its React f
+ Body

{
first_name: "Mike",
last_name: "Johnson",
email: "[email protected]",
password: "hunter2",
zip: "80020",
mentor: "true"
first_name: "Mike",
last_name: "Johnson",
bio: "Information",
verified: false,
state: "NC",
address1: "My address",
address2: "PO BOX",
city: "My city",
username: "mike house"
volunteer: "false",
branch_of_service: "Air Force",
years_of_service: "100",
pay_grade: "0",
military_occupational_speciality: "3N",
github: "user_name",
twitter: "user_name",
linked_in: "user_name",
mentor: "true",
education_level: "College Graduate",
scholarship_info: "true",
employment_status: "Employed",
education: "BS",
military_status: "spouse",
company_role: "Developer",
company_name: "Comcast",
education_level: "BS",
scholarship_info: "True",
interests: "Python, Python, Python, Python"
}


Expand All @@ -1751,6 +1800,96 @@ API endpoints that Operation Code's Rails backend makes available to its React f
errors: "Some error message"
}

## User | Exists [/api/v1/users/email/{email}]

+ Parameters

+ email (string, required) - User email in form of a string

### Checks if a user currently exists [GET]

+ Request (application/json)

+ Response 200 (application/json)
+ Body

{
status: "ok"
}

+ Response 422 (application/json)
+ Body

{
status: "Unprocessable Entity"
}

## User | Me [/api/v1/users{?email}]

+ Parameters

+ email (string, required) - Email of the User in the form of a string

### Get full details for a specific user [GET]

+ Request (application/json)

+ Headers

Authorization: Bearer Access-Token

+ Response 200 (application/json)

+ Body

{
email: "[email protected]",
zip: "80020",
first_name: "Mike",
last_name: "Johnson",
bio: "Information",
verified: false,
state: "NC",
address1: "My address",
address2: "PO BOX",
city: "My city",
username: "mike house"
volunteer: "false",
branch_of_service: "Air Force",
years_of_service: "100",
pay_grade: "0",
military_occupational_speciality: "3N",
github: "user_name",
twitter: "user_name",
linked_in: "user_name",
mentor: "true",
education_level: "College Graduate",
scholarship_info: "true",
employment_status: "Employed",
education: "BS",
military_status: "spouse",
company_role: "Developer",
company_name: "Comcast",
education_level: "BS",
scholarship_info: "True",
interests: "Python, Python, Python, Python"
}

+ Response 422 (application/json)

+ Body

{
status: "Unprocessable Entity"
}

+ Response 404 (application/json)

{
error: 'No such record'
}


## User | Reset Password [/api/v1/users/passwords/reset{?email}]

+ Parameters
Expand Down Expand Up @@ -1798,20 +1937,39 @@ API endpoints that Operation Code's Rails backend makes available to its React f
{
errors: "Some error message"
}
## User | Update [/api/v1/users{?education_level,mentor,scholarship_info,employment_status,company_name,company_role,volunteer,military_status,branch_of_service,interests}]
## User | Update [/api/v1/users{?first_name,last_name,email,zip,password,mentor,bio,verified,state,address1,address2,city,username,volunteer,branch_of_service,years_of_service,pay_grade,military_occupational_speciality,github,twitter,linked_in,employment_status,education,military_status,company_role,company_name,education_level,scholarship_info,interests}]

+ Parameters

+ education_level (string, optional) - Users highest level of education in the form of a string
+ first_name (string, required) - First Name of the user in the form of an string
+ last_name (string, required) - Last Name of the user in the form of an string
+ email (string, required) - Email of the User in the form of a string
+ zip (string, required) - Zipcode of the User in the form of a string
+ password (string, required) - Password of the User in the form on a string
+ mentor (boolean, optional) - Is User requesting mentor in the form of a boolean
+ scholarship_info (boolean, optional) - Is User interested in scholarship info in the form of a boolean
+ employment_status (string, optional) - Users employment status in the form of a string
+ company_name (string, optional) - Users name of employer in the form on a string
+ company_role (string, optional) - Users role at company in the form of a string
+ volunteer (boolean, optional) - Is User wanting to volunteer in the form of a boolean
+ military_status (string, optional) - Users military status, either current, veteran, spouse, or blank
+ branch_of_service (string, optional) - Users branch of service in the form of a string
+ interests (string, optional) - User interests in the form of a string.
+ bio (string, optional) - in the form of a string
+ verified (string, optional) - in the form of a string
+ state (string, optional) - in the form of a string
+ address1 (string, optional) - in the form of a string
+ address2 (string, optional) - in the form of a string
+ city (string, optional) - in the form of a string
+ username (string, optional) - in the form of a string
+ volunteer (string, optional) - in the form of a string
+ branch_of_service (string, optional) - in the form of a string
+ years_of_service (string, optional) - in the form of a string
+ pay_grade (string, optional) - in the form of a string
+ military_occupational_speciality (string, optional) - in the form of a string
+ github (string, optional) - in the form of a string
+ twitter (string, optional) - in the form of a string
+ linked_in (string, optional) - in the form of a string
+ employment_status (string, optional) - in the form of a string
+ education (string, optional) - in the form of a string
+ military_status (string, optional) - in the form of a string
+ company_role (string, optional) - in the form of a string
+ company_name (string, optional) - in the form of a string
+ education_level (string, optional) - in the form of a string
+ scholarship_info (boolean, optional) - in the form of a string
+ interests (string, optional) - in the form of a string

### Update user record [PATCH]

Expand All @@ -1824,15 +1982,36 @@ API endpoints that Operation Code's Rails backend makes available to its React f
+ Body

{
education_level: "College Graduate" ,
email: "[email protected]",
password: "hunter2",
zip: "80020",
first_name: "Mike",
last_name: "Johnson",
bio: "Information",
verified: false,
state: "NC",
address1: "My address",
address2: "PO BOX",
city: "My city",
username: "mike house"
volunteer: "false",
branch_of_service: "Air Force",
years_of_service: "100",
pay_grade: "0",
military_occupational_speciality: "3N",
github: "user_name",
twitter: "user_name",
linked_in: "user_name",
mentor: "true",
education_level: "College Graduate",
scholarship_info: "true",
employment_status: "Employed",
company_name: "Comcast",
company_role: "Developer",
education: "BS",
military_status: "spouse",
volunteer: "false",
branch_of_service: "Air Force",
company_role: "Developer",
company_name: "Comcast",
education_level: "BS",
scholarship_info: "True",
interests: "Python, Python, Python, Python"
}

Expand Down
26 changes: 23 additions & 3 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Api
module V1
class UsersController < ApiController
before_action :authenticate_user!, only: %i[update]
before_action :authenticate_user!, only: %i[update me]

def index
render json: { user_count: User.count }, status: :ok
Expand All @@ -13,7 +13,8 @@ def create
user = User.new(user_params)

if user.save
user.welcome_user
user.invite_to_slack
user.add_to_send_grid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should probably occur after sign_in right? Unsure why user.welcome_user was listed before UserMailer.welcome(user).deliver unless user.invalid?

UserMailer.welcome(user).deliver unless user.invalid?
sign_in(user)
render json: { token: user.token }
Expand Down Expand Up @@ -53,6 +54,25 @@ def by_location
render json: { errors: e.message }, status: :unprocessable_entity
end

def by_email
user = User.find_by(email: params[:email])
if user
Rails.logger.debug "search by email successful #{request.env}"
render json: { status: :ok }, status: :ok
else
Rails.logger.debug "search by email not found from request: #{request.env}"
render json: { status: :not_found }, status: :not_found
end
end

def me
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's happening in this method?

# Rails.logger.debug "search by email for authed user email: #{current_user}"
render json: ComplexUserSerializer.new(current_user), status: :ok
rescue StandardError => e
Rails.logger.debug "search by email errored: #{current_user} error: #{e}"
render json: { status: :unprocessable_entity }, status: :unprocessable_entity
end

private

def user_params
Expand All @@ -68,6 +88,7 @@ def user_params
:state,
:address1,
:address2,
:city,
:username,
:volunteer,
:branch_of_service,
Expand All @@ -84,7 +105,6 @@ def user_params
:company_name,
:education_level,
:scholarship_info,
:role_id,
interests: []
)
end
Expand Down
1 change: 1 addition & 0 deletions app/jobs/add_user_to_send_grid_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class AddUserToSendGridJob < ApplicationJob

def perform(user_id)
user = User.find(user_id)

SendGridClient.new.add_user(user)
end
end
8 changes: 7 additions & 1 deletion app/lib/slack/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def initialize(subdomain:, token:)
end

def invite(extra_message:, email:, channels: [])
Rails.logger.info "Inviting user with email '#{email}'"
# unsure if some string expansion is causing an error here
Rails.logger.info 'Inviting slack user user'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can prolly delete this line and comment above

Rails.logger.info "Inviting slack user user with email #{email}"
body = send_api_request(
to: INVITE_PATH,
payload: {
Expand All @@ -40,6 +42,10 @@ def invite(extra_message:, email:, channels: [])
end

true
rescue StandardError => e
Rails.logger.warn "Some Exception occured while inviting slack user #{e}"
# want to reraise the exception so the job retries
raise
end

def post_message_to(channel:, with_text:)
Expand Down
9 changes: 4 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,16 @@ def name
"#{first_name} #{last_name}"
end

def welcome_user
add_to_send_grid
invite_to_slack
end

def invite_to_slack
SlackJobs::InviterJob.perform_async(self.email)
rescue StandardError => e
Rails.logger.warn "Error occured when trying to add to job queue for slack invite #{e}"
end

def add_to_send_grid
AddUserToSendGridJob.perform_async(self.id)
rescue StandardError => e
Rails.logger.warn "Error occured when trying to add to job queue for sendgrid #{e}"
end

def token
Expand Down
Loading