Merge remote-tracking branch 'origin/pre_trustie_server' into trustie_server
This commit is contained in:
commit
63f1cdda00
|
@ -3,13 +3,22 @@ class Api::V1::BaseController < ApplicationController
|
|||
include Api::ProjectHelper
|
||||
include Api::UserHelper
|
||||
|
||||
before_action :doorkeeper_authorize!
|
||||
skip_before_action :user_setup
|
||||
# before_action :doorkeeper_authorize!
|
||||
# skip_before_action :user_setup
|
||||
|
||||
protected
|
||||
def current_user
|
||||
User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
|
||||
end
|
||||
# def current_user
|
||||
# #client方法对接,需要一直带着用户标识uid
|
||||
# Rails.logger.info doorkeeper_token
|
||||
# if doorkeeper_token && doorkeeper_token.resource_owner_id.blank?
|
||||
# # return User.anonymous if params[:uid].nil?
|
||||
# # tip_exception("2222")
|
||||
# # return render_error('缺少用户标识!') if params[:uid].nil?
|
||||
# User.current = User.find(params[:uid])
|
||||
# else
|
||||
# User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
|
||||
# end
|
||||
# end
|
||||
|
||||
def require_manager_above
|
||||
@project = load_project
|
||||
|
|
|
@ -170,10 +170,6 @@ class ApplicationController < ActionController::Base
|
|||
# 未授权的捕捉407,弹试用申请弹框
|
||||
def require_login
|
||||
#6.13 -hs
|
||||
if request.headers["Authorization"].present?
|
||||
tip_exception(401, "请登录后再操作!") unless valid_doorkeeper_token?
|
||||
User.current = User.find_by(id: @doorkeeper_token.resource_owner_id) if @doorkeeper_token.present?
|
||||
end
|
||||
tip_exception(401, "请登录后再操作") unless User.current.logged?
|
||||
end
|
||||
|
||||
|
@ -252,42 +248,55 @@ class ApplicationController < ActionController::Base
|
|||
#return if params[:controller] == "main"
|
||||
# Find the current user
|
||||
#Rails.logger.info("current_laboratory is #{current_laboratory} domain is #{request.subdomain}")
|
||||
User.current = find_current_user
|
||||
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous"))
|
||||
|
||||
# 开放课程通过链接访问的用户
|
||||
if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank?
|
||||
content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}"
|
||||
|
||||
if Digest::MD5.hexdigest(content) == params[:chinaoocKey]
|
||||
user = open_class_user
|
||||
if user
|
||||
start_user_session(user)
|
||||
set_autologin_cookie(user)
|
||||
if request.headers["Authorization"].present? && request.headers["Authorization"].start_with?('Bearer')
|
||||
tip_exception(401, "请登录后再操作!") unless valid_doorkeeper_token?
|
||||
if @doorkeeper_token.present?
|
||||
# client方法对接,需要一直带着用户标识uid
|
||||
if @doorkeeper_token.resource_owner_id.blank?
|
||||
tip_exception(-1, "缺少用户标识!") if params[:uid].nil?
|
||||
User.current = User.find(params[:uid])
|
||||
else
|
||||
User.current = User.find_by(id: @doorkeeper_token.resource_owner_id)
|
||||
end
|
||||
User.current = user
|
||||
end
|
||||
end
|
||||
else
|
||||
User.current = find_current_user
|
||||
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous"))
|
||||
|
||||
# if !User.current.logged? && Rails.env.development?
|
||||
# user = User.find 1
|
||||
# User.current = user
|
||||
# start_user_session(user)
|
||||
# end
|
||||
# 开放课程通过链接访问的用户
|
||||
if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank?
|
||||
content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}"
|
||||
|
||||
if Digest::MD5.hexdigest(content) == params[:chinaoocKey]
|
||||
user = open_class_user
|
||||
if user
|
||||
start_user_session(user)
|
||||
set_autologin_cookie(user)
|
||||
end
|
||||
User.current = user
|
||||
end
|
||||
end
|
||||
|
||||
# if !User.current.logged? && Rails.env.development?
|
||||
# user = User.find 1
|
||||
# User.current = user
|
||||
# start_user_session(user)
|
||||
# end
|
||||
|
||||
|
||||
# 测试版前端需求
|
||||
logger.info("subdomain:#{request.subdomain}")
|
||||
if request.subdomain != "www"
|
||||
if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除
|
||||
User.current = User.find 81403
|
||||
elsif params[:debug] == 'student'
|
||||
User.current = User.find 8686
|
||||
elsif params[:debug] == 'admin'
|
||||
logger.info "@@@@@@@@@@@@@@@@@@@@@@ debug mode....."
|
||||
user = User.find 36480
|
||||
User.current = user
|
||||
cookies.signed[:user_id] = user.id
|
||||
# 测试版前端需求
|
||||
logger.info("subdomain:#{request.subdomain}")
|
||||
if request.subdomain != "www"
|
||||
if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除
|
||||
User.current = User.find 81403
|
||||
elsif params[:debug] == 'student'
|
||||
User.current = User.find 8686
|
||||
elsif params[:debug] == 'admin'
|
||||
logger.info "@@@@@@@@@@@@@@@@@@@@@@ debug mode....."
|
||||
user = User.find 36480
|
||||
User.current = user
|
||||
cookies.signed[:user_id] = user.id
|
||||
end
|
||||
end
|
||||
end
|
||||
# User.current = User.find 81403
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
class CommitLogsController < ApplicationController
|
||||
|
||||
def create
|
||||
tip_exception "未认证" unless params[:token].to_s == "7917908927b6f1b792f2027a08a8b24a2de42c1692c2fd45da0dee5cf90a5af5"
|
||||
ref = params[:ref]
|
||||
commit_id = params[:commits][0][:id]
|
||||
message = params[:commits][0][:message]
|
||||
user_name = params[:commits][0][:committer][:username]
|
||||
user_mail = params[:commits][0][:committer][:email]
|
||||
user = User.find_by(mail: user_mail)
|
||||
user = User.find_by(login: user_name) if user.blank?
|
||||
|
||||
repository_id = params[:repository][:id]
|
||||
repository_name = params[:repository][:name]
|
||||
repository_full_name = params[:repository][:full_name]
|
||||
project = Project.where(identifier: repository_name).where(user_id: user.id)&.first
|
||||
project = Project.where(identifier: repository_name).where(gpid: repository_id)&.first if project.blank?
|
||||
CommitLog.create(user: user, project: project, repository_id: repository_id,
|
||||
name: repository_name, full_name: repository_full_name,
|
||||
ref: ref, commit_id: commit_id, message: message)
|
||||
|
||||
end
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class CommitLog < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :project
|
||||
belongs_to :repository
|
||||
|
||||
end
|
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Doorkeeper.configure do
|
||||
base_controller 'ApplicationController'
|
||||
# Change the ORM that doorkeeper will use (requires ORM extensions installed).
|
||||
# Check the list of supported ORMs here: https://github.com/doorkeeper-gem/doorkeeper#orms
|
||||
orm :active_record
|
||||
|
@ -20,7 +21,7 @@ Doorkeeper.configure do
|
|||
access_token_generator '::Doorkeeper::JWT'
|
||||
|
||||
admin_authenticator do
|
||||
user = User.find_by_id(session[:www_user_id])
|
||||
user = current_user
|
||||
unless user && user.admin_or_business?
|
||||
redirect_to root_url
|
||||
end
|
||||
|
@ -513,7 +514,7 @@ Doorkeeper::JWT.configure do
|
|||
# about the user. Defaults to a randomly generated token in a hash:
|
||||
# { token: "RANDOM-TOKEN" }
|
||||
token_payload do |opts|
|
||||
user = User.find(opts[:resource_owner_id])
|
||||
user = User.find_by(id: opts[:resource_owner_id])
|
||||
|
||||
{
|
||||
iss: 'GitLink',
|
||||
|
@ -523,9 +524,9 @@ Doorkeeper::JWT.configure do
|
|||
jti: SecureRandom.uuid,
|
||||
|
||||
user: {
|
||||
id: user.id,
|
||||
login: user.login,
|
||||
mail: user.mail
|
||||
id: user&.id,
|
||||
login: user&.login,
|
||||
mail: user&.mail
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -1011,6 +1011,8 @@ Rails.application.routes.draw do
|
|||
get 'oauth/get_code', to: 'oauth#get_code'
|
||||
get 'oauth/get_token_callback', to: 'oauth#get_token_callback'
|
||||
|
||||
resources :commit_logs, :only => [:create]
|
||||
|
||||
root 'main#index'
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
class CreateCommitLogs < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :commit_logs do |t|
|
||||
t.references :user
|
||||
t.references :project
|
||||
t.integer :repository_id
|
||||
t.string :name
|
||||
t.string :full_name
|
||||
t.string :commit_id
|
||||
t.string :ref
|
||||
t.string :message
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :commit_logs, :commit_id
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue