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!
|
2013-06-25 08:00:20 +01:00
|
|
|
|
2015-04-03 22:37:37 +01:00
|
|
|
before_action :load_token, except: [:index, :create, :new]
|
2013-06-25 08:00:20 +01:00
|
|
|
|
|
|
|
def index
|
2015-04-03 22:37:37 +01:00
|
|
|
authorize @platform, :local_admin_manage?
|
2013-06-25 08:00:20 +01:00
|
|
|
@tokens = @platform.tokens.includes(:creator, :updater)
|
2014-01-21 04:51:49 +00:00
|
|
|
.paginate(per_page: 20, page: params[:page])
|
2013-06-25 08:00:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def withdraw
|
2014-01-21 04:51:49 +00:00
|
|
|
if @token.block
|
2013-06-25 09:10:45 +01:00
|
|
|
@token.updater = current_user
|
|
|
|
@token.save
|
2014-01-21 04:51:49 +00:00
|
|
|
redirect_to :back, notice: t('flash.tokens.withdraw_success')
|
2013-06-25 08:00:20 +01:00
|
|
|
else
|
2014-01-21 04:51:49 +00:00
|
|
|
redirect_to :back, notice: t('flash.tokens.withdraw_fail')
|
2013-06-25 08:00:20 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2015-04-03 22:37:37 +01:00
|
|
|
authorize @token = @platform.tokens.new
|
2013-06-25 08:00:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-05-20 22:52:50 +01:00
|
|
|
@token = @platform.tokens.build token_params
|
2013-06-25 08:00:20 +01:00
|
|
|
@token.creator = current_user
|
2015-04-03 22:37:37 +01:00
|
|
|
authorize @token
|
2013-06-25 08:00:20 +01:00
|
|
|
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
|
|
|
|
|
2015-04-03 22:37:37 +01:00
|
|
|
protected
|
|
|
|
|
2015-05-20 22:52:50 +01:00
|
|
|
def token_params
|
|
|
|
subject_params(Token)
|
|
|
|
end
|
|
|
|
|
2015-04-03 22:37:37 +01:00
|
|
|
# Private: before_action hook which loads Repository.
|
|
|
|
def load_token
|
|
|
|
authorize @token = @platform.tokens.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2013-06-25 08:00:20 +01:00
|
|
|
end
|