|
|
|
@@ -8,18 +8,17 @@ class InstallationsController < ApplicationController |
|
|
|
end |
|
|
|
|
|
|
|
def index |
|
|
|
@install_bots = BotInstall.where(:installer_id => current_user.id) |
|
|
|
@install_bots = BotInstall.where(bot_id: get_bot_id) |
|
|
|
end |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
def repositories |
|
|
|
# 与github差异,所以取安装用户和bot对应所有的仓库 |
|
|
|
install_bot = BotInstall.find 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) |
|
|
|
@install_bots = BotInstall.where(bot_id: get_bot_id).where(installer_id: params[:id]) |
|
|
|
end |
|
|
|
|
|
|
|
def update_secret |
|
|
|
@@ -60,11 +59,13 @@ class InstallationsController < ApplicationController |
|
|
|
@install_bot.update_attributes!(state: 0) |
|
|
|
render_ok |
|
|
|
end |
|
|
|
|
|
|
|
def unsuspended |
|
|
|
@install_bot = BotInstall.find params[:id] |
|
|
|
@install_bot.update_attributes!(state: 1) |
|
|
|
render_ok |
|
|
|
end |
|
|
|
|
|
|
|
def auth_active |
|
|
|
begin |
|
|
|
@bot = Bot.find params[:id] |
|
|
|
@@ -89,7 +90,8 @@ class InstallationsController < ApplicationController |
|
|
|
end |
|
|
|
|
|
|
|
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 |
|
|
|
@application = Doorkeeper::Application.find_by(uid: @bot.client_id, secret: @bot.client_secret) |
|
|
|
tip_exception("该Bot未激活") if @application.blank? |
|
|
|
@@ -104,5 +106,16 @@ class InstallationsController < ApplicationController |
|
|
|
render_ok(token: @access_token.token) |
|
|
|
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 |
|
|
|
|