Sha256: 59d01e07cacf3f45132a9c2f4846bc7a1ff140a598e0f7d5246b9bdc7b8ef4b7

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

class ShipitController < ApplicationController
  layout 'shipit'

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

  before_action :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 force_github_authentication
    return unless Shipit.github_required?

    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 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

1 entries across 1 versions & 1 rubygems

Version Path
shipit-engine-0.0.1.pre app/controllers/shipit_controller.rb