cla fix and add token verify
This commit is contained in:
parent
d35bbcf6fb
commit
65816a980b
|
@ -4,9 +4,9 @@ class ProjectsController < ApplicationController
|
||||||
include ProjectsHelper
|
include ProjectsHelper
|
||||||
include Acceleratorable
|
include Acceleratorable
|
||||||
|
|
||||||
before_action :require_login, except: %i[index branches branches_slice group_type_list simple show fork_users praise_users watch_users recommend banner_recommend about menu_list]
|
before_action :require_login, except: %i[index branches branches_slice group_type_list simple show fork_users praise_users watch_users recommend banner_recommend about menu_list verify_auth_token]
|
||||||
before_action :require_profile_completed, only: [:create, :migrate]
|
before_action :require_profile_completed, only: [:create, :migrate,:verify_auth_token]
|
||||||
before_action :load_repository, except: %i[index group_type_list migrate create recommend banner_recommend]
|
before_action :load_repository, except: %i[index group_type_list migrate create recommend banner_recommend verify_auth_token]
|
||||||
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
||||||
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
||||||
before_action :request_limit, only: %i[index]
|
before_action :request_limit, only: %i[index]
|
||||||
|
@ -63,6 +63,15 @@ class ProjectsController < ApplicationController
|
||||||
tip_exception(e.message)
|
tip_exception(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def verify_auth_token
|
||||||
|
data = Projects::VerifyAuthTokenService.call(params[:clone_addr], params[:auth_token])
|
||||||
|
if data
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error('token验证不通过')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def migrate
|
def migrate
|
||||||
Projects::MigrateForm.new(mirror_params).validate!
|
Projects::MigrateForm.new(mirror_params).validate!
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,16 @@ class Users::ClasController < Users::BaseController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@user_cla = current_user.user_clas.find_by(cla_id: params[:cla_id])
|
@user_cla = current_user.user_clas.find_by(cla_id: params[:cla_id])
|
||||||
if @user_cla
|
if @user_cla.nil?
|
||||||
@user_cla.update_attributes(state: 1)
|
|
||||||
else
|
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
Users::UserClaForm.new(user_cla_params).validate!
|
Users::UserClaForm.new(user_cla_params).validate!
|
||||||
@user_cla = UserCla.build(user_cla_params, current_user.id)
|
@user_cla = UserCla.build(user_cla_params, current_user.id)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
elsif @user_cla.state == "failed"
|
||||||
|
@user_cla.update_by_params(user_cla_params)
|
||||||
|
elsif @user_cla.state == "signed"
|
||||||
|
return render_error('协议生效中,请勿重复签署')
|
||||||
end
|
end
|
||||||
render_ok
|
render_ok
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
|
@ -40,6 +40,7 @@ class Cla < ApplicationRecord
|
||||||
user_clas.where(user_id: user_id, state:1).present?
|
user_clas.where(user_id: user_id, state:1).present?
|
||||||
end
|
end
|
||||||
def fresh_count
|
def fresh_count
|
||||||
update(count:self.users.count)
|
number = self.user_clas.where(state: 1).count
|
||||||
|
update(count: number)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
# state :integer default("0")
|
# state :integer default("0")
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
|
# sign_time :datetime
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
@ -22,7 +23,8 @@ class UserCla < ApplicationRecord
|
||||||
belongs_to :cla
|
belongs_to :cla
|
||||||
# identity 0: 教师教授 1: 学生, 2: 专业人士, 3: 开发者
|
# identity 0: 教师教授 1: 学生, 2: 专业人士, 3: 开发者
|
||||||
enum state: { deafult: 0, signed: 1, failed: 2}
|
enum state: { deafult: 0, signed: 1, failed: 2}
|
||||||
after_create do
|
|
||||||
|
after_save do
|
||||||
cla.fresh_count
|
cla.fresh_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -35,10 +37,20 @@ class UserCla < ApplicationRecord
|
||||||
cla_id: params[:cla_id],
|
cla_id: params[:cla_id],
|
||||||
real_name: params[:real_name],
|
real_name: params[:real_name],
|
||||||
email: params[:email],
|
email: params[:email],
|
||||||
|
sign_time: Time.now,
|
||||||
state: 1
|
state: 1
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_by_params(params)
|
||||||
|
update(\
|
||||||
|
state: 1,
|
||||||
|
sign_time: Time.now,
|
||||||
|
real_name: params[:real_name],
|
||||||
|
email: params[:email],
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def fresh_pull_request
|
def fresh_pull_request
|
||||||
project_ids = cla.organization.projects.pluck(:id)
|
project_ids = cla.organization.projects.pluck(:id)
|
||||||
if state == "signed"
|
if state == "signed"
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
class Projects::VerifyAuthTokenService < ApplicationService
|
||||||
|
attr_accessor :url, :token
|
||||||
|
|
||||||
|
def initialize(url, token)
|
||||||
|
@url = url
|
||||||
|
@token = token
|
||||||
|
@repo = nil
|
||||||
|
@owner = nil
|
||||||
|
@website = nil
|
||||||
|
@success = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
Rails.logger.info("###### VerifyAuthTokenService begin ######")
|
||||||
|
regular_url
|
||||||
|
to_verify
|
||||||
|
Rails.logger.info("##### VerifyAuthTokenService end ######")
|
||||||
|
return @success
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def regular_url
|
||||||
|
regx = /\/\/[\s\S]*.git$/ #获取字串
|
||||||
|
data = (regx.match @url).to_s[2..-5].split("/")
|
||||||
|
@website = data[0]
|
||||||
|
@owner = data[1]
|
||||||
|
@repo = data[2]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def to_verify
|
||||||
|
data = case @website
|
||||||
|
when "github.com"
|
||||||
|
github_verify
|
||||||
|
when "gitlab.com"
|
||||||
|
gitlab_verify
|
||||||
|
when "gitee.com"
|
||||||
|
gitee_verify
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def gitee_verify
|
||||||
|
url = "/api/v5/repos/#{@owner}/#{@repo}"
|
||||||
|
api_url= "https://gitee.com"
|
||||||
|
client = Faraday.new(url: api_url)
|
||||||
|
client.options["open_timeout"] = 1
|
||||||
|
client.options["timeout"] = 1
|
||||||
|
client.options["write_timeout"] = 1
|
||||||
|
req_params={
|
||||||
|
access_token: @token,
|
||||||
|
owner: @owner,
|
||||||
|
repo: @repo
|
||||||
|
}
|
||||||
|
response = client.public_send("get", url, req_params)
|
||||||
|
@success = true if response.status == 200
|
||||||
|
end
|
||||||
|
|
||||||
|
def github_verify
|
||||||
|
url = "/octocat"
|
||||||
|
api_url= "https://api.github.com"
|
||||||
|
client = Faraday.new(url: api_url)
|
||||||
|
client.options["open_timeout"] = 1
|
||||||
|
client.options["timeout"] = 1
|
||||||
|
client.options["write_timeout"] = 1
|
||||||
|
client.headers["Authorization"] = "Bearer #{@token}"
|
||||||
|
response = client.public_send("get", url)
|
||||||
|
@success = true if response.status == 200
|
||||||
|
end
|
||||||
|
|
||||||
|
def gitlab_verify
|
||||||
|
url = "/api/v4/projects"
|
||||||
|
api_url= "https://gitlab.com"
|
||||||
|
client = Faraday.new(url: api_url)
|
||||||
|
client.options["open_timeout"] = 1
|
||||||
|
client.options["timeout"] = 1
|
||||||
|
client.options["write_timeout"] = 1
|
||||||
|
req_params={
|
||||||
|
private_token: @token
|
||||||
|
}
|
||||||
|
response = client.public_send("get", url, req_params)
|
||||||
|
@success = true if response.status == 200
|
||||||
|
end
|
||||||
|
end
|
|
@ -20,7 +20,7 @@ class PullRequests::SendJournalService < ApplicationService
|
||||||
journalized_id: @issue.id ,
|
journalized_id: @issue.id ,
|
||||||
journalized_type: "Issue",
|
journalized_type: "Issue",
|
||||||
user_id: sender_id ,
|
user_id: sender_id ,
|
||||||
notes: "@#{@current_user.nickname} 您好!欢迎参与 #{@project.name} 的贡献。首次进行贡献请完成《<a href='/#{@project.owner.login}/cla/#{@project.owner.cla.key}' target='_blank'>#{@project.owner.cla.name}</a>》的签署,签署完成后,项目成员才可查看到您的合并请求",
|
notes: "<b>#{@current_user.nickname}</b>您好!欢迎参与 #{@project.name} 的贡献。首次进行贡献请完成《<a href='/#{@project.owner.login}/cla/#{@project.owner.cla.key}' target='_blank'>#{@project.owner.cla.name}</a>》的签署,签署完成后,项目成员才可查看到您的合并请求",
|
||||||
}
|
}
|
||||||
journal = Journal.new journal_params
|
journal = Journal.new journal_params
|
||||||
if journal.save
|
if journal.save
|
||||||
|
|
|
@ -2,7 +2,7 @@ json.id user_cla.id
|
||||||
json.real_name user_cla.real_name
|
json.real_name user_cla.real_name
|
||||||
json.email user_cla.email
|
json.email user_cla.email
|
||||||
json.state user_cla.state
|
json.state user_cla.state
|
||||||
json.created_at format_time(user_cla.created_at)
|
json.created_at format_time(user_cla.sign_time)
|
||||||
json.cla do
|
json.cla do
|
||||||
json.partial! "/organizations/clas/detail", locals: {cla: user_cla.cla}
|
json.partial! "/organizations/clas/detail", locals: {cla: user_cla.cla}
|
||||||
end
|
end
|
||||||
|
|
|
@ -241,6 +241,7 @@ Rails.application.routes.draw do
|
||||||
get :group_type_list
|
get :group_type_list
|
||||||
get :recommend
|
get :recommend
|
||||||
get :banner_recommend
|
get :banner_recommend
|
||||||
|
post :verify_auth_token
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddSignTimeToUserClas < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :user_clas, :sign_time, :datetime
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue