Merge branch 'standalone_develop' of https://gitlink.org.cn/Trustie/forgeplus into standalone_develop
This commit is contained in:
commit
8e25db5122
|
@ -8,18 +8,17 @@ class InstallationsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@install_bots = BotInstall.where(:installer_id => current_user.id)
|
@install_bots = BotInstall.where(bot_id: get_bot_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@install_bot = BotInstall.find params[:id]
|
@install_bot = BotInstall.find_by(bot_id: get_bot_id, installer_id: params[:id]) || BotInstall.find_by(id: params[:id])
|
||||||
|
tip_exception "参数installer_id错误" if @install_bot.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def repositories
|
def repositories
|
||||||
# 与github差异,所以取安装用户和bot对应所有的仓库
|
# 与github差异,所以取安装用户和bot对应所有的仓库
|
||||||
install_bot = BotInstall.find params[:id]
|
@install_bots = BotInstall.where(bot_id: get_bot_id).where(installer_id: params[:id])
|
||||||
bot = Bot.find_by(uid: current_user.id)
|
|
||||||
@install_bots = BotInstall.where(bot_id: bot.id).where(:installer_id => install_bot.installer_id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_secret
|
def update_secret
|
||||||
|
@ -60,11 +59,13 @@ class InstallationsController < ApplicationController
|
||||||
@install_bot.update_attributes!(state: 0)
|
@install_bot.update_attributes!(state: 0)
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def unsuspended
|
def unsuspended
|
||||||
@install_bot = BotInstall.find params[:id]
|
@install_bot = BotInstall.find params[:id]
|
||||||
@install_bot.update_attributes!(state: 1)
|
@install_bot.update_attributes!(state: 1)
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def auth_active
|
def auth_active
|
||||||
begin
|
begin
|
||||||
@bot = Bot.find params[:id]
|
@bot = Bot.find params[:id]
|
||||||
|
@ -89,7 +90,8 @@ class InstallationsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def access_tokens
|
def access_tokens
|
||||||
@install_bot = BotInstall.find params[:id]
|
@install_bot = BotInstall.find_by(bot_id: get_bot_id, installer_id: params[:id]) || BotInstall.find_by(id: params[:id])
|
||||||
|
tip_exception "参数installer_id错误" if @install_bot.blank?
|
||||||
@bot = @install_bot.bot
|
@bot = @install_bot.bot
|
||||||
@application = Doorkeeper::Application.find_by(uid: @bot.client_id, secret: @bot.client_secret)
|
@application = Doorkeeper::Application.find_by(uid: @bot.client_id, secret: @bot.client_secret)
|
||||||
tip_exception("该Bot未激活") if @application.blank?
|
tip_exception("该Bot未激活") if @application.blank?
|
||||||
|
@ -104,5 +106,16 @@ class InstallationsController < ApplicationController
|
||||||
render_ok(token: @access_token.token)
|
render_ok(token: @access_token.token)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def get_bot_id
|
||||||
|
header = request.authorization
|
||||||
|
pattern = /^Bearer /i
|
||||||
|
token = header.gsub(pattern, "")
|
||||||
|
decoded_token = JWT.decode token, nil, false
|
||||||
|
# 前面已验证token有效期和正确性
|
||||||
|
decoded_token[0]["iss"]
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,7 @@ json.status 0
|
||||||
json.message "success"
|
json.message "success"
|
||||||
json.data do
|
json.data do
|
||||||
json.array! @install_bots do |install_bot|
|
json.array! @install_bots do |install_bot|
|
||||||
json.installation_id install_bot.id
|
json.extract! install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time
|
||||||
json.extract! install_bot.bot, :id, :name
|
json.bot_name install_bot&.bot&.name
|
||||||
json.bot_id install_bot.bot.id
|
|
||||||
json.bot_name install_bot.bot.name
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,5 +1,5 @@
|
||||||
json.partial! "commons/success"
|
json.partial! "commons/success"
|
||||||
|
|
||||||
json.extract! @install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time
|
json.extract! @install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time
|
||||||
json.bot_name @install_bot.bot.name
|
json.bot_name @install_bot&.bot&.name
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue