Skip to content

Commit

Permalink
Merge branch 'hotfix/0.2.17_fix.3'
Browse files Browse the repository at this point in the history
* hotfix/0.2.17_fix.3:
  some fixes
  • Loading branch information
kalashnikovisme committed Jun 23, 2015
2 parents f41ce58 + 0ad3c5f commit afc0ed6
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 16 deletions.
28 changes: 22 additions & 6 deletions app/controllers/web/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,30 @@ def new
def create
@user_form = UserForm.new_with_model
@user_form.submit params[:user]
if @user_form.save
#TODO replace to observers
send_notification @user_form.model, @user_form.model, :after_create

sign_in @user_form.model
if check_exists_unavailable_member
redirect_to account_path
else
render action: :new
if @user_form.save
#TODO replace to observers
send_notification @user_form.model, @user_form.model, :after_create

sign_in @user_form.model
redirect_to account_path
else
render action: :new
end
end
end

private

def check_exists_unavailable_member
exists_member = Member.unavailable.find_by_email params[:user][:email]
if exists_member
exists_member.becomes! User
User.find(exists_member.id).update type: nil
User.find(exists_member.id).update state: :unviewed
sign_in exists_member
end
end
end
2 changes: 1 addition & 1 deletion app/forms/admin/member/unavailable_member_form.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Admin::Member::UnavailableMemberForm < ActiveForm::Base
self.main_model = :member

attributes :first_name, :last_name, :patronymic, :email, :motto, :ticket, :mobile_phone, :birth_date, :home_adress, :municipality, :locality, :avatar, :state, :type, :parent_id
attributes :first_name, :last_name, :patronymic, :email, :motto, :ticket, :mobile_phone, :birth_date, :home_adress, :municipality, :locality, :avatar, :state, :type, :parent_id, :school

association :positions do
attributes :title, :begin_date, :end_date, :member_id
Expand Down
1 change: 1 addition & 0 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Member < User
allow_blank: true
validates :motto, uniqueness: true,
allow_blank: true
validates :avatar, presence: true

include MemberScopes
enumerize :municipality, in: Municipalities.list, default: Municipalities.list.first
Expand Down
4 changes: 2 additions & 2 deletions app/scopes/news_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module NewsScopes
included do
scope :published, -> {
where('published_at <= ?', DateTime.now).
where.not(state: :removed).
where(state: :confirmed).
order('published_at DESC')
}
scope :unpublished, -> {
where('published_at > ?', DateTime.now).
where.not(state: :removed).
where(state: :confirmed).
order('published_at DESC')
}
scope :removed, -> { where state: :removed }
Expand Down
15 changes: 8 additions & 7 deletions app/views/web/users/account/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.container.mic-form-container.account-form
%h3.title
= t('.title')
- if @user.is_member?
- if @user.is_member? && !@user.unavailable?
- if @user.unviewed?
%span.label.warning
= t('.your_member_profile_is_unviewed')
Expand Down Expand Up @@ -47,7 +47,7 @@
= f.input :email, as: :string, required: true
= f.input :password, as: :string
= f.button :submit, t('helpers.links.save')
- unless @user.is_member?
- if !@user.is_member? || (@user.is_member? && @user.unavailable?)
- if @user.is_questionary?
%span.label
= t('.you_want_to_join_mic')
Expand All @@ -58,11 +58,12 @@
= t('.you_are_member_mic')
.medium-4.medium-offset-1.columns.end
= link_to t('.enter_datas_mic_member'), new_member_path, class: 'button'
.row
.medium-4.columns
= t('.you_are_not_member_mic')
.medium-4.medium-offset-1.columns.end
= link_to t('organization.send_request'), new_join_path, class: 'button'
- unless @user.is_member?
.row
.medium-4.columns
= t('.you_are_not_member_mic')
.medium-4.medium-offset-1.columns.end
= link_to t('organization.send_request'), new_join_path, class: 'button'
.row-fluid.authentications
%h3
= t('.authentications')
Expand Down
2 changes: 2 additions & 0 deletions test/factories/members.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
avatar { generate :file }
password { generate :string }
password_confirmation { password }
municipality 'г. Ульяновск'
locality 'г. Ульяновск'
end
end
2 changes: 2 additions & 0 deletions test/factories/questionaries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
state 'unviewed'
password { generate :string }
password_confirmation { password }
municipality 'г. Ульяновск'
locality 'г. Ульяновск'
end
end

0 comments on commit afc0ed6

Please sign in to comment.