diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 2addade2d..fb819444a 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -2,10 +2,23 @@ class InstallationsController < ApplicationController include RegisterHelper before_action :require_login + # app详情 + def app + @bot = Bot.find_by(uid: current_user.id) + end + def index @install_bots = BotInstall.where(:installer_id => current_user.id) end + def show + @install_bot = BotInstall.find params[:id] + end + + def repositories + @install_bots = BotInstall.where(:installer_id => current_user.id) + end + def update_secret ActiveRecord::Base.transaction do bot = Bot.find params[:id] @@ -25,6 +38,24 @@ class InstallationsController < ApplicationController render_ok end + def update_callback_url + bot = Bot.find params[:id] + application = Doorkeeper::Application.find_by(uid: bot.client_id, secret: bot.client_secret) + # application.redirect_uri = bot.callback_url + application.save + render_ok + end + + def suspended + @install_bot = BotInstall.find params[:id] + @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] @@ -60,6 +91,7 @@ class InstallationsController < ApplicationController :expires_in => "604800", :use_refresh_token => true }) + @install_bot.update_attributes!(state: 1) render_ok(token: @access_token.token) end diff --git a/app/views/installations/app.json.jbuilder b/app/views/installations/app.json.jbuilder new file mode 100644 index 000000000..cc738e6b9 --- /dev/null +++ b/app/views/installations/app.json.jbuilder @@ -0,0 +1,4 @@ +json.partial! "commons/success" + +json.extract! @bot, :id, :bot_name, :bot_des, :webhook, :is_public, :logo, :state, :web_url, :install_num, :owner_id, :create_time, :update_time + diff --git a/app/views/installations/index.json.jbuilder b/app/views/installations/index.json.jbuilder index 3d64a3323..2163567ed 100644 --- a/app/views/installations/index.json.jbuilder +++ b/app/views/installations/index.json.jbuilder @@ -4,5 +4,8 @@ json.data do json.array! @install_bots do |install_bot| json.installation_id install_bot.id json.extract! install_bot.bot, :id, :name + json.bot_id install_bot.bot.id + json.bot_name install_bot.bot.name + end end \ No newline at end of file diff --git a/app/views/installations/repositories.json.jbuilder b/app/views/installations/repositories.json.jbuilder new file mode 100644 index 000000000..01e873378 --- /dev/null +++ b/app/views/installations/repositories.json.jbuilder @@ -0,0 +1,15 @@ +json.status 0 +json.message "success" +json.total_count @install_bots.size +json.repositories do + json.array! @install_bots do |install_bot| + project = Project.find_by(id: install_bot.store_id) + if project.present? + json.id install_bot.store_id + json.url "#{base_url}/#{project.owner.login}/#{project.owner.identifier}.git" + json.name project.owner.identifier + json.owner_name project.owner.login + json.is_public project.is_public + end + end +end \ No newline at end of file diff --git a/app/views/installations/show.json.jbuilder b/app/views/installations/show.json.jbuilder new file mode 100644 index 000000000..33c7ba206 --- /dev/null +++ b/app/views/installations/show.json.jbuilder @@ -0,0 +1,5 @@ +json.partial! "commons/success" + +json.extract! @install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time +json.bot_name @install_bot.bot.name + diff --git a/config/routes.rb b/config/routes.rb index c544c9198..9c280e2bf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1064,18 +1064,23 @@ Rails.application.routes.draw do resources :commit_logs, :only => [:create] scope '/app' do + get '/', to: 'installations#app' post ':id/auth_active', to: 'installations#auth_active' post ':id/update_private_key', to: 'installations#update_private_key' post ':id/update_secret', to: 'installations#update_secret' - resources :installations do - get :repositories, on: :collection + resources :installations, only: [:index, :show] do member do post :access_tokens - put :suspended + put :suspended, to: 'installations#suspended' + delete :suspended, to: 'installations#unsuspended' end end end + resources :installations, only: [] do + get :repositories, on: :collection + end + root 'main#index'