Skip to content

Commit

Permalink
Merge branch 'release/0.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashnikovisme committed Jan 19, 2017
2 parents 505315b + 67e7c6f commit f529357
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 15 deletions.
5 changes: 1 addition & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ gem 'doorkeeper'
gem 'responders', '~> 2.0'
gem 'kabal', '>= 1.3'
gem 'youtube_rails', github: 'luizpicolo/youtube_rails'

group :production do
gem 'unicorn-rails'
end
gem 'unicorn-rails'

group :development, :test do
gem 'byebug'
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Api::ActivityLines::Lider::YaLider::ApplicationController < Api::ApplicationController
before_filter :check_ya_lider_token
before_filter :authenticate
before_filter :check_ya_lider_token

private

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
class Api::ActivityLines::Lider::YaLider::ParticipantsController < Api::ActivityLines::Lider::YaLider::ApplicationController
skip_before_filter :verify_authenticity_token, only: :create

def create
user = User.confirmed.where(email: params[:user][:email]).first
if user
user.update_attributes! params[:user]
user_form = UserForm.new user
params[:user].each do |attr, value|
if user.try(attr).nil?
user_form.submit attr => value
end
end
create_participant user
else
user_form = ActivityLines::Lider::YaLider::ParticipantUserForm.new User.new
if user_form.save params[:user]
create_participant user_form
if user_form.submit params[:user]
create_participant user_form, avatar_update: true
else
User.tech_admins.each do |user|
send_notification user, user_form.model, :fail_participant_api_create
Expand All @@ -19,13 +26,26 @@ def create

private

def create_participant(user)
def create_participant(user, avatar_update: false)
params[:activity_lines_lider_ya_lider_participant] = {}
params[:activity_lines_lider_ya_lider_participant][:user_id] = user.id
params[:activity_lines_lider_ya_lider_participant][:contest_id] = ::ActivityLines::Lider::YaLider.current.first.id
params[:activity_lines_lider_ya_lider_participant][:fields_attributes] = {}
params[:user][:fields].each do |index, obj|
params[:activity_lines_lider_ya_lider_participant][:fields_attributes][index] = {
value: obj[:value],
title: obj[:title],
participant_id: obj[:user_id]
}
end
participant_form = ::ActivityLines::Lider::YaLider::ParticipantForm.new_with_model
if participant_form.submit params[:activity_lines_lider_ya_lider_participant]
first_stage = participant_form.model.contest.first_stage
ActivityLines::Lider::YaLider::Participation.create! participant_id: participant_form.model.id, stage_id: first_stage.id
head :ok
if avatar_update
user.model.update_attributes! remote_avatar_url: "#{configus.it_projects.ul_lider.url}#{params[:user][:avatar]}"
end
else
User.tech_admins.each do |user|
send_notification user, participant_form.model, :fail_api_create
Expand Down
15 changes: 15 additions & 0 deletions app/forms/activity_lines/lider/ya_lider/participant_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,19 @@ class ActivityLines::Lider::YaLider::ParticipantForm < ApplicationReform

validates :contest_id, presence: true
validates :user_id, presence: true

collection :fields, populate_if_empty: ::ActivityLines::Lider::YaLider::ParticipantField do
properties :value, :participant_id, :title

validates :value, presence: true
validates :title, presence: true
validates :participant_id, presence: true
end

def build_values!
titles = ::ActivityLines::Lider::YaLider::ParticipantField.title.values
titles.each do |title|
fields << model.fields.build(title: title)
end
end
end
18 changes: 16 additions & 2 deletions app/forms/activity_lines/lider/ya_lider/participant_user_form.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
class ActivityLines::Lider::YaLider::ParticipantUserForm < Reform::Form
properties :email, :first_name, :last_name, :patronymic, :birth_date, :municipality, :locality, :school, :mobile_phone,
:avatar
properties :email, :first_name, :last_name, :patronymic, :birth_date, :municipality, :locality, :school, :mobile_phone

validates :email, presence: true
validates :first_name, presence: true
validates :last_name, presence: true
validates :patronymic, presence: true
validates :birth_date, presence: true
validates :municipality, presence: true
validates :locality, presence: true
validates :school, presence: true
validates :mobile_phone, presence: true

