Sha256: e8cfcbaed45e0d313af6b6210ea7e27e8d10d0925245d0d5957512e7bba3b856

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

# MessageTrain authorization
module MessageTrainAuthorization
  extend ActiveSupport::Concern

  protected

  def authorize_collective(collective, division)
    return false unless authorize_collective_access(collective)
    case division
    when :in, :ignored
      authorize_collective_receiving(collective)
    when :sent, :drafts
      authorize_collective_sending(collective)
    end
  end

  def authorize_collective_access(collective)
    return true if collective.allows_access_by? @box_user
    flash[:error] = :access_to_that_box_denied.l
    redirect_to main_app.root_url
    false
  end

  def authorize_collective_receiving(collective)
    return true if collective.allows_receiving_by? @box_user
    flash[:error] = :access_to_that_box_denied.l
    redirect_to message_train.collective_box_url(collective.path_part, :sent)
    false
  end

  def authorize_collective_sending(collective)
    return true if collective.allows_sending_by? @box_user
    flash[:error] = :access_to_that_box_denied.l
    redirect_to message_train.collective_box_url(collective.path_part, :in)
    false
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
message_train-0.7.6 app/controllers/concerns/message_train_authorization.rb
message_train-0.7.5 app/controllers/concerns/message_train_authorization.rb
message_train-0.7.3 app/controllers/concerns/message_train_authorization.rb
message_train-0.7.2 app/controllers/concerns/message_train_authorization.rb
message_train-0.7.1 app/controllers/concerns/message_train_authorization.rb