Merge branch 'standalone_develop' into pre_trustie_server

This commit is contained in:
yystopf 2023-04-21 15:37:20 +08:00
commit 1a6500d686
7 changed files with 115 additions and 4 deletions

View File

@ -0,0 +1,23 @@
class Api::V1::Users::OpenkylinSignController < Api::V1::BaseController
before_action :load_observe_user
def competitions
@competition_ids = EduSetting.get("openkylin_sign_competitions").split(",") rescue []
render :json => {data: @competition_ids}
end
def create
@object_result = Api::V1::Users::OpenkylinSign::CreateService.call(@observe_user, create_params)
if @result_object
return render_ok
else
return render_error('签署失败!')
end
end
private
def create_params
params.permit(:login, :email, :nickname, :phone, :address)
end
end

View File

@ -1,7 +1,7 @@
class Api::V1::UsersController < Api::V1::BaseController
before_action :load_observe_user, except: [:check_user_id]
before_action :check_auth_for_observe_user, except: [:check_user_id]
before_action :load_observe_user, except: [:check_user_id, :check_user_login]
before_action :check_auth_for_observe_user, except: [:check_user_id, :check_user_login]
def check_user_id
return tip_exception(-1, "用户ID不存在") unless params[:user_id].present? && User.exists?(id: params[:user_id])

View File

@ -88,7 +88,7 @@ module RepositoriesHelper
unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:")
# new_r_content = "#{path}" + new_r_content
new_r_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{path_current}/#{path_last}&ref=#{ref}"].join
new_r_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{path_current}/#{path_last}?ref=#{ref}"].join
end
content = content.gsub(/src=\"#{r_content}\"/, "src=\"#{new_r_content}\"").gsub(/src='#{r_content}'/, "src=\"#{new_r_content}\"")
rescue
@ -132,7 +132,7 @@ module RepositoriesHelper
s_content = File.expand_path(s_content, file_path)
s_content = s_content.split("#{Rails.root}/")[1]
# content = content.gsub(s[0], "/#{s_content}")
s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{s_content}&ref=#{ref}"].join
s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{s_content}?ref=#{ref}"].join
case k.to_s
when 'ss_src'
content = content.gsub("src=\"#{s[0]}\"", "src=\"#{s_content}\"")

View File

@ -0,0 +1,24 @@
# == Schema Information
#
# Table name: openkylin_sign_details
#
# id :integer not null, primary key
# user_id :integer
# login :string(255)
# email :string(255)
# nickname :string(255)
# phone :string(255)
# address :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_openkylin_sign_details_on_user_id (user_id)
#
class OpenkylinSignDetail < ApplicationRecord
belongs_to :user
end

View File

@ -0,0 +1,45 @@
class Api::V1::Users::OpenkylinSign::CreateService < ApplicationService
include ActiveModel::Model
attr_reader :observe_user, :login, :email, :nickname, :phone, :address
# validates :login, format: {with: CustomRegexp::LOGIN}
validates :email, format: {with: CustomRegexp::EMAIL}
validates :nickname, length: { maximum: 32 }
validates :phone, format: {with: CustomRegexp::PHONE}
validates :address, length: { maximum: 100 }
def initialize(observe_user, params={})
@observe_user = observe_user
@login = observe_user.login
@email = params[:email]
@nickname = params[:nickname]
@phone = params[:phone]
@address = params[:address]
end
def call
raise Error, errors.full_messages.join(",") unless valid?
raise Error, '用户已经签署CLA协议' if @observe_user.sign_cla
begin
ActiveRecord::Base.transaction do
create_openkylin_sign_detail
update_user_sign_cla
end
return true
rescue
raise Error, "服务器错误,请联系系统管理员!"
end
end
private
def create_openkylin_sign_detail
OpenkylinSignDetail.create!(user_id: @observe_user.id, login: @login, email: @email, nickname: @nickname, phone: @phone, address: @address)
end
def update_user_sign_cla
@observe_user.update_attributes!(sign_cla: true)
end
end

View File

@ -24,6 +24,11 @@ defaults format: :json do
scope module: :users do
resources :projects, only: [:index]
resources :feedbacks, only: [:create]
resources :openkylin_sign, only: [:create] do
collection do
get :competitions
end
end
end
scope ':repo', constraints: { repo: /[^\/]+/ } do

View File

@ -0,0 +1,14 @@
class CreateOpenkylinSignDetails < ActiveRecord::Migration[5.2]
def change
create_table :openkylin_sign_details do |t|
t.references :user
t.string :login
t.string :email
t.string :nickname
t.string :phone
t.string :address
t.timestamps
end
end
end