Sha256: c43c2f4d3e3ce042f46d0502e2bf5f352f6ea6247ab60cc01ef4305382a05b04

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

class ShipitController < ApplicationController
  layout 'shipit'

  helper Shipit::Engine.routes.url_helpers
  include Shipit::Engine.routes.url_helpers

  before_action :ensure_required_settings,
                :force_github_authentication,
                :set_variant

  # Respond to HTML by default
  respond_to :html

  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  private

  def ensure_required_settings
    return if Shipit.all_settings_present?

    render 'missing_settings'
  end

  def force_github_authentication
    if current_user.logged_in?
      team = Shipit.github_team
      if team && !current_user.in?(team.members)
        render text: "You must be a member of #{team.handle} to access this application.", status: :forbidden
      end
    else
      redirect_to Shipit::Engine.routes.url_helpers.github_authentication_path(origin: request.original_url)
    end
  end

  def current_user
    @current_user ||= find_current_user || AnonymousUser.new
  end
  helper_method :current_user

  def find_current_user
    return unless session[:user_id].present?
    User.find(session[:user_id])
  rescue ActiveRecord::RecordNotFound
  end

  def set_variant
    return unless request.negotiate_mime('text/partial+html')

    request.format = :html
    request.variant = :partial
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
shipit-engine-0.5.2 app/controllers/shipit_controller.rb
shipit-engine-0.5.1 app/controllers/shipit_controller.rb
shipit-engine-0.5.0 app/controllers/shipit_controller.rb
shipit-engine-0.4.10 app/controllers/shipit_controller.rb
shipit-engine-0.4.9 app/controllers/shipit_controller.rb