Skip to content
This repository was archived by the owner on Nov 29, 2017. It is now read-only.
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
7 changes: 6 additions & 1 deletion app/controllers/v1/leaders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class LeadersController < ApplicationController

def intake
leader = Leader.new(
leader_params.merge(club_ids: [club_id], slack_team_id: TEAM_ID)
leader_params.merge(club_ids: [club_id], slack_username: slack_username,
slack_team_id: TEAM_ID)
)

if leader.save
Expand All @@ -24,6 +25,10 @@ def club_id
params[:club_id]
end

def slack_username
params[:slack_username].strip
end

def verify_club_id
return unless club_id.nil?
render json: { errors: { club_id: ["can't be blank"] } }, status: 422
Expand Down
6 changes: 6 additions & 0 deletions app/models/leader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Leader < ApplicationRecord
end

validates :name, presence: true
validate :validate_slack_username_found

def slack_update
return if access_token.nil?
Expand All @@ -80,6 +81,11 @@ def timezone

private

def validate_slack_username_found
return unless user_from_username(slack_username).nil?
errors.add(:slack_username, 'Slack user not found')
end

def slack_id_sync
info = SlackClient::Users.info(slack_id, access_token)[:user]
self.slack_username = info[:name] unless info.nil?
Expand Down