Skip to content

Commit

Permalink
Merge branch 'release/0.5.5_patch.4'
Browse files Browse the repository at this point in the history
* release/0.5.5_patch.4:
  #FIX fix confession decorator
  #430 fix helpers names
  #430 add dates_helper
  #430 fix argument decorator
  #430 fix member_state
  #430 some refactoring. Add tests
  #430 fix decorators
  #430 fix user scope
  #430 fix scopes
  #430 fix auth logic
  • Loading branch information
kalashnikovisme committed Jan 10, 2016
2 parents 8867a05 + 53e1c72 commit 7b520e4
Show file tree
Hide file tree
Showing 72 changed files with 115 additions and 150 deletions.
14 changes: 3 additions & 11 deletions app/controllers/api/members/corporative/arguments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
class Api::Members::Corporative::ArgumentsController < Api::Members::Corporative::ApplicationController
def create
update_params
params[:arguments].keys.each do |index|
::ActivityLines::Corporative::ArgumentType.create! params[:arguments][index]
params[:arguments].each do |index, argument_params|
attrs = argument_params.merge({ member_id: current_user.id })
::ActivityLines::Corporative::ArgumentType.create! attrs
end
head :ok
end

private

def update_params
params[:arguments].keys.each do |index|
params[:arguments][index][:member_id] = current_user.id
end
end
end
9 changes: 3 additions & 6 deletions app/controllers/concerns/auth_managment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ def authenticate_confirmed_user!
end

def authenticate_member!
if signed_in?
unless current_user.is_member? && current_user.member_state == 'confirmed'
redirect_to not_found_page_path
end
else
redirect_to new_session_path
authenticate_user!
unless current_user.is_member? && current_user.member_confirmed?
redirect_to not_found_page_path
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/web/admin/questionaries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def update
@questionary_form = QuestionaryForm.find_with_model params[:id]
@questionary_form.submit params[:questionary]
if @questionary_form.save
if @questionary_form.model.member_state == 'confirmed'
if @questionary_form.model.member_confirmed?
User.update params[:id], type: 'Member'
#FIXME message in controller
redirect_to edit_admin_member_path(params[:id], message: :fill_member_form)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/web/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def show
@event = ::Event.find(params[:id]).decorate
organizers = @event.registrations.organizers
attenders = @event.registrations.attenders
@all_registrations = organizers + attenders
@all_registrations = Event::RegistrationDecorator.decorate_collection(organizers + attenders)
@registrations = @all_registrations.first 10
@other_registrations = @all_registrations.drop 10
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class Web::Members::Corporative::PetitionsController < Web::Members::Corporative::ApplicationController
before_filter :choose_members, only: [ :new, :edit ]

include DatesHelper

def new
if submissions_petitions_not_begins?
if !submissions_petitions_begins?
redirect_to not_found_page_path
elsif submissions_petitions_ends?
redirect_to page_page_path :confession_submissions_petitions_ends
Expand All @@ -15,7 +17,7 @@ def new
def create
if submissions_petitions_during?
confession_params = params[:activity_lines_corporative_confession]
confession_params[:year] = configus.dates.activity_lines.corporative.confession.begining_submissions_petitions.year
confession_params[:year] = current_confession_year
confession_params[:creator_id] = current_user.id
confession_params[:arguments_attributes].keys.each do |index|
confession_params[:arguments_attributes][index][:member_id] = current_user.id
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/web/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create

def show
member = Member.find_by_ticket(params[:ticket])
if member.member_state == 'confirmed'
if member.member_confirmed?
@member = member.decorate
@children = MemberDecorator.decorate_collection member.children.shuffle
@parent = MemberDecorator.decorate member.parent
Expand Down
2 changes: 2 additions & 0 deletions app/decorators/activity_line_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class ActivityLineDecorator < ApplicationDecorator
delegate_all

decorates_association :member

def short_body
"#{strip_tags(model.description)[0..50]}..."
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class ActivityLines::Corporative::ArgumentDecorator < ApplicationDecorator
delegate_all

def short_name
object.member.decorate.short_name
end
decorates_association :member
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class ActivityLines::Corporative::ConfessionDecorator < ApplicationDecorator
delegate_all

