| @@ -2,10 +2,23 @@ class InstallationsController < ApplicationController | |||||
| include RegisterHelper | include RegisterHelper | ||||
| before_action :require_login | before_action :require_login | ||||
| # app详情 | |||||
| def app | |||||
| @bot = Bot.find_by(uid: current_user.id) | |||||
| end | |||||
| def index | def index | ||||
| @install_bots = BotInstall.where(:installer_id => current_user.id) | @install_bots = BotInstall.where(:installer_id => current_user.id) | ||||
| end | 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 | def update_secret | ||||
| ActiveRecord::Base.transaction do | ActiveRecord::Base.transaction do | ||||
| bot = Bot.find params[:id] | bot = Bot.find params[:id] | ||||
| @@ -25,6 +38,24 @@ class InstallationsController < ApplicationController | |||||
| render_ok | render_ok | ||||
| end | 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 | def auth_active | ||||
| begin | begin | ||||
| @bot = Bot.find params[:id] | @bot = Bot.find params[:id] | ||||
| @@ -60,6 +91,7 @@ class InstallationsController < ApplicationController | |||||
| :expires_in => "604800", | :expires_in => "604800", | ||||
| :use_refresh_token => true | :use_refresh_token => true | ||||
| }) | }) | ||||
| @install_bot.update_attributes!(state: 1) | |||||
| render_ok(token: @access_token.token) | render_ok(token: @access_token.token) | ||||
| end | end | ||||
| @@ -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 | |||||
| @@ -4,5 +4,8 @@ json.data do | |||||
| json.array! @install_bots do |install_bot| | json.array! @install_bots do |install_bot| | ||||
| json.installation_id install_bot.id | json.installation_id install_bot.id | ||||
| json.extract! install_bot.bot, :id, :name | json.extract! install_bot.bot, :id, :name | ||||
| json.bot_id install_bot.bot.id | |||||
| json.bot_name install_bot.bot.name | |||||
| end | end | ||||
| end | end | ||||
| @@ -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 | |||||
| @@ -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 | |||||
| @@ -1064,18 +1064,23 @@ Rails.application.routes.draw do | |||||
| resources :commit_logs, :only => [:create] | resources :commit_logs, :only => [:create] | ||||
| scope '/app' do | scope '/app' do | ||||
| get '/', to: 'installations#app' | |||||
| post ':id/auth_active', to: 'installations#auth_active' | post ':id/auth_active', to: 'installations#auth_active' | ||||
| post ':id/update_private_key', to: 'installations#update_private_key' | post ':id/update_private_key', to: 'installations#update_private_key' | ||||
| post ':id/update_secret', to: 'installations#update_secret' | post ':id/update_secret', to: 'installations#update_secret' | ||||
| resources :installations do | |||||
| get :repositories, on: :collection | |||||
| resources :installations, only: [:index, :show] do | |||||
| member do | member do | ||||
| post :access_tokens | post :access_tokens | ||||
| put :suspended | |||||
| put :suspended, to: 'installations#suspended' | |||||
| delete :suspended, to: 'installations#unsuspended' | |||||
| end | end | ||||
| end | end | ||||
| end | end | ||||
| resources :installations, only: [] do | |||||
| get :repositories, on: :collection | |||||
| end | |||||
| root 'main#index' | root 'main#index' | ||||