rosa-build/app/controllers/platforms/tokens_controller.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

2013-06-25 08:01:03 +01:00
class Platforms::TokensController < Platforms::BaseController
2015-03-04 23:19:19 +00:00
before_action :authenticate_user!
load_resource :platform
load_and_authorize_resource :through => :platform, :shallow => true
def index
2013-06-26 09:04:40 +01:00
authorize! :local_admin_manage, @platform
@tokens = @platform.tokens.includes(:creator, :updater)
2014-01-21 04:51:49 +00:00
.paginate(per_page: 20, page: params[:page])
end
def show
end
def withdraw
2014-01-21 04:51:49 +00:00
if @token.block
@token.updater = current_user
@token.save
2014-01-21 04:51:49 +00:00
redirect_to :back, notice: t('flash.tokens.withdraw_success')
else
2014-01-21 04:51:49 +00:00
redirect_to :back, notice: t('flash.tokens.withdraw_fail')
end
end
def new
end
def create
@token = @platform.tokens.build params[:token]
@token.creator = current_user
if @token.save
flash[:notice] = t('flash.tokens.saved')
redirect_to platform_tokens_path(@platform)
else
flash[:error] = t('flash.tokens.save_error')
flash[:warning] = @token.errors.full_messages.join('. ') unless @token.errors.blank?
render :new
end
end
end