decorates_association :member

def short_name
object.member.decorate.short_name
object.member&.decorate.short_name
end

alias name short_name
Expand Down
10 changes: 1 addition & 9 deletions app/decorators/comment_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
class CommentDecorator < ApplicationDecorator
delegate_all

# Define presentation-specific methods here. Helpers are accessed through
# `helpers` (aka `h`). You can override attributes, for example:
#
# def created_at
# helpers.content_tag :span, class: 'time' do
# object.created_at.strftime("%a %m/%d/%y")
# end
# end

decorates_association :user
end
3 changes: 2 additions & 1 deletion app/decorators/event/registration_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class Event::RegistrationDecorator < Draper::Decorator
delegate_all

decorates_association :user

def localize_role
I18n.t("enumerize.event/registration.role.#{object.role}")
end

end
2 changes: 2 additions & 0 deletions app/decorators/event_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class EventDecorator < ApplicationDecorator
delegate_all

decorates_association :creator

def full_duration
if begin_date.day == end_date.day && begin_date.month == end_date.month && begin_date.year == end_date.year
"#{I18n.l(begin_date, format: '%d %b %Y')} #{begin_date.strftime('%H:%m')} - #{end_date.strftime('%H:%m')}"
Expand Down
2 changes: 2 additions & 0 deletions app/decorators/feedback_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class FeedbackDecorator < ApplicationDecorator
delegate_all

decorates_association :user
end
3 changes: 3 additions & 0 deletions app/decorators/member_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class MemberDecorator < UserDecorator
delegate_all

decorates_association :teams

def full_name
"#{first_name} #{patronymic} #{last_name}"
end
Expand Down
2 changes: 2 additions & 0 deletions app/decorators/news_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class NewsDecorator < ApplicationDecorator
delegate_all

decorates_association :member

def generate_lead
@sentences = strip_tags(model.body).split('.')
@finally_sen = "#{@sentences[0]}."
Expand Down
2 changes: 2 additions & 0 deletions app/decorators/position_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class PositionDecorator < ApplicationDecorator
delegate_all

decorates_association :member

def end_date_datetime
object.end_date ? I18n.l(object.end_date.to_datetime, format: '%d.%m.%Y') : object.end_date
end
Expand Down
2 changes: 2 additions & 0 deletions app/decorators/tag_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class TagDecorator < ApplicationDecorator
delegate_all

decorates_association :target

def just_text
case tag_type
when 'string'
Expand Down
3 changes: 1 addition & 2 deletions app/models/activity_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class ActivityLine < ActiveRecord::Base

enumerize :activity_type, in: [ :central_program, :local_project, :corporative, :event_line ]

include ActivityLineScopes

state_machine :state, initial: :active do
state :unviewed
state :active
Expand All @@ -27,6 +25,7 @@ class ActivityLine < ActiveRecord::Base
#FIXME tags association
include Concerns::TagsHelper

include ActivityLineScopes
include PgSearch
pg_search_scope :search_everywhere, against: [:title]
end
3 changes: 2 additions & 1 deletion app/models/activity_lines/corporative/confession.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class ActivityLines::Corporative::Confession < ActiveRecord::Base
validates :nomination, presence: true
validates :state, presence: true

include ActivityLines::Corporative::ConfessionScopes
extend Enumerize
enumerize :nomination, in: [ :debut, :number_one ]

Expand Down Expand Up @@ -43,6 +42,8 @@ class ActivityLines::Corporative::Confession < ActiveRecord::Base
end
end

include ActivityLines::Corporative::ConfessionScopes

include DatesHelper

def user_can_update_petition?(user_id)
Expand Down
6 changes: 3 additions & 3 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ class Article < ActiveRecord::Base
validates :category_id, presence: true
validates :user_id, presence: true

include ArticleScopes
include Concerns::ViewsManagment

state_machine :state, initial: :unviewed do
state :unviewed
state :confirmed
Expand All @@ -32,6 +29,9 @@ class Article < ActiveRecord::Base
transition all => :inactive
end
end