def submit(params)
raise 'ApplicationForm::Params should not be nil' unless params
save if validate params
end
end
1 change: 1 addition & 0 deletions app/models/activity_lines/lider/ya_lider/participant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class ActivityLines::Lider::YaLider::Participant < ActiveRecord::Base
belongs_to :user
belongs_to :contest, class_name: 'ActivityLines::Lider::YaLider'
has_many :participations, class_name: 'ActivityLines::Lider::YaLider::Participation'
has_many :fields, class_name: 'ActivityLines::Lider::YaLider::ParticipantField'

state_machine :state, initial: :unviewed do
state :unviewed
Expand Down
4 changes: 4 additions & 0 deletions app/models/activity_lines/lider/ya_lider/participant_field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ActivityLines::Lider::YaLider::ParticipantField < ActiveRecord::Base
extend Enumerize
enumerize :title, in: [ :reason, :what_is_win_for_you, :quality, :if_i_have_one_million, :one_dream, :hobby, :life_plans ]
end
2 changes: 0 additions & 2 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class Member < User
enumerize :locality, in: Localities.list, default: Localities.list.first
enumerize :school, in: Schools.list

mount_uploader :avatar, AvatarUploader

state_machine :state, initial: :unviewed do
state :unviewed
state :confirmed
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class User < ActiveRecord::Base
validates :last_name, human_name: true,
allow_blank: true

mount_uploader :avatar, AvatarUploader

extend Enumerize
enumerize :role, in: [ :user, :admin, :author, :tech_admin ], default: :user

Expand Down
9 changes: 9 additions & 0 deletions bin/generates/ya_lider_token.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
current_ya_lider = ActivityLines::Lider::YaLider.where(state: :active,
contest_year: (DateTime.now.month > 8 ? DateTime.now.year + 1 : DateTime.now.year)).first
if current_ya_lider.tokens.any?
raise "You have already generated token".inspect
else
Token.create! record_id: current_ya_lider.id, record_type: 'ActivityLines::Lider::YaLider',
content: SecureHelper.generate_token
puts "#{Token.last.content}"
end
7 changes: 7 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@
resources :users, only: :show
end
resources :yofications, only: [ :create, :update ]
namespace :activity_lines do
namespace :lider do
namespace :ya_lider do
resources :participants, only: :create
end
end
end
end
namespace :rss do
resources :news, only: :index
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateActivityLinesLiderYaLiderParticipantFields < ActiveRecord::Migration
def change
create_table :activity_lines_lider_ya_lider_participant_fields do |t|
t.integer :participant_id
t.text :title
t.text :value

t.timestamps null: false
end
end
end
10 changes: 9 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170111010734) do
ActiveRecord::Schema.define(version: 20170119042814) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -69,6 +69,14 @@
t.integer "event_id"
end

create_table "activity_lines_lider_ya_lider_participant_fields", force: :cascade do |t|
t.integer "participant_id"
t.text "title"
t.text "value"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "activity_lines_lider_ya_lider_participants", force: :cascade do |t|
t.integer "contest_id"
t.integer "user_id"
Expand Down
5 changes: 5 additions & 0 deletions lib/configus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
env :development, parent: :staging do
host 'localhost:3000'
full_host 'http://localhost:3000'
it_projects do
ul_lider do
url 'http://localhost:3001'
end
end
end
env :test, parent: :development
end
3 changes: 2 additions & 1 deletion test/checks/mailer_subjects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class MailerSubjectsTest < ActionController::TestCase

setup do
exceptions = [ :activity_lines, :concerns, 'concerns/message_constructor.rb',
'activity_lines/corporative', 'activity_lines/corporative/online_conference' ].map(&:to_s)
'activity_lines/corporative', 'activity_lines/corporative/online_conference', 'activity_lines/lider',
'activity_lines/lider/ya_lider' ].map(&:to_s)
@mailers = Dir.glob('app/mailers/**/*').each { |m| m }.map do |m|
m.gsub('app/mailers/', '').gsub('_mailer.rb', '')
end.except(*exceptions)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FactoryGirl.define do
factory :activity_lines_lider_ya_lider_participant_field, :class => 'ActivityLines::Lider::YaLider::ParticipantField' do
participant_id 1
title "MyText"
value "MyText"
end

end

0 comments on commit f529357

Please sign in to comment.