Merge branch 'standalone_develop' into pre_trustie_server

This commit is contained in:
yystopf 2022-04-21 16:59:55 +08:00
commit 121e04f751
9 changed files with 367 additions and 374 deletions

View File

@ -1,324 +1,331 @@
class UsersController < ApplicationController class UsersController < ApplicationController
include ApplicationHelper include ApplicationHelper
include Ci::DbConnectable include Ci::DbConnectable
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users, :hovercard] before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users, :hovercard]
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard] before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard]
before_action :require_login, only: %i[me sync_user_info] before_action :require_login, only: %i[me sync_user_info]
before_action :connect_to_ci_db, only: [:get_user_info] before_action :connect_to_ci_db, only: [:get_user_info]
before_action :convert_image!, only: [:update, :update_image] before_action :convert_image!, only: [:update, :update_image]
skip_before_action :check_sign, only: [:attachment_show] skip_before_action :check_sign, only: [:attachment_show]
def connect_to_ci_db(options={}) def connect_to_ci_db(options={})
if !(current_user && !current_user.is_a?(AnonymousUser) && current_user.devops_certification?) if !(current_user && !current_user.is_a?(AnonymousUser) && current_user.devops_certification?)
return return
end end
if current_user.ci_cloud_account.server_type == Ci::CloudAccount::SERVER_TYPE_TRUSTIE if current_user.ci_cloud_account.server_type == Ci::CloudAccount::SERVER_TYPE_TRUSTIE
connect_to_trustie_ci_database(options) connect_to_trustie_ci_database(options)
else else
connect_to_ci_database(options) connect_to_ci_database(options)
end end
end end
def list def list
scope = User.active.recent.like(params[:search]).includes(:user_extension) scope = User.active.recent.like(params[:search]).includes(:user_extension)
@total_count = scope.size @total_count = scope.size
@users = paginate(scope) @users = paginate(scope)
end end
def show def show
#待办事项,现在未做 #待办事项,现在未做
if User.current.admin? || User.current.login == @user.login if User.current.admin? || User.current.login == @user.login
@waiting_applied_messages = @user.applied_messages.waiting @waiting_applied_messages = @user.applied_messages.waiting
@common_applied_transfer_projects = AppliedTransferProject.where(owner_id: @user.id).common + AppliedTransferProject.where(owner_id: Organization.joins(team_users: :team).where(team_users: {user_id: @user.id}, teams: {authorize: %w(admin owner)} )).common @common_applied_transfer_projects = AppliedTransferProject.where(owner_id: @user.id).common + AppliedTransferProject.where(owner_id: Organization.joins(team_users: :team).where(team_users: {user_id: @user.id}, teams: {authorize: %w(admin owner)} )).common
@common_applied_projects = AppliedProject.where(project_id: @user.full_admin_projects).common @common_applied_projects = AppliedProject.where(project_id: @user.full_admin_projects).common
#@undo_events = @waiting_applied_messages.size + @common_applied_transfer_projects.size + @common_applied_projects.size #@undo_events = @waiting_applied_messages.size + @common_applied_transfer_projects.size + @common_applied_projects.size
@undo_events = @common_applied_transfer_projects.size + @common_applied_projects.size @undo_events = @common_applied_transfer_projects.size + @common_applied_projects.size
else else
@waiting_applied_messages = AppliedMessage.none @waiting_applied_messages = AppliedMessage.none
@common_applied_transfer_projects = AppliedTransferProject.none @common_applied_transfer_projects = AppliedTransferProject.none
@common_applied_projects = AppliedProject.none @common_applied_projects = AppliedProject.none
@undo_events = 0 @undo_events = 0
end end
#用户的组织数量 #用户的组织数量
# @user_composes_count = @user.composes.size # @user_composes_count = @user.composes.size
@user_composes_count = 0 @user_composes_count = 0
user_organizations = User.current.logged? ? @user.organizations.with_visibility(%w(common limited)) + @user.organizations.with_visibility("privacy").joins(:team_users).where(team_users: {user_id: current_user.id}) : @user.organizations.with_visibility("common") user_organizations = User.current.logged? ? @user.organizations.with_visibility(%w(common limited)) + @user.organizations.with_visibility("privacy").joins(:team_users).where(team_users: {user_id: current_user.id}) : @user.organizations.with_visibility("common")
@user_org_count = user_organizations.size @user_org_count = user_organizations.size
normal_projects = Project.members_projects(@user.id).to_sql normal_projects = Project.members_projects(@user.id).to_sql
org_projects = Project.joins(team_projects: [team: :team_users]).where(team_users: {user_id: @user.id}).to_sql org_projects = Project.joins(team_projects: [team: :team_users]).where(team_users: {user_id: @user.id}).to_sql
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct
user_projects = User.current.logged? && (User.current.admin? || User.current.login == @user.login) ? projects : projects.visible user_projects = User.current.logged? && (User.current.admin? || User.current.login == @user.login) ? projects : projects.visible
@projects_common_count = user_projects.common.size @projects_common_count = user_projects.common.size
@projects_mirrior_count = user_projects.mirror.size @projects_mirrior_count = user_projects.mirror.size
@projects_sync_mirrior_count = user_projects.sync_mirror.size @projects_sync_mirrior_count = user_projects.sync_mirror.size
# 为了缓存活跃用户的基本信息,后续删除 # 为了缓存活跃用户的基本信息,后续删除
Cache::V2::OwnerCommonService.new(@user.id).read Cache::V2::OwnerCommonService.new(@user.id).read
end end
def watch_users def watch_users
watchers = Watcher.watching_users(@user.id).includes(:user).order("watchers.created_at desc") watchers = Watcher.watching_users(@user.id).includes(:user).order("watchers.created_at desc")
if params[:search].present? if params[:search].present?
search_user_ids = User.where(id: watchers.pluck(:watchable_id)).like(params[:search]).pluck(:id) search_user_ids = User.where(id: watchers.pluck(:watchable_id)).like(params[:search]).pluck(:id)
watchers = watchers.where(watchable_id: search_user_ids) watchers = watchers.where(watchable_id: search_user_ids)
end end
@watchers_count = watchers.size @watchers_count = watchers.size
@watchers = paginate(watchers) @watchers = paginate(watchers)
end end
def fan_users def fan_users
watchers = @user.watchers.includes(:user).order("watchers.created_at desc") watchers = @user.watchers.includes(:user).order("watchers.created_at desc")
watchers = watchers.joins(:user).merge(User.like(params[:search])) watchers = watchers.joins(:user).merge(User.like(params[:search]))
@watchers_count = watchers.size @watchers_count = watchers.size
@watchers = paginate(watchers) @watchers = paginate(watchers)
end end
def hovercard def hovercard
end end
def update def update
return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id]) return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id])
return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id) return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
Util.write_file(@image, avatar_path(@user)) if user_params[:image].present? Util.write_file(@image, avatar_path(@user)) if user_params[:image].present?
@user.attributes = user_params.except(:image) @user.attributes = user_params.except(:image)
unless @user.save unless @user.save
render_error(-1, @user.errors.full_messages.join(", ")) render_error(-1, @user.errors.full_messages.join(", "))
end end
end end
def update_image def update_image
return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id]) return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id])
return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id) return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
Util.write_file(@image, avatar_path(@user)) Util.write_file(@image, avatar_path(@user))
return render_ok({message: '头像修改成功'}) return render_ok({message: '头像修改成功'})
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
render_error(-1, '头像修改失败!') render_error(-1, '头像修改失败!')
end end
def me def get_image
@user = current_user return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id])
end return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
# 贴吧获取用户信接口 redirect_to Rails.application.config_for(:configuration)['platform_url'] + "/" + url_to_avatar(@user).to_s
def get_user_info end
begin
@user = current_user def me
begin @user = current_user
result = Notice::Read::CountService.call(current_user.id) end
@message_unread_total = result.nil? ? 0 : result[2]["unread_notification"]
rescue # 贴吧获取用户信接口
@message_unread_total = 0 def get_user_info
end begin
# TODO 等消息上线再打开注释 @user = current_user
#@tidding_count = unviewed_tiddings(current_user) if current_user.present? begin
rescue Exception => e result = Notice::Read::CountService.call(current_user.id)
uid_logger_error(e.message) @message_unread_total = result.nil? ? 0 : result[2]["unread_notification"]
missing_template rescue
end @message_unread_total = 0
end
end # TODO 等消息上线再打开注释
#@tidding_count = unviewed_tiddings(current_user) if current_user.present?
def attachment_show rescue Exception => e
file_name = params[:file_name] uid_logger_error(e.message)
path = params[:path] || file_storage_directory missing_template
send_file "#{path}/#{file_name}", :filename => "#{file_name}", end
:type => 'game',
:disposition => 'attachment' #inline can open in browser end
end
def attachment_show
def html_show file_name = params[:file_name]
@contents = File.read("#{params[:path]}") path = params[:path] || file_storage_directory
respond_to do |format| send_file "#{path}/#{file_name}", :filename => "#{file_name}",
format.html {render :layout => false} :type => 'game',
end :disposition => 'attachment' #inline can open in browser
end end
# Redo: 消息总数缓存 def html_show
def get_navigation_info @contents = File.read("#{params[:path]}")
# @old_domain = edu_setting('old_edu_host') respond_to do |format|
# @user = current_user format.html {render :layout => false}
# # 新消息数 end
# @new_message = @user.tidings.where("created_at > '#{@user.click_time}'").count > 0 || @user.private_messages.where("created_at > '#{@user.click_time}'").count > 0 end
#
# @user_url = "/users/#{@user.login}" # Redo: 消息总数缓存
# @career = Career.where(status: true).order("created_at asc").pluck(:id, :name) def get_navigation_info
# @auth = User.current.ec_school.present? ? "#{@old_domain}/ecs/department?school_id=#{User.current.ec_school}" : nil # @old_domain = edu_setting('old_edu_host')
end # @user = current_user
# # 新消息数
# 用户回复功能 # @new_message = @user.tidings.where("created_at > '#{@user.click_time}'").count > 0 || @user.private_messages.where("created_at > '#{@user.click_time}'").count > 0
def reply_message #
message = JournalsForMessage.new(reply_message_params) # @user_url = "/users/#{@user.login}"
message.user_id = current_user.id # @career = Career.where(status: true).order("created_at asc").pluck(:id, :name)
message.save! # @auth = User.current.ec_school.present? ? "#{@old_domain}/ecs/department?school_id=#{User.current.ec_school}" : nil
end
render_ok(id: message.id)
end # 用户回复功能
def reply_message
# 搜索用户具有管理员角色的项目 message = JournalsForMessage.new(reply_message_params)
def search_user_projects message.user_id = current_user.id
projects = Project.where.not(status: 9) message.save!
projects = projects.joins(members: :member_roles).where(member_roles: { role_id: 3 }) render_ok(id: message.id)
projects = projects.where(members: { user_id: current_user.id }) end
search = params[:search].to_s.strip # 搜索用户具有管理员角色的项目
projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present? def search_user_projects
projects = Project.where.not(status: 9)
@projects = projects.select(:id, :name)
end projects = projects.joins(members: :member_roles).where(member_roles: { role_id: 3 })
projects = projects.where(members: { user_id: current_user.id })
#TODO 个人主页信息forge上弃用-hs, 0602
def homepage_info search = params[:search].to_s.strip
#待办事项,现在未做 projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present?
@undo_events = 10
#用户的组织数量 @projects = projects.select(:id, :name)
# @user_composes_count = @user.composes.size end
@user_composes_count = 10
end #TODO 个人主页信息forge上弃用-hs, 0602
def homepage_info
def brief_introduction #待办事项,现在未做
content = params[:content].to_s.strip @undo_events = 10
#用户的组织数量
current_user.user_extension.update!(brief_introduction: content) # @user_composes_count = @user.composes.size
@user_composes_count = 10
render_ok end
end
def brief_introduction
def attendance content = params[:content].to_s.strip
attendance = Users::AttendanceService.call(current_user)
render_ok(grade: current_user.grade, next_gold: attendance.next_gold) current_user.user_extension.update!(brief_introduction: content)
rescue Users::AttendanceService::Error => ex
render_error(ex.message) render_ok
end end
# 其他平台登录后必须将token同步到forge平台实现sso登录功能 def attendance
def sync_token attendance = Users::AttendanceService.call(current_user)
return render_error('未找相关用户!') unless @user render_ok(grade: current_user.grade, next_gold: attendance.next_gold)
rescue Users::AttendanceService::Error => ex
token = Token.get_or_create_permanent_login_token(@user, 'autologin') render_error(ex.message)
token.update_column(:value, params[:token]) end
render_ok
end # 其他平台登录后必须将token同步到forge平台实现sso登录功能
def sync_token
def trustie_related_projects return render_error('未找相关用户!') unless @user
projects = Project.includes(:owner, :members, :project_score).where(id: params[:ids]).order("updated_on desc")
projects_json = [] token = Token.get_or_create_permanent_login_token(@user, 'autologin')
domain_url = EduSetting.get('host_name') token.update_column(:value, params[:token])
if projects.present? render_ok
projects.each do |p| end
project_url = "/#{p.owner.login}/#{p.identifier}"
pj = { def trustie_related_projects
id: p.id, projects = Project.includes(:owner, :members, :project_score).where(id: params[:ids]).order("updated_on desc")
name: p.name, projects_json = []
is_public: p.is_public, domain_url = EduSetting.get('host_name')
updated_on: p.updated_on.strftime("%Y-%m-%d"), if projects.present?
status: p.status, projects.each do |p|
is_member: p.member?(current_user.try(:id)), project_url = "/#{p.owner.login}/#{p.identifier}"
owner: { pj = {
name: p.owner.try(:show_real_name), id: p.id,
login: p.owner.login name: p.name,
}, is_public: p.is_public,
members_count: p&.members.size, updated_on: p.updated_on.strftime("%Y-%m-%d"),
issues_count: p.issues_count - p.pull_requests_count, status: p.status,
commits_count: p&.project_score&.changeset_num.to_i, is_member: p.member?(current_user.try(:id)),
http_url: domain_url + project_url, owner: {
http_collaborator_url: domain_url + project_url + "/setting/collaborator", name: p.owner.try(:show_real_name),
http_issues_url: domain_url + project_url + "/issues", login: p.owner.login
http_commits_url: domain_url + project_url + "/commits", },
project_score: p&.project_score.present? ? p&.project_score&.as_json(:except=>[:created_at, :updated_at]).merge!(commit_time: format_time(p&.project_score&.commit_time)) : {} members_count: p&.members.size,
} issues_count: p.issues_count - p.pull_requests_count,
projects_json.push(pj) commits_count: p&.project_score&.changeset_num.to_i,
end http_url: domain_url + project_url,
end http_collaborator_url: domain_url + project_url + "/setting/collaborator",
Rails.logger.info("==========projects_json========+########{projects_json}") http_issues_url: domain_url + project_url + "/issues",
render json: { projects: projects_json.present? ? projects_json : {} } http_commits_url: domain_url + project_url + "/commits",
end project_score: p&.project_score.present? ? p&.project_score&.as_json(:except=>[:created_at, :updated_at]).merge!(commit_time: format_time(p&.project_score&.commit_time)) : {}
}
def trustie_projects projects_json.push(pj)
user_id = User.select(:id, :login).where(login: params[:login])&.first&.id end
projects = Project.visible end
Rails.logger.info("==========projects_json========+########{projects_json}")
projects = projects.joins(:members).where(members: { user_id: user_id }) render json: { projects: projects_json.present? ? projects_json : {} }
end
search = params[:search].to_s.strip
projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present? def trustie_projects
user_id = User.select(:id, :login).where(login: params[:login])&.first&.id
projects = projects.select(:id, :name).limit(10).as_json projects = Project.visible
render json: { projects: projects }
end projects = projects.joins(:members).where(members: { user_id: user_id })
def projects search = params[:search].to_s.strip
is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == @user.id) projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present?
scope = Projects::ListMyQuery.call(params, @user,is_current_admin_user)
@total_count = scope.size projects = projects.select(:id, :name).limit(10).as_json
@projects = paginate(scope) render json: { projects: projects }
end end
# TODO 其他平台登录时同步修改gitea平台对应用户的密码 def projects
# 该方法主要用于别的平台初次部署对接forge平台同步用户后gitea平台对应的用户密码与forge平台用户密码不一致是问题 is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
def sync_gitea_pwd scope = Projects::ListMyQuery.call(params, @user,is_current_admin_user)
return render_error("未找到相关的用户") if @user.blank? @total_count = scope.size
@projects = paginate(scope)
flag = sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) end
flag ? render_ok : render_error('同步失败!')
end # TODO 其他平台登录时同步修改gitea平台对应用户的密码
# 该方法主要用于别的平台初次部署对接forge平台同步用户后gitea平台对应的用户密码与forge平台用户密码不一致是问题
# TODO def sync_gitea_pwd
# 同步trusite平台用户的salt信息只需同步一次同步完成后该方法可以删除 return render_error("未找到相关的用户") if @user.blank?
def sync_salt
user = User.find_by_login params[:login] flag = sync_pwd_to_gitea!(@user, {password: params[:password].to_s})
return if user.blank? flag ? render_ok : render_error('同步失败!')
user.update_column(:salt, params[:salt]) end
render_ok
end # TODO
# 同步trusite平台用户的salt信息只需同步一次同步完成后该方法可以删除
def sync_user_info def sync_salt
user = User.find_by_login params[:login] user = User.find_by_login params[:login]
return render_forbidden unless user === current_user return if user.blank?
user.update_column(:salt, params[:salt])
sync_params = { render_ok
email: params[:email], end
password: params[:password]
} def sync_user_info
user = User.find_by_login params[:login]
Users::UpdateInfoForm.new(sync_params.merge(login: params[:login])).validate! return render_forbidden unless user === current_user
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params) sync_params = {
if interactor.success? email: params[:email],
user.update!(password: params[:password], mail: params[:email], status: User::STATUS_ACTIVE) password: params[:password]
render_ok }
else
render_error(interactor.error) Users::UpdateInfoForm.new(sync_params.merge(login: params[:login])).validate!
end
end interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
if interactor.success?
private user.update!(password: params[:password], mail: params[:email], status: User::STATUS_ACTIVE)
def load_user render_ok
@user = User.find_by_login(params[:id]) || User.find_by(id: params[:id]) else
end render_error(interactor.error)
end
def user_params end
params.require(:user).permit(:nickname, :image,
user_extension_attributes: [ private
:gender, :location, :location_city, def load_user
:occupation, :technical_title, @user = User.find_by_login(params[:id]) || User.find_by(id: params[:id])
:school_id, :department_id, :province, :city, end
:custom_department, :identity, :student_id, :description,
:show_email, :show_location, :show_department] def user_params
) params.require(:user).permit(:nickname, :image,
end user_extension_attributes: [
:gender, :location, :location_city,
def reply_message_params :occupation, :technical_title,
normal_status(-1, "参数不对") if params[:journals_for_message][:jour_type].nil? || params[:journals_for_message][:jour_id].nil? || :school_id, :department_id, :province, :city,
params[:journals_for_message][:notes].nil? || params[:journals_for_message][:reply_id].nil? :custom_department, :identity, :student_id, :description,
params.require(:journals_for_message).permit(:jour_type, :jour_id, :notes, :m_parent_id, :reply_id) :show_email, :show_location, :show_department]
end )
end
def check_user_exist
return if @user.present? def reply_message_params
render_not_found normal_status(-1, "参数不对") if params[:journals_for_message][:jour_type].nil? || params[:journals_for_message][:jour_id].nil? ||
end params[:journals_for_message][:notes].nil? || params[:journals_for_message][:reply_id].nil?
params.require(:journals_for_message).permit(:jour_type, :jour_id, :notes, :m_parent_id, :reply_id)
end end
def check_user_exist
return if @user.present?
render_not_found
end
end