include ArticleScopes
include Concerns::ViewsManagment
include PgSearch
pg_search_scope :search_everywhere, against: [:title, :body, :view]
end
6 changes: 3 additions & 3 deletions app/models/banner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ class Banner < ActiveRecord::Base
validate :check_dimensions
validate :one_of_images_presents

include BannerScopes
include Concerns::DurationManagment

state_machine :state, initial: :active do
state :active
state :unviewed
Expand All @@ -29,6 +26,9 @@ class Banner < ActiveRecord::Base
end
end

include BannerScopes
include Concerns::DurationManagment

include PgSearch
pg_search_scope :search_everywhere, against: [:link]

Expand Down
4 changes: 2 additions & 2 deletions app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class Category < ActiveRecord::Base
validates :parent_id, presence: false
validates :is_last, presence: false

include CategoryScopes

def self.get_by_parent_id(category_id, all_tree = false)
Category.where(parent_id: category_id).where.not(state: :removed)
end
Expand Down Expand Up @@ -59,6 +57,8 @@ def self.get_tree
end
end

include CategoryScopes

private
def initial_load
self.is_last = true if self.is_last == nil
Expand Down
4 changes: 2 additions & 2 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class Document < ActiveRecord::Base

mount_uploader :file, FileUploader

include DocumentScopes

state_machine :state, initial: :unviewed do
state :unviewed
state :active
Expand All @@ -23,4 +21,6 @@ class Document < ActiveRecord::Base
transition all => :unviewed
end
end

include DocumentScopes
end
6 changes: 3 additions & 3 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ class Event < ActiveRecord::Base

mount_uploader :main_photo, PhotoUploader

include EventScopes
include Concerns::DurationManagment

extend Enumerize
enumerize :organizer_type, in: [ 'Member', 'Team' ]

Expand Down Expand Up @@ -38,6 +35,9 @@ class Event < ActiveRecord::Base
#FIXME try fix active form
after_save :remove_empty_registrations

include EventScopes
include Concerns::DurationManagment

include PgSearch
pg_search_scope :search_everywhere, against: [:title, :description]

Expand Down
2 changes: 1 addition & 1 deletion app/models/event/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Event::Registration < ActiveRecord::Base
belongs_to :event
belongs_to :user

# validates :user_id, uniqueness: { scope: [ :event_id ] }
validates :user_id, uniqueness: { scope: [ :event_id ] }

include Event::RegistrationScopes
extend Enumerize
Expand Down
4 changes: 2 additions & 2 deletions app/models/feedback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class Feedback < ActiveRecord::Base
validates :url, presence: true
validates :user_id, presence: true

include FeedbackScopes

state_machine initial: :unviewed do
state :unviewed
state :fixing
Expand All @@ -23,4 +21,6 @@ class Feedback < ActiveRecord::Base
transition all => :declined
end
end

include FeedbackScopes
end
4 changes: 2 additions & 2 deletions app/models/letter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class Letter < ActiveRecord::Base

mount_uploader :file, FileUploader

include LetterScopes

state_machine :state, initial: :sended do
state :unviewed
state :sended
Expand All @@ -28,6 +26,8 @@ class Letter < ActiveRecord::Base
end
end

include LetterScopes

include PgSearch
pg_search_scope :search_everywhere, against: [:title, :receiver, :number, :executor_name]
end
5 changes: 3 additions & 2 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class Member < User
allow_blank: true
validates :avatar, presence: true

include MemberScopes
enumerize :municipality, in: Municipalities.list, default: Municipalities.list.first
enumerize :locality, in: Localities.list, default: Localities.list.first
enumerize :school, in: Schools.list
Expand Down Expand Up @@ -61,7 +60,7 @@ class Member < User
end
end

state_machine :member_state, initial: :unviewed do
state_machine :member_state, initial: :unviewed, namespace: :member do
state :unviewed
state :confirmed
state :declined
Expand All @@ -77,6 +76,8 @@ class Member < User
end
end

include MemberScopes

def has_auth_provider?(provider)
authentications.map do |authentication|
return authentication if authentication.provider == provider
Expand Down
Loading

0 comments on commit 7b520e4

Please sign in to comment.