View File

@ -147,6 +147,15 @@ module ApplicationHelper
end end
end end
def url_to_avatar_with_platform_url(source)
platform_url = Rails.application.config_for(:configuration)['platform_url']
if platform_url
return Rails.application.config_for(:configuration)['platform_url'] + "/" + url_to_avatar(source).to_s
else
return url_to_avatar(source).to_s
end
end
# 主页banner图 # 主页banner图
def banner_img(source_type) def banner_img(source_type)
if File.exist?(disk_filename(source_type, "banner")) if File.exist?(disk_filename(source_type, "banner"))

View File

@ -7,7 +7,7 @@ module Notice
config = Rails.application.config_for(:configuration).symbolize_keys! config = Rails.application.config_for(:configuration).symbolize_keys!
notice_config = config[:notice].symbolize_keys! notice_config = config[:notice].symbolize_keys!
raise 'notice config missing' if notice_config.blank? raise 'notice config missing' if notice_config.blank?
rescue => exception rescue => ex
raise ex if Rails.env.production? raise ex if Rails.env.production?
puts %Q{\033[33m [warning] gitea config or configuration.yml missing, puts %Q{\033[33m [warning] gitea config or configuration.yml missing,

View File

@ -7,7 +7,7 @@ module Trace
config = Rails.application.config_for(:configuration).symbolize_keys! config = Rails.application.config_for(:configuration).symbolize_keys!
trace_config = config[:trace].symbolize_keys! trace_config = config[:trace].symbolize_keys!
raise 'trace config missing' if trace_config.blank? raise 'trace config missing' if trace_config.blank?
rescue => exception rescue => ex
raise ex if Rails.env.production? raise ex if Rails.env.production?
puts %Q{\033[33m [warning] gitea config or configuration.yml missing, puts %Q{\033[33m [warning] gitea config or configuration.yml missing,

View File

@ -83,6 +83,10 @@ class Organization < Owner
after_save :reset_cache_data after_save :reset_cache_data
def gitea_token
team_users.joins(:team).where(teams: {authorize: "owner"}).take&.user&.gitea_token
end
def reset_cache_data def reset_cache_data
Cache::V2::OwnerCommonService.new(self.id).reset Cache::V2::OwnerCommonService.new(self.id).reset
end end

View File

@ -47,7 +47,7 @@ class Organizations::CreateService < ApplicationService
end end
def create_org_and_extension def create_org_and_extension
@organization = Organization.build(params[:name], params[:nickname], user.gitea_token) @organization = Organization.build(params[:name], params[:nickname])
org_extension = OrganizationExtension.build(organization.id, description, website, org_extension = OrganizationExtension.build(organization.id, description, website,
location, repo_admin_change_team_access, location, repo_admin_change_team_access,
visibility, max_repo_creation) visibility, max_repo_creation)

View File

@ -2,20 +2,14 @@ class Trace::ClientService < ApplicationService
def post(url, params={}) def post(url, params={})
puts "[trace][POST] request params: #{params}" puts "[trace][POST] request params: #{params}"
conn.post do |req| conn.post(full_url(url), params[:data])
req.url full_url(url)
req.body = params[:data].to_json
end
end end
def authed_post(token, url, params={}) def authed_post(token, url, params={})
puts "[trace][POST] request params: #{params}" puts "[trace][POST] request params: #{params}"
puts "[trace][POST] request token: #{token}" puts "[trace][POST] request token: #{token}"
conn.post do |req| conn.headers['Authorization'] = token
req.url full_url(url) conn.post(full_url(url), params[:data])
req.body = params[:data].to_json
req.headers['Authorization'] = token
end
end end
def get(url, params={}) def get(url, params={})
@ -42,69 +36,42 @@ class Trace::ClientService < ApplicationService
def delete(url, params={}) def delete(url, params={})
puts "[trace][DELETE] request params: #{params}" puts "[trace][DELETE] request params: #{params}"
conn.delete do |req| conn.delete(full_url(url), params[:data])
req.url full_url(url)
req.body = params[:data].to_json
end
end end
def authed_delete(token, url, params={}) def authed_delete(token, url, params={})
puts "[trace][DELETE] request params: #{params}" puts "[trace][DELETE] request params: #{params}"
puts "[trace][DELETE] request token: #{token}" puts "[trace][DELETE] request token: #{token}"
conn.delete do |req| conn.headers['Authorization'] = token
req.url full_url(url) conn.delete(full_url(url), params[:data])
req.body = params[:data].to_json
req.headers['Authorization'] = token
end
end end
def patch(url, params={}) def patch(url, params={})
puts "[trace][PATCH] request params: #{params}" puts "[trace][PATCH] request params: #{params}"
conn.patch do |req| conn.patch(full_url(url), params[:data])
req.url full_url(url)
req.body = params[:data].to_json
end
end end
def authed_patch(token, url, params={}) def authed_patch(token, url, params={})
puts "[trace][PATCH] request params: #{params}" puts "[trace][PATCH] request params: #{params}"
puts "[trace][PATCH] request token: #{token}" puts "[trace][PATCH] request token: #{token}"
conn.patch do |req| conn.headers['Authorization'] = token
req.url full_url(url) conn.patch(full_url(url), params[:data])
req.body = params[:data].to_json
req.headers['Authorization'] = token
end
end end
def put(url, params={}) def put(url, params={})
puts "[trace][PUT] request params: #{params}" puts "[trace][PUT] request params: #{params}"
conn.put do |req| conn.put(full_url(url), params[:data])
req.url full_url(url)
req.body = params[:data].to_json
end
end end
def authed_put(token, url, params={}) def authed_put(token, url, params={})
puts "[trace][PUT] request params: #{params}" puts "[trace][PUT] request params: #{params}"
puts "[trace][PUT] request token: #{token}" puts "[trace][PUT] request token: #{token}"
conn.put do |req| conn.headers['Authorization'] = token
req.url full_url(url) conn.put(full_url(url), params[:data])
req.body = params[:data].to_json
req.headers['Authorization'] = token
end
end end
private
def conn def conn
@client ||= begin Faraday.new(url: domain)
Faraday.new(url: domain) do |req|
req.request :url_encoded
req.headers['Content-Type'] = 'application/json'
req.adapter Faraday.default_adapter
end
end
@client
end end
def base_url def base_url
@ -138,6 +105,6 @@ class Trace::ClientService < ApplicationService
log_error(status, body) log_error(status, body)
return [body["code"], body["Data"], body["Error"]] return [body["code"], body["data"], body["error"]]
end end
end end

View File

@ -45,6 +45,11 @@
<li> <li>
<%= sidebar_item_group('#setting-glcc', 'GLCC配置', icon: 'fire') do %> <%= sidebar_item_group('#setting-glcc', 'GLCC配置', icon: 'fire') do %>
<li><%= sidebar_item(admins_topic_glcc_news_index_path, '新闻稿管理', icon: 'edit', controller: 'admins-topic-glcc_news') %></li> <li><%= sidebar_item(admins_topic_glcc_news_index_path, '新闻稿管理', icon: 'edit', controller: 'admins-topic-glcc_news') %></li>
<li>
<% if EduSetting.get("glcc_apply_informations_admin_url")%>
<%= sidebar_item(EduSetting.get("glcc_apply_informations_admin_url"), '报名列表', icon: 'user', controller: 'root') %>
<% end %>
</li>
<% end %> <% end %>
</li> </li>
<li> <li>

View File

@ -225,6 +225,7 @@ Rails.application.routes.draw do
get :fan_users get :fan_users
get :hovercard get :hovercard
put :update_image put :update_image
get :get_image
end end
collection do collection do
post :following post :following