Merge pull request '20231011版本' (#338) from Trustie/forgeplus:standalone_develop into develop
This commit is contained in:
commit
1e427a62a6
54
Dockerfile
54
Dockerfile
|
@ -1,33 +1,47 @@
|
|||
FROM ubuntu:18.04
|
||||
FROM ubuntu:20.04
|
||||
RUN apt-get update
|
||||
# basics
|
||||
RUN apt-get install -y libssl-dev curl libmysqlclient-dev imagemagick nodejs mysql-server redis-server tzdata
|
||||
RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
||||
# confirm openssl version
|
||||
RUN openssl version
|
||||
RUN which openssl
|
||||
# install RVM, Ruby, and Bundler
|
||||
RUN \curl -L https://get.rvm.io | bash -s stable
|
||||
RUN /bin/bash -l -c "rvm requirements"
|
||||
# replace ruby mirror url, accelerate install ruby
|
||||
RUN sed -i 's/rvm_remote_server_url2/#rvm_remote_server_url2/g' /usr/local/rvm/config/db
|
||||
RUN sed -i 's/cache.ruby-lang.org/cache.ruby-china.com/g' /usr/local/rvm/config/db
|
||||
# install ruby
|
||||
RUN /bin/bash -l -c "rvm install 2.4.5"
|
||||
# confirm ruby version
|
||||
RUN /bin/bash -l -c "rvm list"
|
||||
RUN /bin/bash -l -c "ruby -v"
|
||||
|
||||
RUN apt update
|
||||
|
||||
RUN apt install -y openssl libssl-dev imagemagick git ruby-dev nodejs libmariadb-dev libmysqlclient-dev shared-mime-info libpq-dev libxml2-dev libxslt-dev
|
||||
RUN DEBIAN_FRONTEND="noninteractive" apt -y install tzdata
|
||||
RUN ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
||||
#RUN apt-get install -y nodejs
|
||||
|
||||
WORKDIR /home/app/gitlink
|
||||
|
||||
ADD ./ /home/app/gitlink
|
||||
|
||||
RUN gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
|
||||
RUN cd /home/app/gitlink
|
||||
|
||||
RUN gem update --system
|
||||
RUN /bin/bash -l -c 'gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/'
|
||||
|
||||
RUN gem install bundler
|
||||
RUN gem install rake
|
||||
RUN /bin/bash -l -c 'gem update --system'
|
||||
|
||||
RUN /bin/bash -l -c 'gem install bundler -v 2.3.26'
|
||||
RUN /bin/bash -l -c 'gem install rake'
|
||||
RUN /bin/bash -l -c 'gem install puma -v 5.6.5'
|
||||
|
||||
RUN rm -rf Gemfile.lock
|
||||
|
||||
#RUN cp config/configuration.yml.example config/configuration.yml
|
||||
#RUN cp config/database.yml.example config/database.yml
|
||||
#RUN touch config/redis.yml
|
||||
#RUN touch config/elasticsearch.yml
|
||||
|
||||
RUN bundle install
|
||||
|
||||
EXPOSE 4000
|
||||
RUN rails s -p 4000 -b '0.0.0.0'
|
||||
|
||||
RUN cp config/configuration.yml.example config/configuration.yml
|
||||
RUN cp config/database.yml.example config/database.yml
|
||||
RUN touch config/redis.yml
|
||||
RUN touch config/elasticsearch.yml
|
||||
|
||||
RUN /bin/bash -l -c 'bundle install'
|
||||
|
||||
#EXPOSE 4000
|
||||
#RUN /bin/bash -l -c 'RAILS_ENV=production puma'
|
9
Gemfile
9
Gemfile
|
@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|||
|
||||
gem 'rails', '~> 5.2.0'
|
||||
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
|
||||
gem 'puma', '~> 3.11'
|
||||
gem 'puma', '~> 5.6.5'
|
||||
gem 'sass-rails', '~> 5.0'
|
||||
gem 'uglifier', '>= 1.3.0'
|
||||
|
||||
|
@ -23,7 +23,7 @@ gem 'chinese_pinyin'
|
|||
gem 'rack-cors'
|
||||
gem 'redis-rails'
|
||||
gem 'roo-xls'
|
||||
gem 'simple_xlsx_reader'
|
||||
gem 'simple_xlsx_reader', '~>1.0.4'
|
||||
|
||||
gem 'rubyzip'
|
||||
|
||||
|
@ -53,7 +53,7 @@ gem 'acts_as_list'
|
|||
gem 'omniauth-cas'
|
||||
|
||||
# profiler Middleware
|
||||
gem 'rack-mini-profiler'
|
||||
# gem 'rack-mini-profiler'
|
||||
|
||||
# object-based searching
|
||||
gem 'ransack'
|
||||
|
@ -102,6 +102,7 @@ gem 'rails-i18n', '~> 5.1'
|
|||
gem 'sidekiq',"5.2.8"
|
||||
gem 'sinatra'
|
||||
gem "sidekiq-cron", "1.2.0"
|
||||
gem 'sidekiq-failures'
|
||||
|
||||
# batch insert
|
||||
gem 'bulk_insert'
|
||||
|
@ -140,4 +141,4 @@ gem 'doorkeeper'
|
|||
|
||||
gem 'doorkeeper-jwt'
|
||||
|
||||
gem 'gitea-client', '~> 0.11.6'
|
||||
gem 'gitea-client', '~> 1.4.2'
|
||||
|
|
27
Gemfile.lock
27
Gemfile.lock
|
@ -1,5 +1,5 @@
|
|||
GEM
|
||||
remote: https://gems.ruby-china.com/
|
||||
remote: https://mirrors.cloud.tencent.com/rubygems/
|
||||
specs:
|
||||
aasm (5.0.6)
|
||||
concurrent-ruby (~> 1.0)
|
||||
|
@ -135,7 +135,7 @@ GEM
|
|||
fugit (1.4.1)
|
||||
et-orbi (~> 1.1, >= 1.1.8)
|
||||
raabro (~> 1.4)
|
||||
gitea-client (0.10.5)
|
||||
gitea-client (1.4.2)
|
||||
rest-client (~> 2.1.0)
|
||||
globalid (0.4.2)
|
||||
activesupport (>= 4.2.0)
|
||||
|
@ -189,7 +189,7 @@ GEM
|
|||
method_source (0.9.2)
|
||||
mime-types (3.4.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2022.0105)
|
||||
mime-types-data (3.2023.0218.1)
|
||||
mimemagic (0.3.10)
|
||||
nokogiri (~> 1)
|
||||
rake
|
||||
|
@ -220,9 +220,21 @@ GEM
|
|||
addressable (~> 2.3)
|
||||
nokogiri (~> 1.5)
|
||||
omniauth (~> 1.2)
|
||||
omniauth-gitee (1.0.0)
|
||||
omniauth (>= 1.5, < 3.0)
|
||||
omniauth-oauth2 (>= 1.4.0, < 2.0)
|
||||
omniauth-github (1.4.0)
|
||||
omniauth (~> 1.5)
|
||||
omniauth-oauth2 (>= 1.4.0, < 2.0)
|
||||
omniauth-oauth2 (1.6.0)
|
||||
oauth2 (~> 1.1)
|
||||
omniauth (~> 1.9)
|
||||
omniauth-rails_csrf_protection (0.1.2)
|
||||
actionpack (>= 4.2)
|
||||
omniauth (>= 1.3.1)
|
||||
omniauth-wechat-oauth2 (0.2.2)
|
||||
omniauth (>= 1.3.2)
|
||||
omniauth-oauth2 (>= 1.1.1)
|
||||
parallel (1.19.1)
|
||||
parser (2.7.1.1)
|
||||
ast (~> 2.4.0)
|
||||
|
@ -385,6 +397,8 @@ GEM
|
|||
sidekiq-cron (1.2.0)
|
||||
fugit (~> 1.1)
|
||||
sidekiq (>= 4.2.1)
|
||||
sidekiq-failures (1.0.4)
|
||||
sidekiq (>= 4.0.0)
|
||||
simple_form (5.0.2)
|
||||
actionpack (>= 5.0)
|
||||
activemodel (>= 5.0)
|
||||
|
@ -478,7 +492,7 @@ DEPENDENCIES
|
|||
enumerize
|
||||
faraday (~> 0.15.4)
|
||||
font-awesome-sass (= 4.7.0)
|
||||
gitea-client (~> 0.10.2)
|
||||
gitea-client (~> 1.4.2)
|
||||
grape-entity (~> 0.7.1)
|
||||
groupdate (~> 4.1.0)
|
||||
harmonious_dictionary (~> 0.0.1)
|
||||
|
@ -492,7 +506,11 @@ DEPENDENCIES
|
|||
oauth2
|
||||
omniauth (~> 1.9.0)
|
||||
omniauth-cas
|
||||
omniauth-gitee (~> 1.0.0)
|
||||
omniauth-github
|
||||
omniauth-oauth2 (~> 1.6.0)
|
||||
omniauth-rails_csrf_protection
|
||||
omniauth-wechat-oauth2
|
||||
parallel (~> 1.19, >= 1.19.1)
|
||||
pdfkit
|
||||
prettier
|
||||
|
@ -518,6 +536,7 @@ DEPENDENCIES
|
|||
selenium-webdriver
|
||||
sidekiq (= 5.2.8)
|
||||
sidekiq-cron (= 1.2.0)
|
||||
sidekiq-failures
|
||||
simple_form
|
||||
simple_xlsx_reader
|
||||
sinatra
|
||||
|
|
|
@ -111,6 +111,7 @@ gitea:
|
|||
access_key_secret: 'password'
|
||||
domain: 'http://www.gitea.example.com'
|
||||
base_url: '/api/v1'
|
||||
hat_base_url: '/api/hat'
|
||||
```
|
||||
|
||||
(8)配置/config/database.yml文件(安装redis环境:请自行搜索各平台如何安装部署redis环境)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -63,7 +63,7 @@ $(document).on('turbolinks:load', function() {
|
|||
|
||||
if(!valid) return;
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
method: 'PUT',
|
||||
dataType: 'json',
|
||||
url: $form.attr('action'),
|
||||
data: new FormData($form[0]),
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,65 @@
|
|||
$(document).on('turbolinks:load', function(){
|
||||
if ($('body.admins-organizations-index-page').length > 0) {
|
||||
var showSuccessNotify = function() {
|
||||
$.notify({
|
||||
message: '操作成功'
|
||||
},{
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
|
||||
// organizations open cla
|
||||
$('.organizations-list-container').on('click', '.open-cla-action', function(){
|
||||
var $openClaAction = $(this);
|
||||
var $closeClaAction = $openClaAction.siblings('.close-cla-action');
|
||||
|
||||
var userId = $openClaAction.data('id');
|
||||
customConfirm({
|
||||
content: '确认开通吗?',
|
||||
ok: function () {
|
||||
$.ajax({
|
||||
url: '/admins/organizations/' + userId + '/open_cla',
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
showSuccessNotify();
|
||||
$closeClaAction.show();
|
||||
$openClaAction.hide();
|
||||
},
|
||||
error: function(res){
|
||||
$.notify({ message: res.responseJSON.message }, { type: 'danger' });
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// organizations close cla
|
||||
$('.organizations-list-container').on('click', '.close-cla-action', function(){
|
||||
var $closeClaAction = $(this);
|
||||
var $openClaAction= $closeClaAction.siblings('.open-cla-action');
|
||||
|
||||
var userId = $openClaAction.data('id');
|
||||
customConfirm({
|
||||
content: '确认关闭吗?',
|
||||
ok: function () {
|
||||
$.ajax({
|
||||
url: '/admins/organizations/' + userId + '/close_cla',
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
showSuccessNotify();
|
||||
$openClaAction.show();
|
||||
$closeClaAction.hide();
|
||||
},
|
||||
error: function(res){
|
||||
$.notify({ message: res.responseJSON.message }, { type: 'danger' });
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -94,6 +94,20 @@ $(document).on('turbolinks:load', function(){
|
|||
}
|
||||
});
|
||||
});
|
||||
// reset user login times
|
||||
$('.users-list-container').on('click', '.fresh-gitea-token-action', function(){
|
||||
var $action = $(this);
|
||||
|
||||
var userId = $action.data('id');
|
||||
$.ajax({
|
||||
url: '/admins/users/' + userId + '/fresh_gitea_token',
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
showSuccessNotify();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ***************** reward grade modal *****************
|
||||
var $rewardGradeModal = $('.admin-users-reward-grade-modal');
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the admins/glcc_pr_check controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the admins/identity_verifications controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the admins/organizations controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the admins/page_themes controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the admins/site_pages controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the identity_verifications controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the organizations/clas controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the pages controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the users/clas controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -4,15 +4,16 @@ class AccountsController < ApplicationController
|
|||
|
||||
#skip_before_action :check_account, :only => [:logout]
|
||||
|
||||
def simple_update
|
||||
def simple_update
|
||||
simple_update_params.merge!(username: params[:username]&.gsub(/\s+/, ""))
|
||||
simple_update_params.merge!(email: params[:email]&.gsub(/\s+/, ""))
|
||||
simple_update_params.merge!(platform: (params[:platform] || 'forge')&.gsub(/\s+/, ""))
|
||||
Register::RemoteForm.new(simple_update_params).validate!
|
||||
Register::RemoteForm.new(simple_update_params.merge(user_id: current_user.id)).validate!
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
result = auto_update(current_user, simple_update_params)
|
||||
if result[:message].blank?
|
||||
UserAction.create(:action_id => current_user.id, :action_type => "sync_educoder_user", :user_id => current_user.id, :ip => request.remote_ip) if params[:platform] == "educoder"
|
||||
render_ok
|
||||
else
|
||||
render_error(result[:message])
|
||||
|
@ -160,8 +161,11 @@ class AccountsController < ApplicationController
|
|||
successful_authentication(user)
|
||||
render_ok
|
||||
end
|
||||
elsif interactor.result[:message].to_s.include?("user already exists")
|
||||
UserAction.create(:action_id => 2, :action_type => "register_error", :user_id => user.try(:id).to_i, :ip => "code: #{register_params[:code]}; login: #{register_params[:login]}; namespace: #{register_params[:namespace]}; password: #{password};")
|
||||
normal_status(-1, "用户已注册,请勿连续操作。")
|
||||
else
|
||||
tip_exception(-1, interactor.error)
|
||||
tip_exception(-1, interactor.result[:message])
|
||||
end
|
||||
rescue Register::BaseForm::EmailError => e
|
||||
render_result(-2, e.message)
|
||||
|
@ -176,9 +180,14 @@ class AccountsController < ApplicationController
|
|||
rescue Register::BaseForm::VerifiCodeError => e
|
||||
render_result(-6, e.message)
|
||||
rescue Exception => e
|
||||
Gitea::User::DeleteService.call(user.login) unless user.nil?
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(-1, e.message)
|
||||
if user.present? && !e.message.to_s.include?("user already exists")
|
||||
# Gitea::User::DeleteService.call(user.login)
|
||||
# user.destroy
|
||||
end
|
||||
Rails.logger.error("##:register error--#{user.try(:id)},message:#{e.message}")
|
||||
UserAction.create(:action_id => 1, :action_type => "register_error", :user_id => user.try(:id).to_i, :ip => "code: #{register_params[:code]}; login: #{register_params[:login]}; namespace: #{register_params[:namespace]}; password: #{password};")
|
||||
logger_error(e)
|
||||
tip_exception(-1, "注册失败")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -205,9 +214,10 @@ class AccountsController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
LimitForbidControl::UserLogin.new(@user).clear
|
||||
successful_authentication(@user)
|
||||
sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步
|
||||
|
||||
|
||||
# session[:user_id] = @user.id
|
||||
end
|
||||
|
||||
|
@ -324,6 +334,8 @@ class AccountsController < ApplicationController
|
|||
send_type = verify_type(login_type, type)
|
||||
verification_code = code.sample(6).join
|
||||
|
||||
status, message = InfoRiskControlService.call(value, request.remote_ip)
|
||||
tip_exception(420, message) if status == 0
|
||||
sign = Digest::MD5.hexdigest("#{OPENKEY}#{value}")
|
||||
tip_exception(501, "请求不合理") if sign != params[:smscode]
|
||||
|
||||
|
@ -347,6 +359,17 @@ class AccountsController < ApplicationController
|
|||
Register::LoginCheckColumnsForm.new(check_params.merge(user: current_user)).validate!
|
||||
render_ok
|
||||
end
|
||||
|
||||
def check_keywords
|
||||
text = params[:text].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
data = ! ReversedKeyword.check_exists?(text)
|
||||
result = {
|
||||
status: 0,
|
||||
data: data,
|
||||
message: data ? "" : "无法使用以下关键词:#{text},请重新命名"
|
||||
}
|
||||
render_ok(result)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
class Admins::GlccPrCheckController < Admins::BaseController
|
||||
def index
|
||||
params[:sort_by] = params[:sort_by].presence || 'created_on'
|
||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||
examine_materials = Admins::GlccExamineMaterial.call(params)
|
||||
@examine_materials = paginate examine_materials.includes(:glcc_student)
|
||||
end
|
||||
|
||||
def send_mail
|
||||
year = if params[:date].present?
|
||||
params[:date][:year]
|
||||
end
|
||||
if year.nil?
|
||||
return redirect_to admins_glcc_pr_check_index_path
|
||||
flash[:error] = "时间不能为空"
|
||||
end
|
||||
if params[:term].blank?
|
||||
return redirect_to admins_glcc_pr_check_index_path
|
||||
flash[:error] = "考核选项不能为空"
|
||||
end
|
||||
|
||||
examine_materials = GlccMediumTermExamineMaterial.where(\
|
||||
term: params[:term],
|
||||
created_on: [Time.now.change(year:year).beginning_of_year .. Time.now.change(year:year).end_of_year]
|
||||
)
|
||||
examine_materials.map{ |e|
|
||||
e.send_mail
|
||||
}
|
||||
flash[:danger] = "#{year} 年 #{params[:term].to_i == 1 ? "中期考核": "结项考核"} PR 检测邮件已全部发送完毕,一共#{examine_materials.count}封邮件"
|
||||
redirect_to admins_glcc_pr_check_index_path
|
||||
end
|
||||
end
|
|
@ -0,0 +1,35 @@
|
|||
class Admins::IdentityVerificationsController < Admins::BaseController
|
||||
before_action :finder_identity_verification, except: [:index]
|
||||
def index
|
||||
params[:sort_by] = params[:sort_by].presence || 'created_at'
|
||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||
identity_verifications = Admins::IdentityVerificationQuery.call(params)
|
||||
@identity_verifications = paginate identity_verifications.preload(:user)
|
||||
end
|
||||
|
||||
def show
|
||||
render 'edit'
|
||||
end
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @identity_verification.update(update_params)
|
||||
redirect_to admins_identity_verifications_path
|
||||
flash[:success] = "更新成功"
|
||||
else
|
||||
redirect_to admins_identity_verifications_path
|
||||
flash[:danger] = "更新失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def finder_identity_verification
|
||||
@identity_verification = IdentityVerification.find(params[:id])
|
||||
@user = @identity_verification.user
|
||||
end
|
||||
|
||||
def update_params
|
||||
params.require(:identity_verification).permit(:state, :description)
|
||||
end
|
||||
end
|
|
@ -25,6 +25,6 @@ class Admins::LaboratorySettingsController < Admins::BaseController
|
|||
params.permit(:identifier, :name,
|
||||
:nav_logo, :login_logo, :tab_logo, :oj_banner,
|
||||
:subject_banner, :course_banner, :competition_banner, :moop_cases_banner,
|
||||
:footer, navbar: %i[name link hidden])
|
||||
:footer, navbar: %i[name link hidden index])
|
||||
end
|
||||
end
|
|
@ -49,7 +49,7 @@ class Admins::MessageTemplatesController < Admins::BaseController
|
|||
def message_template_params
|
||||
# type = @message_template.present? ? @message_template.type : "MessageTemplate::CustomTip"
|
||||
# params.require(type.split("::").join("_").underscore.to_sym).permit!
|
||||
params.require(:message_template).permit!
|
||||
params.require(:message_template_custom_tip).permit!
|
||||
end
|
||||
|
||||
def get_template
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
class Admins::OrganizationsController < Admins::BaseController
|
||||
before_action :finder_org, except: [:index]
|
||||
|
||||
def index
|
||||
params[:sort_by] = params[:sort_by].presence || 'created_on'
|
||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||
|
||||
orgs = Admins::OrganizationQuery.call(params)
|
||||
@orgs = paginate orgs
|
||||
end
|
||||
|
||||
|
||||
def open_cla
|
||||
@org.open_cla!
|
||||
render_ok
|
||||
end
|
||||
|
||||
def close_cla
|
||||
if @org.cla.nil?
|
||||
@org.close_cla!
|
||||
render_ok
|
||||
else
|
||||
render_error(' 该组织已创建CLA 不允许关闭')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def destroy
|
||||
@org.destroy!
|
||||
Admins::DeleteOrganizationService.call(@org.login)
|
||||
UserAction.create(action_id: @org.id, action_type: "DestroyOrganization", user_id: current_user.id, :ip => request.remote_ip, data_bank: @org.attributes.to_json)
|
||||
render_delete_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def finder_org
|
||||
@org = Organization.find(params[:id])
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,79 @@
|
|||
class Admins::PageThemesController < Admins::BaseController
|
||||
before_action :finder_page_theme, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
params[:sort_by] = params[:sort_by].presence || 'created_at'
|
||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||
|
||||
page_themes = Admins::PageThemesQuery.call(params)
|
||||
|
||||
@page_themes = paginate page_themes
|
||||
end
|
||||
|
||||
def show
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
@page_theme = PageTheme.new theme_params
|
||||
if @page_theme.save
|
||||
save_image_file(params[:image])
|
||||
redirect_to admins_page_themes_path
|
||||
flash[:success] = "新增主题成功"
|
||||
else
|
||||
redirect_to admins_page_themes_path
|
||||
flash[:danger] = "新增主题失败: #{@page_theme.errors.messages.values.flatten.join(',')}"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if PageTheme.where(language_frame: @page_theme.language_frame).count <= 1
|
||||
flash[:danger] = "删除主题失败,必须存在一个主题"
|
||||
return redirect_to admins_page_themes_path
|
||||
end
|
||||
|
||||
if @page_theme.destroy
|
||||
redirect_to admins_page_themes_path
|
||||
flash[:success] = "删除主题成功"
|
||||
else
|
||||
redirect_to admins_page_themes_path
|
||||
flash[:danger] = "删除主题失败"
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@page_theme = PageTheme.new
|
||||
end
|
||||
|
||||
def update
|
||||
@page_theme.attributes = theme_params
|
||||
if @page_theme.save
|
||||
save_image_file(params[:image])
|
||||
redirect_to admins_page_themes_path
|
||||
flash[:success] = "更新成功"
|
||||
else
|
||||
redirect_to admins_page_themes_path
|
||||
flash[:danger] = "更新失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def finder_page_theme
|
||||
@page_theme = PageTheme.find(params[:id])
|
||||
end
|
||||
|
||||
def theme_params
|
||||
params.require(:page_theme).permit(:language_frame, :name, :cate, :image_url, :clone_url, :order_index)
|
||||
end
|
||||
|
||||
def save_image_file(file)
|
||||
return unless file.present? && file.is_a?(ActionDispatch::Http::UploadedFile)
|
||||
file_path = Util::FileManage.source_disk_filename(@page_theme, "image")
|
||||
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
|
||||
Util.write_file(file, file_path)
|
||||
end
|
||||
|
||||
end
|
|
@ -35,6 +35,7 @@ class Admins::ProjectsController < Admins::BaseController
|
|||
Gitea::Repository::DeleteService.new(project.owner, project.identifier).call
|
||||
project.destroy!
|
||||
# render_delete_success
|
||||
UserAction.create(action_id: project.id, action_type: "DestroyProject", user_id: current_user.id, :ip => request.remote_ip, data_bank: project.attributes.to_json)
|
||||
redirect_to admins_projects_path
|
||||
flash[:success] = "删除成功"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
class Admins::SitePagesController < Admins::BaseController
|
||||
before_action :finder_site_page, except: [:index]
|
||||
|
||||
def index
|
||||
params[:sort_by] = params[:sort_by].presence || 'created_at'
|
||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||
|
||||
pages = Admins::SitePagesQuery.call(params)
|
||||
|
||||
@site_pages = paginate pages.preload(:user)
|
||||
end
|
||||
|
||||
def show
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
if @site_page.destroy
|
||||
redirect_to admins_site_pages_path
|
||||
flash[:success] = "删除站点成功"
|
||||
else
|
||||
redirect_to admins_site_pages_path
|
||||
flash[:danger] = "删除站点失败"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@site_page.update(update_params)
|
||||
flash[:success] = '保存成功'
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
private
|
||||
def finder_site_page
|
||||
@site_page = Page.find(params[:id])
|
||||
@user = @site_page.user
|
||||
end
|
||||
|
||||
def update_params
|
||||
params.require(:page).permit(:state, :state_description)
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
class Admins::UsersController < Admins::BaseController
|
||||
before_action :finder_user, except: [:index]
|
||||
before_action :finder_user, except: [:index]
|
||||
|
||||
def index
|
||||
params[:sort_by] = params[:sort_by].presence || 'created_on'
|
||||
|
@ -25,15 +25,16 @@ class Admins::UsersController < Admins::BaseController
|
|||
end
|
||||
|
||||
def destroy
|
||||
UserAction.create(action_id: @user.id, action_type: "DestroyUser", user_id: current_user.id, :ip => request.remote_ip, data_bank: @user.attributes.to_json)
|
||||
@user.destroy!
|
||||
Gitea::User::DeleteService.call(@user.login)
|
||||
|
||||
|
||||
render_delete_success
|
||||
end
|
||||
|
||||
def lock
|
||||
@user.lock!
|
||||
|
||||
UserAction.create(action_id: @user.id, action_type: "LockUser", user_id: current_user.id, :ip => request.remote_ip)
|
||||
render_ok
|
||||
end
|
||||
|
||||
|
@ -57,6 +58,12 @@ class Admins::UsersController < Admins::BaseController
|
|||
render_ok
|
||||
end
|
||||
|
||||
|
||||
def fresh_gitea_token
|
||||
@user.fresh_gitea_token
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def finder_user
|
||||
|
@ -64,8 +71,8 @@ class Admins::UsersController < Admins::BaseController
|
|||
end
|
||||
|
||||
def update_params
|
||||
params.require(:user).permit(%i[lastname nickname gender identity technical_title student_id is_shixun_marker
|
||||
mail phone location location_city school_id department_id admin business is_test
|
||||
password professional_certification authentication login])
|
||||
params.require(:user).permit(%i[lastname nickname gender technical_title is_shixun_marker
|
||||
mail phone location location_city school_id department_id admin
|
||||
password login website_permission])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,10 +20,19 @@ class Api::V1::BaseController < ApplicationController
|
|||
# User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
|
||||
# end
|
||||
# end
|
||||
|
||||
def kaminary_select_paginate(relation)
|
||||
limit = params[:limit] || params[:per_page]
|
||||
limit = (limit.to_i.zero? || limit.to_i > 200) ? 200 : limit.to_i
|
||||
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
|
||||
|
||||
relation.page(page).per(limit)
|
||||
end
|
||||
|
||||
def limit
|
||||
params.fetch(:limit, 15)
|
||||
end
|
||||
|
||||
def page
|
||||
params.fetch(:page, 1)
|
||||
end
|
||||
|
@ -43,7 +52,6 @@ class Api::V1::BaseController < ApplicationController
|
|||
# 具有仓库的操作权限或者fork仓库的操作权限
|
||||
def require_operate_above_or_fork_project
|
||||
@project = load_project
|
||||
puts !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
|
||||
return render_forbidden if !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
class Api::V1::Issues::AssignersController < Api::V1::BaseController
|
||||
|
||||
before_action :require_public_and_member_above, only: [:index]
|
||||
|
||||
# 负责人列表
|
||||
def index
|
||||
@assigners = User.joins(assigned_issues: :project).where(projects: {id: @project&.id})
|
||||
@assigners = @assigners.order("users.id=#{current_user.id} desc").distinct
|
||||
@assigners = @assigners.ransack(login_or_nickname_cont: params[:keyword]).result if params[:keyword].present?
|
||||
@assigners = kaminary_select_paginate(@assigners)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
class Api::V1::Issues::AuthorsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:index]
|
||||
|
||||
# 发布人列表
|
||||
def index
|
||||
@authors = User.joins(issues: :project).where(projects: {id: @project&.id})
|
||||
@authors = @authors.order("users.id=#{current_user.id} desc").distinct
|
||||
@authors = @authors.ransack(login_or_nickname_cont: params[:keyword]).result if params[:keyword].present?
|
||||
@authors = kaminary_select_paginate(@authors)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
class Api::V1::Issues::IssuePrioritiesController < Api::V1::BaseController
|
||||
|
||||
before_action :require_public_and_member_above, only: [:index]
|
||||
|
||||
def index
|
||||
@priorities = IssuePriority.order(position: :asc)
|
||||
@priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword]
|
||||
@priorities = kaminary_select_paginate(@priorities)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,65 @@
|
|||
class Api::V1::Issues::IssueTagsController < Api::V1::BaseController
|
||||
before_action :require_login, except: [:index]
|
||||
before_action :require_public_and_member_above, only: [:index]
|
||||
before_action :require_operate_above, only: [:create, :update, :destroy]
|
||||
|
||||
def index
|
||||
@issue_tags = @project.issue_tags.reorder("#{sort_by} #{sort_direction}")
|
||||
@issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
|
||||
if params[:only_name]
|
||||
@issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color))
|
||||
else
|
||||
@issue_tags = kaminari_paginate(@issue_tags.includes(:project, :user, :issue_issues, :pull_request_issues))
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@issue_tag = @project.issue_tags.new(issue_tag_params)
|
||||
if @issue_tag.save!
|
||||
render_ok
|
||||
else
|
||||
render_error("创建标记失败!")
|
||||
end
|
||||
end
|
||||
|
||||
before_action :load_issue_tag, only: [:update, :destroy]
|
||||
|
||||
def update
|
||||
@issue_tag.attributes = issue_tag_params
|
||||
if @issue_tag.save!
|
||||
render_ok
|
||||
else
|
||||
render_error("更新标记失败!")
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @issue_tag.destroy!
|
||||
render_ok
|
||||
else
|
||||
render_error("删除标记失败!")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def sort_by
|
||||
sort_by = params.fetch(:sort_by, "created_at")
|
||||
sort_by = IssueTag.column_names.include?(sort_by) ? sort_by : "created_at"
|
||||
sort_by
|
||||
end
|
||||
|
||||
def sort_direction
|
||||
sort_direction = params.fetch(:sort_direction, "desc").downcase
|
||||
sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc"
|
||||
sort_direction
|
||||
end
|
||||
|
||||
def issue_tag_params
|
||||
params.permit(:name, :description, :color)
|
||||
end
|
||||
|
||||
def load_issue_tag
|
||||
@issue_tag = @project.issue_tags.find_by_id(params[:id])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,64 @@
|
|||
class Api::V1::Issues::JournalsController < Api::V1::BaseController
|
||||
before_action :require_login, except: [:index, :children_journals]
|
||||
before_action :require_public_and_member_above
|
||||
before_action :load_issue
|
||||
before_action :load_journal, only: [:children_journals, :update, :destroy]
|
||||
before_action :check_journal_operate_permission, only: [:update, :destroy]
|
||||
|
||||
def index
|
||||
@object_result = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user)
|
||||
@total_journals_count = @object_result[:total_journals_count]
|
||||
@total_operate_journals_count = @object_result[:total_operate_journals_count]
|
||||
@total_comment_journals_count = @object_result[:total_comment_journals_count]
|
||||
@journals = kaminary_select_paginate(@object_result[:data])
|
||||
end
|
||||
|
||||
def create
|
||||
@object_result = Api::V1::Issues::Journals::CreateService.call(@issue, journal_params, current_user)
|
||||
end
|
||||
|
||||
def children_journals
|
||||
@object_results = Api::V1::Issues::Journals::ChildrenListService.call(@issue, @journal, query_params, current_user)
|
||||
@journals = kaminari_paginate(@object_results)
|
||||
end
|
||||
|
||||
def update
|
||||
@object_result = Api::V1::Issues::Journals::UpdateService.call(@issue, @journal, journal_params, current_user)
|
||||
end
|
||||
|
||||
def destroy
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!))
|
||||
if @journal.destroy!
|
||||
render_ok
|
||||
else
|
||||
render_error("删除评论失败!")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def query_params
|
||||
params.permit(:category, :keyword, :sort_by, :sort_direction)
|
||||
end
|
||||
|
||||
def journal_params
|
||||
params.permit(:notes, :parent_id, :reply_id, :attachment_ids => [], :receivers_login => [])
|
||||
end
|
||||
|
||||
def load_issue
|
||||
@issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index])
|
||||
if @issue.blank?
|
||||
render_not_found("疑修不存在!")
|
||||
end
|
||||
end
|
||||
|
||||
def load_journal
|
||||
@journal = Journal.find_by_id(params[:id])
|
||||
return render_not_found("评论不存在!") unless @journal.present?
|
||||
end
|
||||
|
||||
def check_journal_operate_permission
|
||||
return render_forbidden("您没有操作权限!") unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user || @journal.user == current_user || @journal.parent_journal&.user == current_user
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,87 @@
|
|||
class Api::V1::Issues::MilestonesController < Api::V1::BaseController
|
||||
before_action :require_login, except: [:index, :show]
|
||||
before_action :require_public_and_member_above, only: [:index, :show]
|
||||
before_action :require_operate_above, only: [:create, :update, :destroy]
|
||||
before_action :load_milestone, only: [:show, :update, :destroy]
|
||||
|
||||
# 里程碑列表
|
||||
def index
|
||||
@milestones = @project.versions
|
||||
@milestones = @milestones.ransack(id_eq: params[:keyword]).result.or(@milestones.ransack(name_or_description_cont: params[:keyword]).result) if params[:keyword].present?
|
||||
@closed_milestone_count = @milestones.closed.size
|
||||
@opening_milestone_count = @milestones.opening.size
|
||||
@milestones = params[:category] == "closed" ? @milestones.closed : @milestones.opening
|
||||
@milestones = @milestones.reorder("versions.#{sort_by} #{sort_direction}")
|
||||
if params[:only_name]
|
||||
@milestones = @milestones.select(:id, :name)
|
||||
@milestones = kaminary_select_paginate(@milestones)
|
||||
else
|
||||
@milestones = @milestones.includes(:issues, :closed_issues, :opened_issues)
|
||||
@milestones = kaminari_paginate(@milestones)
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@milestone = @project.versions.new(milestone_params)
|
||||
if @milestone.save!
|
||||
render_ok
|
||||
else
|
||||
render_error(@milestone.errors.full_messages.join(","))
|
||||
end
|
||||
end
|
||||
|
||||
# 里程碑详情
|
||||
def show
|
||||
@object_result = Api::V1::Issues::Milestones::DetailIssuesService.call(@project, @milestone, query_params, current_user)
|
||||
@total_issues_count = @object_result[:total_issues_count]
|
||||
@opened_issues_count = @object_result[:opened_issues_count]
|
||||
@closed_issues_count = @object_result[:closed_issues_count]
|
||||
|
||||
@issues = kaminari_paginate(@object_result[:data])
|
||||
end
|
||||
|
||||
def update
|
||||
@milestone.attributes = milestone_params
|
||||
if @milestone.save!
|
||||
render_ok
|
||||
else
|
||||
render_error(@milestone.errors.full_messages.join(","))
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @milestone.destroy!
|
||||
render_ok
|
||||
else
|
||||
render_error("删除里程碑失败!")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def milestone_params
|
||||
params.permit(:name, :description, :effective_date)
|
||||
end
|
||||
|
||||
def query_params
|
||||
params.permit(:category, :author_id, :assigner_id, :sort_by, :sort_direction, :issue_tag_ids)
|
||||
end
|
||||
|
||||
def load_milestone
|
||||
@milestone = @project.versions.find_by_id(params[:id])
|
||||
return render_not_found('里程碑不存在!') unless @milestone.present?
|
||||
end
|
||||
|
||||
def sort_by
|
||||
sort_by = params.fetch(:sort_by, "created_on")
|
||||
sort_by = Version.column_names.include?(sort_by) ? sort_by : "created_on"
|
||||
|
||||
sort_by
|
||||
end
|
||||
|
||||
def sort_direction
|
||||
sort_direction = params.fetch(:sort_direction, "desc").downcase
|
||||
sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc"
|
||||
sort_direction
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
class Api::V1::Issues::StatuesController < Api::V1::BaseController
|
||||
|
||||
before_action :require_public_and_member_above, only: [:index]
|
||||
|
||||
# 状态列表
|
||||
def index
|
||||
@statues = IssueStatus.order("position asc")
|
||||
@statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
|
||||
@statues = kaminary_select_paginate(@statues)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,117 @@
|
|||
class Api::V1::IssuesController < Api::V1::BaseController
|
||||
before_action :require_login, except: [:index, :show]
|
||||
before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy]
|
||||
before_action :require_operate_above, only: [:batch_update, :batch_destroy]
|
||||
|
||||
def index
|
||||
IssueTag.init_data(@project.id) unless $redis_cache.hget("project_init_issue_tags", @project.id)
|
||||
@object_result = Api::V1::Issues::ListService.call(@project, query_params, current_user)
|
||||
@total_issues_count = @object_result[:total_issues_count]
|
||||
@opened_issues_count = @object_result[:opened_issues_count]
|
||||
@closed_issues_count = @object_result[:closed_issues_count]
|
||||
if params[:only_name].present?
|
||||
@issues = kaminary_select_paginate(@object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on))
|
||||
else
|
||||
@issues = kaminari_paginate(@object_result[:data])
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@object_result = Api::V1::Issues::CreateService.call(@project, issue_params, current_user)
|
||||
end
|
||||
|
||||
before_action :load_issue, only: [:show, :update, :destroy]
|
||||
before_action :check_issue_operate_permission, only: [:update, :destroy]
|
||||
|
||||
def show
|
||||
@user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user)
|
||||
end
|
||||
|
||||
def update
|
||||
@object_result = Api::V1::Issues::UpdateService.call(@project, @issue, issue_params, current_user)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user)
|
||||
if @object_result
|
||||
render_ok
|
||||
else
|
||||
render_error("删除疑修失败!")
|
||||
end
|
||||
end
|
||||
|
||||
before_action :load_issues, only: [:batch_update, :batch_destroy]
|
||||
|
||||
def batch_update
|
||||
@object_result = Api::V1::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user)
|
||||
if @object_result
|
||||
render_ok
|
||||
else
|
||||
render_error("批量更新疑修失败!")
|
||||
end
|
||||
end
|
||||
|
||||
def batch_destroy
|
||||
@object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user)
|
||||
if @object_result
|
||||
render_ok
|
||||
else
|
||||
render_error("批量删除疑修失败!")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_issue
|
||||
@issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index])
|
||||
if @issue.blank?
|
||||
render_not_found("疑修不存在!")
|
||||
end
|
||||
end
|
||||
|
||||
def load_issues
|
||||
return render_error("请输入正确的ID数组!") unless params[:ids].is_a?(Array)
|
||||
params[:ids].each do |id|
|
||||
@issue = Issue.find_by_id(id)
|
||||
if @issue.blank?
|
||||
return render_not_found("ID为#{id}的疑修不存在!")
|
||||
end
|
||||
end
|
||||
@issues = Issue.where(id: params[:ids])
|
||||
end
|
||||
|
||||
def check_issue_operate_permission
|
||||
return render_forbidden("您没有操作权限!") unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user
|
||||
end
|
||||
|
||||
def query_params
|
||||
params.permit(
|
||||
:only_name,
|
||||
:category,
|
||||
:participant_category,
|
||||
:keyword, :author_id,
|
||||
:milestone_id, :assigner_id,
|
||||
:status_id,
|
||||
:begin_date, :end_date,
|
||||
:sort_by, :sort_direction,
|
||||
:issue_tag_ids)
|
||||
end
|
||||
|
||||
def issue_params
|
||||
params.permit(
|
||||
:status_id, :priority_id, :milestone_id,
|
||||
:branch_name, :start_date, :due_date,
|
||||
:subject, :description, :blockchain_token_num,
|
||||
:issue_tag_ids => [],
|
||||
:assigner_ids => [],
|
||||
:attachment_ids => [],
|
||||
:receivers_login => [])
|
||||
end
|
||||
|
||||
def batch_issue_params
|
||||
params.permit(
|
||||
:status_id, :priority_id, :milestone_id,
|
||||
:issue_tag_ids => [],
|
||||
:assigner_ids => [])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,46 @@
|
|||
class Api::V1::ProjectTopicsController < Api::V1::BaseController
|
||||
|
||||
def index
|
||||
@project_topics = ProjectTopic
|
||||
@project_topics = @project_topics.ransack(name_cont: params[:keyword]) if params[:keyword].present?
|
||||
# @project_topics = @project_topics.includes(:projects)
|
||||
@project_topics = kaminary_select_paginate(@project_topics)
|
||||
end
|
||||
|
||||
def create
|
||||
ActiveRecord::Base.transaction do
|
||||
@project = Project.find_by_id(create_params[:project_id])
|
||||
return render_not_found unless @project.present?
|
||||
return render_error("请输入项目搜索标签名称.") unless create_params[:name].present?
|
||||
|
||||
@project_topic = ProjectTopic.find_or_create_by!(name: create_params[:name].downcase)
|
||||
@project_topic_ralate = @project_topic.project_topic_ralates.find_or_create_by!(project_id: create_params[:project_id])
|
||||
|
||||
if @project_topic.present? && @project_topic_ralate.present?
|
||||
render_ok
|
||||
else
|
||||
render_error("项目关联搜索标签失败.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
ActiveRecord::Base.transaction do
|
||||
@project = Project.find_by_id(create_params[:project_id])
|
||||
return render_not_found unless @project.present?
|
||||
|
||||
@project_topic = ProjectTopic.find_by_id(params[:id])
|
||||
@project_topic_ralate = @project_topic.project_topic_ralates.find_by(project_id: @project.id)
|
||||
if @project_topic_ralate.destroy!
|
||||
render_ok
|
||||
else
|
||||
render_error("项目取消关联搜索标签失败.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def create_params
|
||||
params.permit(:project_id, :name)
|
||||
end
|
||||
end
|
|
@ -17,7 +17,16 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController
|
|||
|
||||
def destroy
|
||||
@result_object = Api::V1::Projects::Branches::DeleteService.call(@project, params[:name], current_user&.gitea_token)
|
||||
if @result_object
|
||||
if @result_object
|
||||
# 有开启的pr需要一同关闭
|
||||
# 1、删除本仓库中存在未关闭的pr,即本仓库分支1->分支2
|
||||
# 2、如果是fork仓库,考虑删除主仓库中存在未关闭的pr,即本仓库:分支1->主:分支2,同时分两种删除:1删除本仓库分支1,2删除主仓库分支2
|
||||
close_pull_requests_by(@project, params[:name])
|
||||
if @project.forked_from_project_id.present?
|
||||
# fork项目中删除分支
|
||||
close_pull_requests_by(@project.fork_project, params[:name])
|
||||
end
|
||||
|
||||
return render_ok
|
||||
else
|
||||
return render_error('删除分支失败!')
|
||||
|
@ -39,4 +48,19 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController
|
|||
def branch_params
|
||||
params.require(:branch).permit(:new_branch_name, :old_branch_name)
|
||||
end
|
||||
|
||||
def close_pull_requests_by(project, branch_name)
|
||||
open_pull_requests = project.pull_requests.opening.where(head: branch_name).or(project.pull_requests.opening.where(base: branch_name))
|
||||
if open_pull_requests.present?
|
||||
open_pull_requests.each do |pull_request|
|
||||
closed = PullRequests::CloseService.call(project.owner, project.repository, pull_request, current_user)
|
||||
if closed === true
|
||||
pull_request.project_trends.create!(user: current_user, project: project,action_type: ProjectTrend::CLOSE)
|
||||
# 合并请求下issue处理为关闭
|
||||
pull_request.issue&.update_attributes!({status_id:5})
|
||||
SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, pull_request.id) if Site.has_notice_menu?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,6 +3,6 @@ class Api::V1::Projects::CodeStatsController < Api::V1::BaseController
|
|||
|
||||
def index
|
||||
@result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {ref: params[:ref]}, current_user&.gitea_token)
|
||||
puts @result_object
|
||||
# puts @result_object
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
class Api::V1::Projects::CollaboratorsController < Api::V1::BaseController
|
||||
|
||||
before_action :require_public_and_member_above, only: [:index]
|
||||
|
||||
def index
|
||||
@collaborators = @project.all_collaborators.like(params[:keyword])
|
||||
@collaborators = kaminary_select_paginate(@collaborators)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
class Api::V1::Projects::ContributorsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:index, :stat]
|
||||
|
||||
# todo
|
||||
def index
|
||||
end
|
||||
|
||||
def stat
|
||||
@result_object = Api::V1::Projects::Contributors::StatService.call(@project, {branch: params[:branch], pass_year: params[:pass_year], page: page, limit: limit}, current_user&.gitea_token)
|
||||
end
|
||||
end
|
|
@ -4,6 +4,7 @@ class Api::V1::Projects::TagsController < Api::V1::BaseController
|
|||
def index
|
||||
@release_tags = @repository.version_releases.pluck(:tag_name)
|
||||
@result_object = Api::V1::Projects::Tags::ListService.call(@project, {page: page, limit: limit}, current_user&.gitea_token)
|
||||
puts @result_object
|
||||
end
|
||||
|
||||
before_action :require_operate_above, only: [:destroy]
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
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)
|
||||
Rails.logger.info "OpenkylinSignController=====#{@object_result}"
|
||||
if @object_result
|
||||
return render_ok
|
||||
else
|
||||
return render_error('签署失败!')
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def create_params
|
||||
params.permit(:login, :email, :nickname, :phone, :address)
|
||||
end
|
||||
end
|
|
@ -1,7 +1,17 @@
|
|||
class Api::V1::UsersController < Api::V1::BaseController
|
||||
|
||||
before_action :load_observe_user
|
||||
before_action :check_auth_for_observe_user
|
||||
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])
|
||||
render_ok
|
||||
end
|
||||
|
||||
def check_user_login
|
||||
return tip_exception(-1, "用户标识不存在") unless params[:login].present? && User.exists?(login: params[:login])
|
||||
render_ok
|
||||
end
|
||||
|
||||
def send_email_vefify_code
|
||||
code = %W(0 1 2 3 4 5 6 7 8 9)
|
||||
|
@ -9,21 +19,24 @@ class Api::V1::UsersController < Api::V1::BaseController
|
|||
mail = params[:email]
|
||||
code_type = params[:code_type]
|
||||
|
||||
status, message = InfoRiskControlService.call(mail, request.remote_ip)
|
||||
tip_exception(420, message) if status == 0
|
||||
|
||||
sign = Digest::MD5.hexdigest("#{OPENKEY}#{mail}")
|
||||
Rails.logger.info sign
|
||||
|
||||
tip_exception(501, "请求不合理") if sign != params[:smscode]
|
||||
|
||||
# 60s内不能重复发送
|
||||
send_email_limit_cache_key = "send_email_60_second_limit:#{mail}"
|
||||
tip_exception(-2, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key)
|
||||
send_email_control = LimitForbidControl::SendEmailCode.new(mail)
|
||||
tip_exception(-2, '邮件发送太频繁,请稍后再试') if send_email_control.forbid?
|
||||
# send_email_limit_cache_key = "send_email_60_second_limit:#{mail}"
|
||||
# tip_exception(-2, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key)
|
||||
# send_email_control = LimitForbidControl::SendEmailCode.new(mail)
|
||||
# tip_exception(-2, '邮件发送太频繁,请稍后再试') if send_email_control.forbid?
|
||||
begin
|
||||
UserMailer.update_email(mail, verification_code).deliver_now
|
||||
|
||||
Rails.cache.write(send_email_limit_cache_key, 1, expires_in: 1.minute)
|
||||
send_email_control.increment!
|
||||
# Rails.cache.write(send_email_limit_cache_key, 1, expires_in: 1.minute)
|
||||
# send_email_control.increment!
|
||||
rescue Exception => e
|
||||
logger_error(e)
|
||||
tip_exception(-2,"邮件发送失败,请稍后重试")
|
||||
|
|
|
@ -81,7 +81,7 @@ class ApplicationController < ActionController::Base
|
|||
# 判断用户的邮箱或者手机是否可用
|
||||
# params[:type] 1: 注册;2:忘记密码;3:绑定
|
||||
def check_mail_and_phone_valid login, type
|
||||
unless login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ || login =~ /^1\d{10}$/
|
||||
unless login =~ /\A[a-zA-Z0-9]+([._\-\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+\z/ || login =~ /^1\d{10}$/
|
||||
tip_exception(-2, "请输入正确的手机号或邮箱")
|
||||
end
|
||||
|
||||
|
@ -112,12 +112,12 @@ class ApplicationController < ActionController::Base
|
|||
# 邮箱类型的发送
|
||||
sigle_para = {email: value}
|
||||
# 60s内不能重复发送
|
||||
send_email_limit_cache_key = "send_email_60_second_limit:#{value}"
|
||||
tip_exception(-1, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key)
|
||||
# send_email_limit_cache_key = "send_email_60_second_limit:#{value}"
|
||||
# tip_exception(-1, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key)
|
||||
|
||||
# 短时间内不能大量发送
|
||||
send_email_control = LimitForbidControl::SendEmailCode.new(value)
|
||||
tip_exception(-1, '邮件发送太频繁,请稍后再试') if send_email_control.forbid?
|
||||
# # 短时间内不能大量发送
|
||||
# send_email_control = LimitForbidControl::SendEmailCode.new(value)
|
||||
# tip_exception(-1, '邮件发送太频繁,请稍后再试') if send_email_control.forbid?
|
||||
begin
|
||||
if send_type == 3
|
||||
UserMailer.find_password(value, code).deliver_now
|
||||
|
@ -126,8 +126,8 @@ class ApplicationController < ActionController::Base
|
|||
else
|
||||
UserMailer.register_email(value, code).deliver_now
|
||||
end
|
||||
Rails.cache.write(send_email_limit_cache_key, 1, expires_in: 1.minute)
|
||||
send_email_control.increment!
|
||||
# Rails.cache.write(send_email_limit_cache_key, 1, expires_in: 1.minute)
|
||||
# send_email_control.increment!
|
||||
# Mailer.run.email_register(code, value)
|
||||
rescue Exception => e
|
||||
logger_error(e)
|
||||
|
@ -680,6 +680,14 @@ class ApplicationController < ActionController::Base
|
|||
relation.page(page).per(limit)
|
||||
end
|
||||
|
||||
def kaminari_unlimit_paginate(relation)
|
||||
limit = params[:limit] || params[:per_page]
|
||||
limit = (limit.to_i.zero? || limit.to_i > 9999) ? 9999 : limit.to_i
|
||||
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
|
||||
|
||||
relation.page(page).per(limit)
|
||||
end
|
||||
|
||||
def kaminari_array_paginate(relation)
|
||||
limit = params[:limit] || params[:per_page]
|
||||
limit = (limit.to_i.zero? || limit.to_i > 20) ? 20 : limit.to_i
|
||||
|
@ -832,8 +840,340 @@ class ApplicationController < ActionController::Base
|
|||
HotSearchKeyword.add(keyword)
|
||||
end
|
||||
|
||||
# author: zxh
|
||||
# blockchain相关项目活动调用函数
|
||||
# return true: 表示上链操作成功; return false: 表示上链操作失败
|
||||
def push_activity_2_blockchain(activity_type, model)
|
||||
if activity_type == "issue_create"
|
||||
|
||||
project_id = model['project_id']
|
||||
project = Project.find(project_id)
|
||||
if project['use_blockchain'] == 0 || project['use_blockchain'] == false
|
||||
# 无需执行上链操作
|
||||
return true
|
||||
end
|
||||
|
||||
id = model['id']
|
||||
|
||||
owner_id = project['user_id']
|
||||
owner = User.find(owner_id)
|
||||
ownername = owner['login']
|
||||
identifier = project['identifier']
|
||||
|
||||
author_id = project['user_id']
|
||||
author = User.find(author_id)
|
||||
username = author['login']
|
||||
|
||||
action = 'opened'
|
||||
|
||||
title = model['subject']
|
||||
content = model['description']
|
||||
created_at = model['created_on']
|
||||
updated_at = model['updated_on']
|
||||
|
||||
# 调用区块链接口
|
||||
params = {
|
||||
"request-type": "upload issue info",
|
||||
"issue_id": "gitlink-" + id.to_s,
|
||||
"repo_id": "gitlink-" + project_id.to_s,
|
||||
"issue_number": 0, # 暂时不需要改字段
|
||||
"reponame": identifier,
|
||||
"ownername": ownername,
|
||||
"username": username,
|
||||
"action": action,
|
||||
"title": title,
|
||||
"content": content,
|
||||
"created_at": created_at,
|
||||
"updated_at": updated_at
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] == 10
|
||||
raise ApplicationService::Error, resp_body['message']
|
||||
elsif resp_body['status'] != 0
|
||||
raise ApplicationService::Error, "区块链接口请求失败."
|
||||
end
|
||||
|
||||
elsif activity_type == "issue_comment_create"
|
||||
issue_comment_id = model['id']
|
||||
issue_id = model['journalized_id']
|
||||
parent_id = model['parent_id'].nil? ? "" : model['parent_id']
|
||||
|
||||
issue = Issue.find(issue_id)
|
||||
issue_classify = issue['issue_classify'] # issue或pull_request
|
||||
project_id = issue['project_id']
|
||||
project = Project.find(project_id)
|
||||
|
||||
if project['use_blockchain'] == 0 || project['use_blockchain'] == false
|
||||
# 无需执行上链操作
|
||||
return
|
||||
end
|
||||
|
||||
identifier = project['identifier']
|
||||
owner_id = project['user_id']
|
||||
owner = User.find(owner_id)
|
||||
ownername = owner['login']
|
||||
|
||||
author_id = model['user_id']
|
||||
author = User.find(author_id)
|
||||
username = author['login']
|
||||
|
||||
action = 'created'
|
||||
|
||||
content = model['notes']
|
||||
created_at = model['created_on']
|
||||
|
||||
if issue_classify == "issue"
|
||||
params = {
|
||||
"request-type": "upload issue comment info",
|
||||
"issue_comment_id": "gitlink-" + issue_comment_id.to_s,
|
||||
"issue_comment_number": 0, # 暂时不需要
|
||||
"issue_number": 0, # 暂时不需要
|
||||
"issue_id": "gitlink-" + issue_id.to_s,
|
||||
"repo_id": "gitlink-" + project.id.to_s,
|
||||
"parent_id": parent_id.to_s,
|
||||
"reponame": identifier,
|
||||
"ownername": ownername,
|
||||
"username": username,
|
||||
"action": action,
|
||||
"content": content,
|
||||
"created_at": created_at,
|
||||
}.to_json
|
||||
elsif issue_classify == "pull_request"
|
||||
params = {
|
||||
"request-type": "upload pull request comment info",
|
||||
"pull_request_comment_id": "gitlink-" + issue_comment_id.to_s,
|
||||
"pull_request_comment_number": 0, # 不考虑该字段
|
||||
"pull_request_number": 0, # 不考虑该字段
|
||||
"pull_request_id": "gitlink-" + issue_id.to_s,
|
||||
"parent_id": parent_id.to_s,
|
||||
"repo_id": "gitlink-" + project.id.to_s,
|
||||
"reponame": identifier,
|
||||
"ownername": ownername,
|
||||
"username": username,
|
||||
"action": action,
|
||||
"content": content,
|
||||
"created_at": created_at,
|
||||
}.to_json
|
||||
end
|
||||
|
||||
# 调用区块链接口
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] == 10
|
||||
raise ApplicationService::Error, resp_body['message']
|
||||
elsif resp_body['status'] != 0
|
||||
raise ApplicationService::Error, "区块链接口请求失败."
|
||||
end
|
||||
elsif activity_type == "pull_request_create"
|
||||
# 调用区块链接口
|
||||
project_id = model['project_id']
|
||||
project = Project.find(project_id)
|
||||
if project['use_blockchain'] == 0 || project['use_blockchain'] == false
|
||||
# 无需执行上链操作
|
||||
return
|
||||
end
|
||||
|
||||
pull_request_id = model['id']
|
||||
identifier = project['identifier']
|
||||
owner_id = project['user_id']
|
||||
owner = User.find(owner_id)
|
||||
ownername = owner['login']
|
||||
|
||||
action = 'opened'
|
||||
|
||||
title = model['title']
|
||||
content = model['body']
|
||||
|
||||
source_branch = model['head']
|
||||
source_repo_id = model['fork_project_id'].nil? ? project_id : model['fork_project_id']
|
||||
|
||||
target_branch = model['base']
|
||||
target_repo_id = project_id
|
||||
|
||||
author_id = model['user_id']
|
||||
author = User.find(author_id)
|
||||
username = author['login']
|
||||
|
||||
created_at = model['created_at']
|
||||
updated_at = model['updated_at']
|
||||
|
||||
# 查询pull request对应的commit信息
|
||||
commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number'], current_user&.gitea_token)
|
||||
if commits.nil?
|
||||
raise ApplicationService::Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败
|
||||
end
|
||||
commit_shas = []
|
||||
commits.each do |c|
|
||||
commit_shas << c["Sha"]
|
||||
end
|
||||
params = {
|
||||
"request-type": "upload pull request info",
|
||||
"pull_request_id": "gitlink-" + pull_request_id.to_s,
|
||||
"pull_request_number": 0, # trustie没有该字段
|
||||
"repo_id": "gitlink-" + project_id.to_s,
|
||||
"ownername": ownername,
|
||||
"reponame": identifier,
|
||||
"username": username,
|
||||
"action": action,
|
||||
"title": title,
|
||||
"content": content,
|
||||
"source_branch": source_branch,
|
||||
"target_branch": target_branch,
|
||||
"reviewers": [], # trustie没有该字段
|
||||
"commit_shas": commit_shas,
|
||||
"merge_user": "", # trustie没有该字段
|
||||
"created_at": created_at,
|
||||
"updated_at": updated_at
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] == 9
|
||||
raise ApplicationService::Error, resp_body['message']
|
||||
elsif resp_body['status'] != 0
|
||||
raise ApplicationService::Error, "区块链接口请求失败."
|
||||
end
|
||||
elsif activity_type == "pull_request_merge"
|
||||
# 调用区块链接口
|
||||
project_id = model['project_id']
|
||||
project = Project.find(project_id)
|
||||
if project['use_blockchain'] == 0 || project['use_blockchain'] == false
|
||||
# 无需执行上链操作
|
||||
return
|
||||
end
|
||||
|
||||
pull_request_id = model['id']
|
||||
identifier = project['identifier']
|
||||
owner_id = project['user_id']
|
||||
owner = User.find(owner_id)
|
||||
ownername = owner['login']
|
||||
|
||||
action = 'merged'
|
||||
|
||||
created_at = model['created_at']
|
||||
updated_at = model['updated_at']
|
||||
|
||||
# 查询pull request对应的commit信息
|
||||
commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number'], current_user&.gitea_token)
|
||||
if commits.nil?
|
||||
raise ApplicationService::Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败
|
||||
end
|
||||
commit_shas = []
|
||||
commits.each do |c|
|
||||
commit_shas << c["Sha"]
|
||||
end
|
||||
|
||||
# 将pull request相关信息写入链上
|
||||
params = {
|
||||
"request-type": "upload pull request info",
|
||||
"pull_request_id": "gitlink-" + pull_request_id.to_s,
|
||||
"pull_request_number": 0, # trustie没有该字段
|
||||
"repo_id": "gitlink-" + project_id.to_s,
|
||||
"ownername": ownername,
|
||||
"reponame": identifier,
|
||||
"username": username,
|
||||
"action": action,
|
||||
"title": title,
|
||||
"content": content,
|
||||
"source_branch": source_branch,
|
||||
"target_branch": target_branch,
|
||||
"reviewers": [], # trustie没有该字段
|
||||
"commit_shas": commit_shas,
|
||||
"merge_user": "", # trustie没有该字段
|
||||
"created_at": created_at,
|
||||
"updated_at": updated_at
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] == 9
|
||||
raise ApplicationService::Error, resp_body['message']
|
||||
elsif resp_body['status'] != 0
|
||||
raise ApplicationService::Error, "区块链接口请求失败."
|
||||
end
|
||||
|
||||
|
||||
# 将commit相关信息写入链上
|
||||
commit_shas.each do |commit_sha|
|
||||
commit_diff = Gitea::Commit::DiffService.call(ownername, identifier, commit_sha, owner['gitea_token'])
|
||||
commit = Gitea::Commit::InfoService.call(ownername, identifier, commit_sha, owner['gitea_token'])
|
||||
params = {
|
||||
"request-type": "upload commit info",
|
||||
"commit_hash": commit_sha,
|
||||
"repo_id": "gitlink-" + project_id.to_s,
|
||||
"author": commit['commit']['author']['name'],
|
||||
"author_email": commit['commit']['author']['email'],
|
||||
"committer": commit['commit']['committer']['name'],
|
||||
"committer_email": commit['commit']['committer']['email'],
|
||||
"author_time": commit['commit']['author']['date'],
|
||||
"committer_time": commit['commit']['committer']['date'],
|
||||
"content": commit['commit']['message'],
|
||||
"commit_diff": commit_diff.present? ? commit_diff['Files'].to_s : ""
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] == 7
|
||||
raise ApplicationService::Error, resp_body['message']
|
||||
elsif resp_body['status'] != 0
|
||||
raise ApplicationService::Error, "区块链接口请求失败."
|
||||
end
|
||||
end
|
||||
|
||||
elsif activity_type == "pull_request_refuse"
|
||||
|
||||
# 调用区块链接口
|
||||
project_id = model['project_id']
|
||||
project = Project.find(project_id)
|
||||
if project['use_blockchain'] == 0 || project['use_blockchain'] == false
|
||||
# 无需执行上链操作
|
||||
return true
|
||||
end
|
||||
|
||||
pull_request_id = model['id']
|
||||
identifier = project['identifier']
|
||||
owner_id = project['user_id']
|
||||
owner = User.find(owner_id)
|
||||
ownername = owner['login']
|
||||
|
||||
action = 'refused'
|
||||
|
||||
# 将pull request相关信息写入链上
|
||||
params = {
|
||||
"request-type": "upload pull request info",
|
||||
"pull_request_id": "gitlink-" + pull_request_id.to_s,
|
||||
"pull_request_number": 0, # trustie没有该字段
|
||||
"repo_id": "gitlink-" + project_id.to_s,
|
||||
"ownername": ownername,
|
||||
"reponame": identifier,
|
||||
"username": username,
|
||||
"action": action,
|
||||
"title": title,
|
||||
"content": content,
|
||||
"source_branch": source_branch,
|
||||
"target_branch": target_branch,
|
||||
"reviewers": [], # trustie没有该字段
|
||||
"commit_shas": commit_shas,
|
||||
"merge_user": "", # trustie没有该字段
|
||||
"created_at": created_at,
|
||||
"updated_at": updated_at
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] == 9
|
||||
raise ApplicationService::Error, resp_body['message']
|
||||
elsif resp_body['status'] != 0
|
||||
raise ApplicationService::Error, "区块链接口请求失败."
|
||||
end
|
||||
end
|
||||
end
|
||||
def find_atme_receivers
|
||||
@atme_receivers = User.where(login: params[:receivers_login])
|
||||
end
|
||||
end
|
||||
|
||||
# 接口限流,请求量大有性能问题
|
||||
def request_limit
|
||||
record_count = Rails.cache.read("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}")
|
||||
if record_count.present?
|
||||
record_count = record_count + 1
|
||||
else
|
||||
record_count = 1
|
||||
end
|
||||
tip_exception("请求太快,请稍后再试。") if record_count > 100
|
||||
|
||||
Rails.cache.write("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}", record_count, expires_in: 1.minute)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -31,16 +31,20 @@ class AttachmentsController < ApplicationController
|
|||
|
||||
def get_file
|
||||
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
||||
url = base_url.starts_with?("https:") ? URI.encode(params[:download_url].to_s.gsub("http:", "https:")) : URI.encode(params[:download_url].to_s)
|
||||
url = base_url.starts_with?("https:") ? params[:download_url].to_s.gsub("http:", "https:") : params[:download_url].to_s
|
||||
if url.starts_with?(base_url) && !url.starts_with?("#{base_url}/repo")
|
||||
domain = GiteaService.gitea_config[:domain]
|
||||
api_url = GiteaService.gitea_config[:base_url]
|
||||
url = ("/repos"+url.split(base_url + "/api")[1]).gsub('?filepath=', '/').gsub('&', '?')
|
||||
request_url = [domain, api_url, url, "?ref=#{params[:ref]}&access_token=#{current_user&.gitea_token}"].join
|
||||
url = ("/repos"+url.split(base_url + "/api")[1])
|
||||
filepath, ref = url.split("/")[-1].split("?")
|
||||
url.gsub!(url.split("/")[-1], '')
|
||||
Rails.logger.info("url===#{url}")
|
||||
request_url = [domain, api_url, URI.encode(url), CGI.escape(filepath), "?ref=#{CGI.escape(ref.split('ref=')[1])}&access_token=#{User.where(admin: true).take&.gitea_token}"].join
|
||||
Rails.logger.info("request_url===#{request_url}")
|
||||
response = Faraday.get(request_url)
|
||||
filename = url.to_s.split("/").pop()
|
||||
filename = filepath
|
||||
else
|
||||
response = Faraday.get(url)
|
||||
response = Faraday.get(URI.encode(url))
|
||||
filename = params[:download_url].to_s.split("/").pop()
|
||||
end
|
||||
send_data(response.body.force_encoding("UTF-8"), filename: filename, type: "application/octet-stream", disposition: 'attachment')
|
||||
|
|
|
@ -39,6 +39,7 @@ class ClaimsController < ApplicationController
|
|||
|
||||
journal = Journal.new(journal_params)
|
||||
if journal.save
|
||||
SendTemplateMessageJob.perform_later('IssueClaim', current_user.id, @issue&.id)
|
||||
render file: 'app/views/claims/list.json.jbuilder'
|
||||
else
|
||||
normal_status(-1,"新建声明关联评论操作失败")
|
||||
|
|
|
@ -19,9 +19,10 @@ class CommitLogsController < ApplicationController
|
|||
params[:commits].each do |commit|
|
||||
commit_id = commit[:id]
|
||||
message = commit[:message]
|
||||
CommitLog.create(user: user, project: project, repository_id: repository_id,
|
||||
commit_log = 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)
|
||||
commit_log.project_trends.create(user_id: user.id, project_id: project&.id, action_type: "create") if user.id !=2
|
||||
# 统计数据新增
|
||||
CacheAsyncSetJob.perform_later("project_common_service", {commits: 1}, project.id)
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module Api::ProjectHelper
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def load_project
|
||||
def load_project
|
||||
namespace = params[:owner]
|
||||
repo = params[:repo]
|
||||
|
||||
|
@ -14,7 +14,7 @@ module Api::ProjectHelper
|
|||
else
|
||||
logger.info "###########:project not found"
|
||||
@project = nil
|
||||
render_not_found and return
|
||||
tip_exception(404, '您访问的页面不存在或已被删除')
|
||||
end
|
||||
@project
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Repository::LanguagesPercentagable
|
|||
def update_project_language(language)
|
||||
return if @project.project_language.present?
|
||||
db_language = ProjectLanguage.find_or_create_by!(name: language.keys.first.downcase.upcase_first)
|
||||
@project.update_column(:project_language_id, db_language.id)
|
||||
@project.update_attribute(:project_language_id, db_language.id)
|
||||
rescue
|
||||
return
|
||||
end
|
||||
|
|
|
@ -5,13 +5,17 @@ class ForksController < ApplicationController
|
|||
before_action :authenticate_project!, :authenticate_user!
|
||||
|
||||
def create
|
||||
@new_project = Projects::ForkService.new(current_user, @project, params[:organization]).call
|
||||
@new_project = Projects::ForkService.new(current_user, @project, params[:organization], params[:new_name], params[:new_identifier]).call
|
||||
end
|
||||
|
||||
private
|
||||
def authenticate_project!
|
||||
if current_user&.id == @project.user_id
|
||||
render_result(-1, "自己不能fork自己的项目")
|
||||
elsif @project.fork_users.where(user_id: current_user.id).present?
|
||||
fork = @project.fork_users.find_by(user_id: current_user.id)
|
||||
render json: { status: 0, id: fork.fork_project_id, identifier: fork.fork_project&.identifier, message: "fork失败,你已拥有了这个项目 #{fork.fork_project&.identifier}" }
|
||||
return
|
||||
elsif Project.exists?(user_id: current_user.id, identifier: @project.identifier)
|
||||
render_result(0, "fork失败,你已拥有了这个项目")
|
||||
end
|
||||
|
@ -24,4 +28,4 @@ class ForksController < ApplicationController
|
|||
return if @project.member?(current_user) || current_user.admin?
|
||||
render_forbidden('你没有权限操作')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,29 @@
|
|||
class IdentityVerificationsController < ApplicationController
|
||||
before_action :require_login
|
||||
before_action :require_profile_completed, only: [:create]
|
||||
|
||||
def index
|
||||
@id_verify = current_user.identity_verification
|
||||
return render_ok({data:nil}) unless @id_verify
|
||||
end
|
||||
|
||||
def create
|
||||
return tip_exception(-1, "您已提交过身份审核,请勿重复提交") if IdentityVerification.exists?(user:current_user)
|
||||
return tip_exception(-1, "身份证输入有误")unless create_params[:number] =~ User::VALID_NUMBER_REGEX
|
||||
@id_verify = IdentityVerification.new(create_params)
|
||||
@id_verify.user = current_user
|
||||
@id_verify.save
|
||||
end
|
||||
|
||||
def update
|
||||
return tip_exception(-1, "身份证输入有误")unless create_params[:number] =~ User::VALID_NUMBER_REGEX
|
||||
current_user.identity_verification.update(create_params.merge({ state: 0 }))
|
||||
current_user.update(id_card_verify: false)
|
||||
@id_verify = current_user.identity_verification
|
||||
end
|
||||
|
||||
private
|
||||
def create_params
|
||||
params.permit(:number, :name, :card_front, :card_back, :hold_card_front, :hold_card_back)
|
||||
end
|
||||
end
|
|
@ -2,8 +2,26 @@ class InstallationsController < ApplicationController
|
|||
include RegisterHelper
|
||||
before_action :require_login
|
||||
|
||||
# app详情
|
||||
def app
|
||||
@bot = Bot.find_by(uid: current_user.id)
|
||||
end
|
||||
|
||||
def index
|
||||
@install_bots = BotInstall.where(:installer_id => current_user.id)
|
||||
@install_bots = BotInstall.where(bot_id: get_bot_id).group(:installer_id)
|
||||
end
|
||||
|
||||
def show
|
||||
@install_bot = BotInstall.find_by(bot_id: get_bot_id, installer_id: params[:id]) || BotInstall.find_by(id: params[:id])
|
||||
tip_exception "参数installer_id错误" if @install_bot.blank?
|
||||
end
|
||||
|
||||
def repositories
|
||||
# 与github差异,所以取安装用户和bot对应所有的仓库
|
||||
# 必须使用access_tokens获取到bot的token才能查询
|
||||
tip_exception "无效Token" if current_user.platform != "bot"
|
||||
bot = Bot.find_by(uid: current_user.id)
|
||||
@install_bots = BotInstall.where(bot_id: bot.id).where(installer_id: params[:id])
|
||||
end
|
||||
|
||||
def update_secret
|
||||
|
@ -25,19 +43,45 @@ class InstallationsController < ApplicationController
|
|||
render_ok
|
||||
end
|
||||
|
||||
# 同步bot信息,回调地址和名称
|
||||
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.oauth_callback_url
|
||||
application.name = bot.name
|
||||
if bot.uid.present?
|
||||
bot_user = User.find_by(id: bot.uid)
|
||||
bot_user.update_column(:nickname, bot.name) if bot_user.present?
|
||||
end
|
||||
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
|
||||
begin
|
||||
@bot = Bot.find params[:id]
|
||||
tip_exception("该Bot已激活") if Doorkeeper::Application.find_by(uid: @bot.client_id, secret: @bot.client_secret).present?
|
||||
@bot.client_id = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_id].blank?
|
||||
@bot.client_id = SecureRandom.uuid.gsub("-", "") if params[:client_id].blank?
|
||||
@bot.client_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_secret].blank?
|
||||
@bot.private_key = OpenSSL::PKey::RSA::generate(2048).to_s
|
||||
@bot.owner_id = current_user.id
|
||||
ActiveRecord::Base.transaction do
|
||||
# 注册bot对应oauth应用
|
||||
Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: "https://gitlink.org.cn")
|
||||
Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: @bot.oauth_callback_url)
|
||||
# 注册bot对应用户
|
||||
result = autologin_register(User.generate_user_login('b'), nil, "#{SecureRandom.hex(6)}", 'bot', nickname: @bot.name)
|
||||
result = autologin_register(User.generate_user_login('b'), nil, "#{SecureRandom.hex(6)}", 'bot', nil, @bot.name)
|
||||
tip_exception(-1, result[:message]) if result[:message].present?
|
||||
@bot.uid = result[:user][:id]
|
||||
@bot.save
|
||||
|
@ -49,7 +93,8 @@ class InstallationsController < ApplicationController
|
|||
end
|
||||
|
||||
def access_tokens
|
||||
@install_bot = BotInstall.find params[:id]
|
||||
@install_bot = BotInstall.find_by(bot_id: get_bot_id, installer_id: params[:id]) || BotInstall.find_by(id: params[:id])
|
||||
tip_exception "参数installer_id错误" if @install_bot.blank?
|
||||
@bot = @install_bot.bot
|
||||
@application = Doorkeeper::Application.find_by(uid: @bot.client_id, secret: @bot.client_secret)
|
||||
tip_exception("该Bot未激活") if @application.blank?
|
||||
|
@ -57,11 +102,26 @@ class InstallationsController < ApplicationController
|
|||
@access_token = Doorkeeper::AccessToken.create!({ :application_id => @application.id,
|
||||
:resource_owner_id => @bot.uid,
|
||||
:scopes => "public write",
|
||||
:expires_in => "604800",
|
||||
:expires_in => "2592000",
|
||||
:use_refresh_token => true
|
||||
})
|
||||
@install_bot.update_attributes!(state: 1)
|
||||
render_ok(token: @access_token.token)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_bot_id
|
||||
header = request.authorization
|
||||
pattern = /^Bearer /i
|
||||
token = header.gsub(pattern, "")
|
||||
decoded_token = JWT.decode token, nil, false
|
||||
# 前面已验证token有效期和正确性
|
||||
decoded_token[0]["iss"]
|
||||
rescue JWT::DecodeError
|
||||
Rails.logger.error "jwt token decode error:#{token}"
|
||||
tip_exception("无效Token")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
class IssuesController < ApplicationController
|
||||
before_action :require_login, except: [:index, :show, :index_chosen]
|
||||
before_action :require_login, except: [:index, :show, :index_chosen, :index_to_name]
|
||||
before_action :require_profile_completed, only: [:create]
|
||||
before_action :load_project
|
||||
before_action :set_user
|
||||
before_action :check_menu_authorize, except: [:index_chosen]
|
||||
before_action :check_issue_permission
|
||||
before_action :operate_issue_permission, only:[:create, :update, :destroy, :clean, :series_update, :copy]
|
||||
before_action :check_project_public, only: [:index ,:show, :copy, :index_chosen, :close_issue]
|
||||
before_action :check_project_public, only: [:index ,:show, :copy, :index_chosen, :close_issue, :index_to_name]
|
||||
|
||||
before_action :set_issue, only: [:edit, :update, :destroy, :show, :copy, :close_issue, :lock_issue]
|
||||
before_action :check_token_enough, :find_atme_receivers, only: [:create, :update]
|
||||
|
@ -49,6 +49,27 @@ class IssuesController < ApplicationController
|
|||
@issue_chosen = issue_left_chosen(@project, nil)
|
||||
end
|
||||
|
||||
def index_to_name
|
||||
issues_index = params[:index].map(&:to_i)
|
||||
exit_index = []
|
||||
issues_result = @project.issues.where(project_issues_index:issues_index).map{ |e|
|
||||
exit_index << e.project_issues_index
|
||||
{
|
||||
id:e.id,
|
||||
project_issues_index:e.project_issues_index,
|
||||
subject:e.subject
|
||||
}
|
||||
|
||||
}
|
||||
not_exit = issues_index - exit_index
|
||||
not_exit.map{|e|
|
||||
issues_result << {id: nil,
|
||||
project_issues_index:e,
|
||||
subject: nil}
|
||||
}
|
||||
render json: issues_result
|
||||
end
|
||||
|
||||
def commit_issues
|
||||
issues = @project.issues.issue_issue.includes(:user,:tracker)
|
||||
issues = issues.where(is_private: false) unless current_user.present? && (current_user.admin? || @project.member?(current_user))
|
||||
|
@ -111,7 +132,9 @@ class IssuesController < ApplicationController
|
|||
issue_params = issue_send_params(params)
|
||||
Issues::CreateForm.new({subject: issue_params[:subject], description: issue_params[:description].blank? ? issue_params[:description] : issue_params[:description].b}).validate!
|
||||
@issue = Issue.new(issue_params)
|
||||
@issue.project_issues_index = @project.get_last_project_issues_index + 1
|
||||
if @issue.save!
|
||||
@project.del_project_issue_cache_delete_count
|
||||
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if Site.has_notice_menu?
|
||||
SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) if Site.has_notice_menu?
|
||||
if params[:attachment_ids].present?
|
||||
|
@ -149,6 +172,7 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
|
||||
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||
|
||||
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) if params[:status_id].to_i == 5
|
||||
|
||||
|
||||
|
@ -157,6 +181,17 @@ class IssuesController < ApplicationController
|
|||
# 新增时向grimoirelab推送事件
|
||||
IssueWebhookJob.set(wait: 5.seconds).perform_later(@issue.id)
|
||||
|
||||
if Site.has_blockchain? && @project.use_blockchain
|
||||
# author: zxh
|
||||
# 扣除发起人的token
|
||||
if @issue.blockchain_token_num > 0
|
||||
Blockchain::CreateIssue.call(user_id: @issue.author_id, project_id: @issue.project_id, token_num: @issue.blockchain_token_num)
|
||||
end
|
||||
|
||||
# 调用上链API存证
|
||||
push_activity_2_blockchain("issue_create", @issue)
|
||||
end
|
||||
|
||||
render json: {status: 0, message: "创建成功", id: @issue.id}
|
||||
else
|
||||
normal_status(-1, "创建失败")
|
||||
|
@ -304,6 +339,7 @@ class IssuesController < ApplicationController
|
|||
login = @issue.user.try(:login)
|
||||
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigned_to_id, @issue.author_id) if Site.has_notice_menu?
|
||||
if @issue.destroy
|
||||
@project.incre_project_issue_cache_delete_count
|
||||
if issue_type == "2" && status_id != 5
|
||||
post_to_chain("add", token, login)
|
||||
end
|
||||
|
@ -543,7 +579,8 @@ class IssuesController < ApplicationController
|
|||
branch_name: params[:branch_name].to_s,
|
||||
issue_classify: "issue",
|
||||
author_id: current_user.id,
|
||||
project_id: @project.id
|
||||
project_id: @project.id,
|
||||
blockchain_token_num: params[:blockchain_token_num]
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -46,11 +46,17 @@ class JournalsController < ApplicationController
|
|||
end
|
||||
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||
AtmeService.call(current_user, @atme_receivers, journal) if @atme_receivers.size > 0
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('PullRequestComment', @issue&.id, current_user.id, journal.id, 'created', {})
|
||||
# @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "journal")
|
||||
|
||||
# author: zxh
|
||||
# 调用上链API
|
||||
push_activity_2_blockchain("issue_comment_create", journal) if Site.has_blockchain? && @project.use_blockchain
|
||||
|
||||
render :json => { status: 0, message: "评论成功", id: journal.id}
|
||||
# normal_status(0, "评论成功")
|
||||
else
|
||||
normal_status(-1, "评论失败")
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -61,6 +67,7 @@ class JournalsController < ApplicationController
|
|||
|
||||
def destroy
|
||||
if @journal.destroy #如果有子评论,子评论删除吗?
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('PullRequestComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!))
|
||||
Journal.children_journals(@journal.id).destroy_all
|
||||
normal_status(0, "评论删除成功")
|
||||
else
|
||||
|
|
|
@ -8,6 +8,18 @@ class MainController < ApplicationController
|
|||
render :json => { status: 0, message: Time.now.to_i }
|
||||
end
|
||||
|
||||
def test_404
|
||||
status_code = 404
|
||||
status = status_code.to_s
|
||||
fname = %w[404 403 422 500].include?(status) ? status : "unknown"
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render template: "/shared/#{fname}", handler: [:erb], status: status }
|
||||
format.xml { render :xml => Laboratory.limit(1).to_xml, status: status }
|
||||
format.all { render body: nil, status: status }
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
domain_session = params[:_educoder_session]
|
||||
if domain_session
|
||||
|
@ -24,6 +36,8 @@ class MainController < ApplicationController
|
|||
# TODO: 这块之后需要整合,者架构重新变化,统一跳转到index后再路由分发
|
||||
if params[:path] && params[:path]&.include?("h5educoderbuild") && params[:path].split("/").first == "h5educoderbuild"
|
||||
render file: 'public/h5educoderbuild/index.html', :layout => false, :content_type=> 'text/html'
|
||||
elsif params[:path].to_s.include?("test_404")
|
||||
test_404
|
||||
else
|
||||
render file: 'public/react/build/index.html', :layout => false, :content_type=> 'text/html'
|
||||
end
|
||||
|
|
|
@ -49,24 +49,29 @@ class Oauth::EducoderController < Oauth::BaseController
|
|||
open_user = OpenUsers::Educoder.find_by(uid: result['login'])
|
||||
if open_user.present? && open_user.user.present?
|
||||
successful_authentication(open_user.user)
|
||||
redirect_to root_path(new_user: false)
|
||||
return
|
||||
else
|
||||
if current_user.blank? || !current_user.logged?
|
||||
new_user = true
|
||||
login = User.generate_login('E')
|
||||
reg_result = autologin_register(login,"#{login}@forge.com", "Ec#{login}2021#", 'educoder', true)
|
||||
if reg_result[:message].blank?
|
||||
open_user = OpenUsers::Educoder.create!(user_id: reg_result[:user][:id], uid: result['login'], extra: result)
|
||||
autosync_register_trustie(login, "Ec#{login}2021#", "#{login}@forge.com")
|
||||
successful_authentication(open_user.user)
|
||||
else
|
||||
render_error(reg_result[:message])
|
||||
end
|
||||
session[:unionid] = result['login']
|
||||
# login = User.generate_login('E')
|
||||
# reg_result = autologin_register(login,"#{login}@forge.com", "Ec#{login}2021#", 'educoder', true)
|
||||
# if reg_result[:message].blank?
|
||||
# open_user = OpenUsers::Educoder.create!(user_id: reg_result[:user][:id], uid: result['login'], extra: result)
|
||||
# autosync_register_trustie(login, "Ec#{login}2021#", "#{login}@forge.com")
|
||||
# successful_authentication(open_user.user)
|
||||
# else
|
||||
# render_error(reg_result[:message])
|
||||
# end
|
||||
else
|
||||
OpenUsers::Educoder.create!(user: current_user, uid: result['login'], extra: result)
|
||||
end
|
||||
end
|
||||
Rails.logger.info("[OAuth2] session[:unionid] -> #{session[:unionid]}")
|
||||
redirect_to "/bindlogin/educoder"
|
||||
|
||||
redirect_to root_path(new_user: new_user)
|
||||
# redirect_to root_path(new_user: new_user)
|
||||
rescue Exception => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
class Organizations::ClasController < Organizations::BaseController
|
||||
before_action :load_organization
|
||||
before_action :load_cla, only: [:show, :update, :destroy]
|
||||
before_action :check_user_can_edit_org, only: [:create, :update, :destroy]
|
||||
|
||||
def index
|
||||
@cla = @organization.cla
|
||||
end
|
||||
|
||||
def show
|
||||
@is_admin = can_edit_org?
|
||||
@is_member = @organization.is_member?(current_user.id)
|
||||
@is_sign = @organization.is_sign?(current_user.id)
|
||||
@cla_sign_email = if @is_sign
|
||||
@organization.cla_sign_email(current_user.id)
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
tip_exception("您的组织还未拥有创建CLA权限,请联系管理员") if @organization.enabling_cla == false
|
||||
ActiveRecord::Base.transaction do
|
||||
if @organization.cla.present?
|
||||
return tip_exception("组织已存在CLA!")
|
||||
else
|
||||
Organizations::CreateClaForm.new(cla_params).validate!
|
||||
@cla = Cla.build(cla_params,@organization.id)
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def update
|
||||
ActiveRecord::Base.transaction do
|
||||
Organizations::CreateClaForm.new(cla_params).validate!
|
||||
@cla.update(cla_params)
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def destroy
|
||||
tip_exception("组织CLA已被签署,无法删除") if @cla.user_clas.size > 0
|
||||
ActiveRecord::Base.transaction do
|
||||
@cla.destroy!
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def cla_params
|
||||
params.permit(:name, :key, :content, :pr_need)
|
||||
end
|
||||
|
||||
def load_organization
|
||||
@organization = Organization.find_by(login: params[:organization_id]) || Organization.find_by(id: params[:organization_id])
|
||||
return render_not_found("组织不存在") if @organization.nil?
|
||||
end
|
||||
|
||||
def load_cla
|
||||
@cla = Cla.find_by!(organization:@organization, key: params[:id])
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,56 @@
|
|||
class Organizations::IsPinnedProjectsController < Organizations::BaseController
|
||||
before_action :load_organization
|
||||
|
||||
def index
|
||||
@is_pinned_projects = @organization.pinned_projects.order(position: :desc, created_at: :asc).includes(project: [:project_category, :project_language, :repository]).order(position: :desc)
|
||||
@is_pinned_projects = kaminari_paginate(@is_pinned_projects)
|
||||
end
|
||||
|
||||
def pin
|
||||
project_ids = params[:is_pinned_project_ids] || []
|
||||
@organization.is_pinned_project_ids = project_ids
|
||||
|
||||
render_ok
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
render_not_found
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def update
|
||||
@pinned_project = PinnedProject.find_by_id(params[:id])
|
||||
@pinned_project.attributes = pinned_project_params
|
||||
if @pinned_project.save
|
||||
render_ok
|
||||
else
|
||||
render_error
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_organization
|
||||
@organization = Organization.find_by(login: params[:organization_id]) || Organization.find_by(id: params[:organization_id])
|
||||
return render_not_found("组织不存在") if @organization.nil?
|
||||
return render_forbidden("没有查看组织的权限") if org_limited_condition || org_privacy_condition
|
||||
end
|
||||
|
||||
# def is_pinned_project_ids
|
||||
# if params[:is_pinned_project_ids].present?
|
||||
# return params[:is_pinned_project_ids].select { |id| @organization.full_member_projects.visible.pluck(:id).include?(id.to_i) }
|
||||
# end
|
||||
# if params[:is_pinned_project_id].present?
|
||||
# return @organization.is_pinned_project_ids unless @organization.full_member_projects.visible.pluck(:id).include?(params[:is_pinned_project_id].to_i)
|
||||
# return @organization.is_pinned_project_ids.include?(params[:is_pinned_project_id].to_i) ? @organization.is_pinned_project_ids : @organization.is_pinned_project_ids.push(params[:is_pinned_project_id].to_i)
|
||||
# end
|
||||
# end
|
||||
|
||||
def pinned_project_params
|
||||
params.require(:pinned_project).permit(:position)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,8 +1,8 @@
|
|||
class Organizations::OrganizationsController < Organizations::BaseController
|
||||
before_action :require_login, except: [:index, :show, :recommend]
|
||||
before_action :require_profile_completed, only: [:create]
|
||||
before_action :require_login, except: [:index, :show, :recommend, :languages]
|
||||
# before_action :require_profile_completed, only: [:create]
|
||||
before_action :convert_image!, only: [:create, :update]
|
||||
before_action :load_organization, only: [:show, :update, :destroy]
|
||||
before_action :load_organization, only: [:show, :update, :destroy, :update_news, :update_memo, :update_other, :languages]
|
||||
before_action :check_user_can_edit_org, only: [:update, :destroy]
|
||||
|
||||
def index
|
||||
|
@ -62,6 +62,46 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
|||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def update_news
|
||||
@organization.organization_extension.update_attributes!(news_banner_id: params[:news_banner_id],
|
||||
news_title: params[:news_title],
|
||||
news_url: params[:news_url],
|
||||
news_content: params[:news_content])
|
||||
render_ok
|
||||
end
|
||||
|
||||
def update_memo
|
||||
@organization.organization_extension.update_attributes!(memo: params[:memo])
|
||||
render_ok
|
||||
end
|
||||
|
||||
def update_other
|
||||
@organization.organization_extension.update_attributes!(news_banner_id: params[:news_banner_id],
|
||||
news_content: params[:news_content],
|
||||
news_title: params[:news_title],
|
||||
news_url: params[:news_url],
|
||||
memo: params[:memo])
|
||||
render_ok
|
||||
end
|
||||
|
||||
def languages
|
||||
projects = @organization.projects
|
||||
projects_count = @organization.projects.count
|
||||
|
||||
languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}/#{projects_count}/2023", :expires_in => 1.days) do
|
||||
total_languages(projects)
|
||||
end
|
||||
|
||||
languages_hash = languages_hash.sort { |x, y| y[1] <=> x[1] }
|
||||
sort_hash = Hash[*languages_hash.flatten]
|
||||
total_byte_size = sort_hash.values.sum
|
||||
# Rails.logger.info "languages_hash=============#{sort_hash}"
|
||||
sort_hash= sort_hash.transform_values { |v|
|
||||
ActionController::Base.helpers.number_to_percentage((v * 100 / total_byte_size), precision: 1)
|
||||
}.select { |k, v| v != "0.0%" }
|
||||
render json: sort_hash
|
||||
end
|
||||
|
||||
def destroy
|
||||
tip_exception("密码不正确") unless current_user.check_password?(password)
|
||||
ActiveRecord::Base.transaction do
|
||||
|
@ -144,5 +184,28 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
|||
# 更新对应所属分类下的项目数量(私有)
|
||||
project.project_category.decrement!(:private_projects_count, 1) if project.project_category.present?
|
||||
end
|
||||
|
||||
def total_languages(projects)
|
||||
languages_hash ={}
|
||||
projects.each do |p|
|
||||
result = Gitea::Repository::Languages::ListService.call(p.owner.login,
|
||||
p.identifier, current_user&.gitea_token)
|
||||
next unless result[:status] === :success
|
||||
total_byte_size = result[:body].values.sum
|
||||
hash = result[:body].transform_values { |v|
|
||||
(v * 100.0 / total_byte_size).to_f
|
||||
}
|
||||
|
||||
hash.each do |key,value|
|
||||
# Rails.logger.info "key=============#{key}:#{value}"
|
||||
if languages_hash.has_key?(key)
|
||||
languages_hash[key] = languages_hash[key] + value
|
||||
else
|
||||
languages_hash[key] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
languages_hash
|
||||
end
|
||||
|
||||
end
|
|
@ -8,14 +8,17 @@ class Organizations::ProjectsController < Organizations::BaseController
|
|||
.joins(team_projects: {team: :team_users})
|
||||
.where(team_users: {user_id: current_user.id}).to_sql
|
||||
@projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects")
|
||||
|
||||
@projects = @projects.ransack(name_or_identifier_cont: params[:search]).result if params[:search].present?
|
||||
# 表情处理
|
||||
keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
@projects = @projects.ransack(name_or_identifier_cont: keywords).result if params[:search].present?
|
||||
@projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}")
|
||||
@projects = paginate(@projects)
|
||||
end
|
||||
|
||||
def search
|
||||
tip_exception("请输入搜索关键词") if params[:search].nil?
|
||||
# 表情处理
|
||||
keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
public_projects_sql = @organization.projects.where(is_public: true).to_sql
|
||||
private_projects_sql = @organization.projects
|
||||
.where(is_public: false)
|
||||
|
@ -23,7 +26,7 @@ class Organizations::ProjectsController < Organizations::BaseController
|
|||
.where(team_users: {user_id: current_user.id}).to_sql
|
||||
@projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects")
|
||||
|
||||
@projects = @projects.ransack(name_or_identifier_cont: params[:search]).result
|
||||
@projects = @projects.ransack(name_or_identifier_cont: keywords).result
|
||||
@projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}")
|
||||
end
|
||||
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
class ProjectRankController < ApplicationController
|
||||
# 根据时间获取热门项目
|
||||
def index
|
||||
def index
|
||||
limit = 9
|
||||
limit = params[:limit].to_i - 1 if params[:limit].present?
|
||||
limit = 99 if limit > 99
|
||||
$redis_cache.zunionstore("recent-days-project-rank-#{time}", get_timeable_key_names)
|
||||
deleted_data = $redis_cache.smembers("v2-project-rank-deleted")
|
||||
$redis_cache.zrem("recent-days-project-rank-#{time}", deleted_data) unless deleted_data.blank?
|
||||
@project_rank = $redis_cache.zrevrange("recent-days-project-rank-#{time}", 0, 9, withscores: true)
|
||||
@project_rank = $redis_cache.zrevrange("recent-days-project-rank-#{time}", 0, limit, withscores: true)
|
||||
rescue Exception => e
|
||||
@project_rank = []
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class ProjectTrendsController < ApplicationController
|
||||
before_action :load_repository
|
||||
before_action :check_project_public
|
||||
before_action :load_repository, except: [:last]
|
||||
before_action :check_project_public, except: [:last]
|
||||
|
||||
def index
|
||||
project_trends = @project.project_trends.preload(:user, trend: :user, project: :owner)
|
||||
|
@ -42,6 +42,14 @@ class ProjectTrendsController < ApplicationController
|
|||
@project_trends = project_trends.page(@page).per(@limit)
|
||||
end
|
||||
|
||||
def last
|
||||
project_trends = ProjectTrend.preload(:user, trend: :user, project: :owner).order("id desc")
|
||||
@page = params[:page] || 1
|
||||
@limit = params[:limit] || 20
|
||||
@project_trends_count = project_trends.count
|
||||
@project_trends = project_trends.page(@page).per(@limit)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_project_public
|
||||
|
|
|
@ -4,11 +4,12 @@ class ProjectsController < ApplicationController
|
|||
include ProjectsHelper
|
||||
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_profile_completed, only: [:create, :migrate]
|
||||
before_action :load_repository, except: %i[index group_type_list migrate create recommend banner_recommend]
|
||||
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,:page_migrate,:verify_auth_token]
|
||||
before_action :load_repository, except: %i[index group_type_list migrate page_migrate create recommend banner_recommend verify_auth_token]
|
||||
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
||||
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
||||
before_action :request_limit, only: %i[index]
|
||||
|
||||
def menu_list
|
||||
menu = []
|
||||
|
@ -34,14 +35,15 @@ class ProjectsController < ApplicationController
|
|||
def index
|
||||
scope = current_user.logged? ? Projects::ListQuery.call(params, current_user.id) : Projects::ListQuery.call(params)
|
||||
|
||||
@projects = kaminari_paginate(scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units))
|
||||
@projects = kaminari_paginate(scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units, :project_topics))
|
||||
# @projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units)
|
||||
|
||||
category_id = params[:category_id]
|
||||
@total_count =
|
||||
if category_id.blank?
|
||||
# ps = ProjectStatistic.first
|
||||
# ps.common_projects_count + ps.mirror_projects_count unless ps.blank?
|
||||
if category_id.blank? && params[:search].blank? && params[:topic_id].blank?
|
||||
# 默认查询时count性能问题处理
|
||||
ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count
|
||||
elsif params[:search].present? || params[:topic_id].present?
|
||||
@projects.total_count
|
||||
else
|
||||
cate = ProjectCategory.find_by(id: category_id)
|
||||
|
@ -54,25 +56,31 @@ class ProjectsController < ApplicationController
|
|||
Projects::CreateForm.new(project_params).validate!
|
||||
@project = Projects::CreateService.new(current_user, project_params).call
|
||||
OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(@project&.id, current_user.id)
|
||||
UpdateProjectTopicJob.perform_later(@project.id) if @project.id.present?
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def verify_auth_token
|
||||
data = Projects::VerifyAuthTokenService.call(params[:clone_addr], params[:auth_token])
|
||||
render_ok({data: data})
|
||||
end
|
||||
|
||||
def migrate
|
||||
Projects::MigrateForm.new(mirror_params).validate!
|
||||
|
||||
@project =
|
||||
@project =
|
||||
if EduSetting.get("mirror_address").to_s.include?("github") && enable_accelerator?(mirror_params[:clone_addr])
|
||||
source_clone_url = mirror_params[:clone_addr]
|
||||
uid_logger("########## 已动加速器 ##########")
|
||||
result = Gitea::Accelerator::MigrateService.call(mirror_params)
|
||||
if result[:status] == :success
|
||||
Rails.logger.info "########## 加速镜像成功 ########## "
|
||||
Projects::MigrateService.call(current_user,
|
||||
mirror_params.merge(source_clone_url: source_clone_url,
|
||||
clone_addr: accelerator_url(mirror_params[:repository_name])))
|
||||
Projects::MigrateService.call(current_user,
|
||||
mirror_params.merge(source_clone_url: source_clone_url,
|
||||
clone_addr: accelerator_url(mirror_params[:repository_name])))
|
||||
else
|
||||
Projects::MigrateService.call(current_user, mirror_params)
|
||||
end
|
||||
|
@ -89,12 +97,54 @@ class ProjectsController < ApplicationController
|
|||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
|
||||
def page_migrate
|
||||
return normal_status(-1, "您还未开通Page服务,无法进行新建站点") unless current_user.id_card_verify
|
||||
return normal_status(-1, "你已使用了 #{page_site_params[:identifier]} 作为page标识") if Page.exists?(identifier: page_site_params[:identifier], user: current_user)
|
||||
|
||||
Projects::MigrateForm.new(mirror_params).validate!
|
||||
|
||||
@project =
|
||||
if EduSetting.get("mirror_address").to_s.include?("github") && enable_accelerator?(mirror_params[:clone_addr])
|
||||
source_clone_url = mirror_params[:clone_addr]
|
||||
uid_logger("########## 已动加速器 ##########")
|
||||
result = Gitea::Accelerator::MigrateService.call(mirror_params)
|
||||
if result[:status] == :success
|
||||
Rails.logger.info "########## 加速镜像成功 ########## "
|
||||
Projects::MigrateService.call(current_user,
|
||||
mirror_params.merge(source_clone_url: source_clone_url,
|
||||
clone_addr: accelerator_url(mirror_params[:repository_name])))
|
||||
else
|
||||
Projects::MigrateService.call(current_user, mirror_params)
|
||||
end
|
||||
elsif EduSetting.get("mirror_address").to_s.include?("cnpmjs") && mirror_params[:clone_addr].include?("github.com")
|
||||
source_clone_url = mirror_params[:clone_addr]
|
||||
clone_url = source_clone_url.gsub('github.com', 'github.com.cnpmjs.org')
|
||||
uid_logger("########## 更改clone_addr ##########")
|
||||
Projects::MigrateService.call(current_user, mirror_params.merge(source_clone_url: source_clone_url, clone_addr: clone_url))
|
||||
else
|
||||
Projects::MigrateService.call(current_user, mirror_params)
|
||||
end
|
||||
if @project.present?
|
||||
page = Page.new page_site_params
|
||||
page.user = current_user
|
||||
page.project = @project
|
||||
end
|
||||
|
||||
if page.save
|
||||
render json: page
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def branches
|
||||
return @branches = [] unless @project.forge?
|
||||
|
||||
# result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier)
|
||||
result = Gitea::Repository::Branches::ListNameService.call(@owner, @project.identifier, params[:name])
|
||||
@branches = result.is_a?(Hash) ? (result.key?(:status) ? [] : result["branch_name"]) : result
|
||||
@branches = result.is_a?(Hash) ? (result.key?(:status) ? [] : result) : result
|
||||
end
|
||||
|
||||
def branches_slice
|
||||
|
@ -128,7 +178,14 @@ class ProjectsController < ApplicationController
|
|||
ActiveRecord::Base.transaction do
|
||||
# TODO:
|
||||
# 临时特殊处理修改website、lesson_url操作方法
|
||||
if project_params.has_key?("website")
|
||||
if project_params.has_key?("website")
|
||||
if params[:project_topic_names].is_a?(Array)
|
||||
ProjectTopicRalate.where(project: @project).destroy_all
|
||||
params[:project_topic_names].each do |name|
|
||||
project_topic = ProjectTopic.find_or_create_by!(name: name.downcase)
|
||||
project_topic.project_topic_ralates.find_or_create_by!(project: @project)
|
||||
end
|
||||
end
|
||||
@project.update(project_params)
|
||||
elsif project_params.has_key?("default_branch")
|
||||
@project.update(project_params)
|
||||
|
@ -137,11 +194,11 @@ class ProjectsController < ApplicationController
|
|||
}
|
||||
Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params)
|
||||
else
|
||||
validate_params = project_params.slice(:name, :description,
|
||||
:project_category_id, :project_language_id, :private, :identifier)
|
||||
|
||||
validate_params = project_params.slice(:name, :description,
|
||||
:project_category_id, :project_language_id, :private, :identifier)
|
||||
|
||||
Projects::UpdateForm.new(validate_params.merge(user_id: @project.user_id, project_identifier: @project.identifier, project_name: @project.name)).validate!
|
||||
|
||||
|
||||
private = @project.forked_from_project.present? ? !@project.forked_from_project.is_public : params[:private] || false
|
||||
|
||||
new_project_params = project_params.except(:private).merge(is_public: !private)
|
||||
|
@ -154,7 +211,7 @@ class ProjectsController < ApplicationController
|
|||
name: @project.identifier
|
||||
}
|
||||
gitea_repo = Gitea::Repository::UpdateService.call(@owner, @project&.repository&.identifier, gitea_params)
|
||||
@project.repository.update_attributes({hidden: gitea_repo["private"], identifier: gitea_repo["name"]})
|
||||
@project.repository.update_attributes({ hidden: gitea_repo["private"], identifier: gitea_repo["name"] })
|
||||
# 更新对应所属分类下的项目数量(私有)
|
||||
before_is_public = @project.previous_changes[:is_public].present? ? @project.previous_changes[:is_public][0] : @project.is_public
|
||||
after_is_public = @project.previous_changes[:is_public].present? ? @project.previous_changes[:is_public][1] : @project.is_public
|
||||
|
@ -195,13 +252,13 @@ class ProjectsController < ApplicationController
|
|||
|
||||
def quit
|
||||
user_is_admin = current_user.admin? || @project.manager?(current_user)
|
||||
if !user_is_admin && @project.member(current_user.id) && @project.forge?
|
||||
if !user_is_admin && @project.member(current_user.id) && @project.forge?
|
||||
ActiveRecord::Base.transaction do
|
||||
Projects::DeleteMemberInteractor.call(@project.owner, @project, current_user)
|
||||
SendTemplateMessageJob.perform_later('ProjectMemberLeft', current_user.id, current_user.id, @project.id) if Site.has_notice_menu?
|
||||
render_ok
|
||||
end
|
||||
else
|
||||
else
|
||||
render_forbidden('你不能退出该仓库')
|
||||
end
|
||||
rescue Exception => e
|
||||
|
@ -230,6 +287,13 @@ class ProjectsController < ApplicationController
|
|||
def simple
|
||||
# 为了缓存活跃项目的基本信息,后续删除
|
||||
Cache::V2::ProjectCommonService.new(@project.id).read
|
||||
# 项目名称,标识,所有者变化时重置缓存
|
||||
project_common = $redis_cache.hgetall("v2-project-common:#{@project.id}")
|
||||
if project_common.present?
|
||||
if project_common["name"] != @project.name || project_common["identifier"] != @project.identifier || project_common["owner_id"] != @project.user_id
|
||||
Cache::V2::ProjectCommonService.new(@project.id).reset
|
||||
end
|
||||
end
|
||||
json_response(@project, current_user)
|
||||
end
|
||||
|
||||
|
@ -258,7 +322,7 @@ class ProjectsController < ApplicationController
|
|||
if @project_detail.save!
|
||||
attachment_ids = Array(params[:attachment_ids])
|
||||
logger.info "=============> #{Array(params[:attachment_ids])}"
|
||||
@attachments = Attachment.where(id: attachment_ids)
|
||||
@attachments = Attachment.where(id: attachment_ids)
|
||||
@attachments.update_all(
|
||||
container_id: @project_detail.id,
|
||||
container_type: @project_detail.model_name.name,
|
||||
|
@ -271,16 +335,22 @@ class ProjectsController < ApplicationController
|
|||
|
||||
|
||||
private
|
||||
|
||||
def project_params
|
||||
params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url, :default_branch, :identifier,
|
||||
:project_category_id, :project_language_id, :license_id, :ignore_id, :private)
|
||||
:project_category_id, :project_language_id, :license_id, :ignore_id, :private,
|
||||
:blockchain, :blockchain_token_all, :blockchain_init_token, :pr_view_admin)
|
||||
end
|
||||
|
||||
def mirror_params
|
||||
params.permit(:user_id, :name, :description, :repository_name, :is_mirror, :auth_username,
|
||||
params.permit(:user_id, :name, :description, :repository_name, :is_mirror, :auth_username, :auth_token,
|
||||
:auth_password, :project_category_id, :project_language_id, :clone_addr, :private)
|
||||
end
|
||||
|
||||
def page_site_params
|
||||
params.permit(:site_name, :identifier,:language_frame,:theme)
|
||||
end
|
||||
|
||||
def project_public?
|
||||
return if @project.is_public?
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ class PullRequestsController < ApplicationController
|
|||
before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge,:get_branches,:create_merge_infos, :files, :commits]
|
||||
before_action :load_pull_request, only: [:files, :commits]
|
||||
before_action :find_atme_receivers, only: [:create, :update]
|
||||
|
||||
include TagChosenHelper
|
||||
include ApplicationHelper
|
||||
|
||||
|
@ -66,6 +67,7 @@ class PullRequestsController < ApplicationController
|
|||
Issues::CreateForm.new({subject: params[:title], description: params[:body].blank? ? params[:body] : params[:body].b}).validate!
|
||||
@pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params)
|
||||
if @gitea_pull_request[:status] == :success
|
||||
PullRequests::SendJournalService.call(@project, @pull_request, current_user)
|
||||
@pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"], @gitea_pull_request[:body]["id"])
|
||||
reviewers = User.where(id: params[:reviewer_ids])
|
||||
@pull_request.reviewers = reviewers
|
||||
|
@ -73,6 +75,11 @@ class PullRequestsController < ApplicationController
|
|||
SendTemplateMessageJob.perform_later('ProjectPullRequest', current_user.id, @pull_request&.id) if Site.has_notice_menu?
|
||||
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||
AtmeService.call(current_user, @atme_receivers, @pull_request) if @atme_receivers.size > 0
|
||||
|
||||
# author: zxh
|
||||
# 调用上链API
|
||||
push_activity_2_blockchain("pull_request_create", @pull_request) if Site.has_blockchain? && @project.use_blockchain
|
||||
|
||||
else
|
||||
render_error("create pull request error: #{@gitea_pull_request[:status]}")
|
||||
raise ActiveRecord::Rollback
|
||||
|
@ -119,7 +126,19 @@ class PullRequestsController < ApplicationController
|
|||
end
|
||||
else
|
||||
return normal_status(-1, "请输入正确的标记。")
|
||||
end
|
||||
end
|
||||
end
|
||||
if params[:attached_issue_ids].present?
|
||||
if params[:attached_issue_ids].is_a?(Array) && params[:attached_issue_ids].size > 1
|
||||
return normal_status(-1, "最多只能关联一个疑修。")
|
||||
elsif params[:attached_issue_ids].is_a?(Array) && params[:attached_issue_ids].size == 1
|
||||
@pull_request&.pull_attached_issues&.destroy_all
|
||||
params[:attached_issue_ids].each do |issue|
|
||||
PullAttachedIssue.create!(issue_id: issue, pull_request_id: @pull_request.id)
|
||||
end
|
||||
else
|
||||
return normal_status(-1, "请输入正确的疑修。")
|
||||
end
|
||||
end
|
||||
if params[:status_id].to_i == 5
|
||||
@issue.issue_times.update_all(end_time: Time.now)
|
||||
|
@ -149,12 +168,16 @@ class PullRequestsController < ApplicationController
|
|||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user)
|
||||
if colsed === true
|
||||
# author: zxh
|
||||
# 调用上链API
|
||||
push_activity_2_blockchain("pull_request_refuse", @pull_request) if Site.has_blockchain? && @project.use_blockchain
|
||||
|
||||
if colsed === true
|
||||
@pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::CLOSE)
|
||||
# 合并请求下issue处理为关闭
|
||||
@issue&.update_attributes!({status_id:5})
|
||||
SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id) if Site.has_notice_menu?
|
||||
normal_status(1, "已拒绝")
|
||||
normal_status(1, "已拒绝")
|
||||
else
|
||||
normal_status(-1, '合并失败')
|
||||
end
|
||||
|
@ -170,10 +193,11 @@ class PullRequestsController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
tip_exception(403, "你没有权限访问") if @project.pr_view_admin? && !@project.manager?(current_user)
|
||||
@issue_user = @issue.user
|
||||
@issue_assign_to = @issue.get_assign_user
|
||||
@gitea_pull = Gitea::PullRequest::GetService.call(@owner.login,
|
||||
@repository.identifier, @pull_request.gitea_number, current_user&.gitea_token)
|
||||
@repository.identifier, @pull_request.gitea_number, @owner&.gitea_token)
|
||||
@last_review = @pull_request.reviews.take
|
||||
end
|
||||
|
||||
|
@ -198,6 +222,28 @@ class PullRequestsController < ApplicationController
|
|||
# @pull_request.project_trend_status!
|
||||
@pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::MERGE)
|
||||
@issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id)
|
||||
|
||||
# author: zxh
|
||||
# 调用上链API
|
||||
push_activity_2_blockchain("pull_request_merge", @pull_request) if Site.has_blockchain? && @project.use_blockchain
|
||||
|
||||
# 查看是否fix了相关issue,如果fix就转账
|
||||
@pull_request.attached_issues.each do |issue|
|
||||
next if PullAttachedIssue.exists?(issue_id: issue.id, fixed: true)
|
||||
token_num = issue.blockchain_token_num
|
||||
token_num = token_num.nil? ? 0 : token_num
|
||||
author_id = @pull_request.user_id
|
||||
if token_num > 0
|
||||
Blockchain::FixIssue.call({user_id: author_id.to_s, project_id: @project.id.to_s, token_num: token_num}) if Site.has_blockchain? && @project.use_blockchain
|
||||
PullAttachedIssue.find_by(issue_id: issue.id, pull_request_id: @pull_request.id).update(fixed: true)
|
||||
end
|
||||
# update issue to state 5
|
||||
issue.issue_participants.create!({participant_type: "edited", participant_id: current_user.id}) unless issue.issue_participants.exists?(participant_type: "edited", participant_id: current_user.id)
|
||||
journal = issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", prop_key: "status_id", old_value: issue.status_id, value: 5})
|
||||
issue.update(status_id: 5)
|
||||
end
|
||||
|
||||
# 合并请求下issue处理为关闭
|
||||
@issue&.update_attributes!({status_id:5})
|
||||
SendTemplateMessageJob.perform_later('PullRequestMerged', current_user.id, @pull_request.id) if Site.has_notice_menu?
|
||||
|
@ -237,12 +283,12 @@ class PullRequestsController < ApplicationController
|
|||
|
||||
|
||||
def files
|
||||
@files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token)
|
||||
@files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, @owner&.gitea_token)
|
||||
# render json: @files_result
|
||||
end
|
||||
|
||||
def commits
|
||||
@commits_result = Gitea::PullRequest::CommitsService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token)
|
||||
@commits_result = Gitea::PullRequest::CommitsService.call(@owner.login, @project.identifier, @pull_request.gitea_number, @owner&.gitea_token)
|
||||
# render json: @commits_result
|
||||
end
|
||||
|
||||
|
@ -274,15 +320,10 @@ class PullRequestsController < ApplicationController
|
|||
body: params[:body], #内容
|
||||
head: params[:head], #源分支
|
||||
base: params[:base], #目标分支
|
||||
milestone: 0, #里程碑,未与本地的里程碑关联
|
||||
# milestone: 0, #里程碑,未与本地的里程碑关联
|
||||
}
|
||||
assignee_login = User.find_by_id(params[:assigned_to_id])&.login
|
||||
@requests_params = @local_params.merge({
|
||||
# assignees: ["#{params[:assigned_login].to_s}"],
|
||||
assignees: ["#{assignee_login.to_s}"],
|
||||
labels: params[:issue_tag_ids]
|
||||
# due_date: Time.now
|
||||
})
|
||||
@requests_params = @local_params.merge({assignees: [assignee_login.to_s].reject!(&:empty?)})
|
||||
@issue_params = {
|
||||
author_id: current_user.id,
|
||||
project_id: @project.id,
|
||||
|
|
|
@ -22,6 +22,12 @@ class RepositoriesController < ApplicationController
|
|||
def detail
|
||||
@user = current_user
|
||||
@result = Repositories::DetailService.call(@owner, @repository, @user)
|
||||
cache_total_forks = $redis_cache.get("ProjectSpecialForks:#{@project.id}")
|
||||
if cache_total_forks.present?
|
||||
@project_forked_count = cache_total_forks.to_i
|
||||
else
|
||||
@project_forked_count = @project.forked_count.to_i
|
||||
end
|
||||
@project_fork_id = @project.try(:forked_from_project_id)
|
||||
if @project_fork_id.present?
|
||||
@fork_project = Project.find_by(id: @project_fork_id)
|
||||
|
@ -110,7 +116,8 @@ class RepositoriesController < ApplicationController
|
|||
result = interactor.result
|
||||
@sub_entries = result.is_a?(Array) ? result.sort_by{ |hash| hash['type'] } : result
|
||||
else
|
||||
render_error(interactor.error)
|
||||
status = interactor.error == "你访问的文件不存在"? -2 : -1
|
||||
render_error(interactor.error,status)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -122,10 +129,10 @@ class RepositoriesController < ApplicationController
|
|||
if params[:filepath].present?
|
||||
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
||||
@hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri,
|
||||
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
||||
sha: params[:sha], page: params[:page], limit: params[:limit], token: @owner&.gitea_token).call
|
||||
else
|
||||
@hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier,
|
||||
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
||||
sha: params[:sha], page: params[:page], limit: params[:limit], token: @owner&.gitea_token).call
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -140,8 +147,8 @@ class RepositoriesController < ApplicationController
|
|||
if @project.educoder?
|
||||
return render_error('暂未开放,敬请期待.')
|
||||
else
|
||||
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token)
|
||||
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true})
|
||||
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, @owner&.gitea_token)
|
||||
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, @owner&.gitea_token, {diff: true})
|
||||
render_error(@commit[:message], @commit[:status]) if @commit.has_key?(:status) || @commit_diff.has_key?(:status)
|
||||
end
|
||||
end
|
||||
|
@ -156,7 +163,7 @@ class RepositoriesController < ApplicationController
|
|||
|
||||
@tag_names = result.is_a?(Hash) && result.key?(:status) ? [] : name_result
|
||||
|
||||
result = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]})
|
||||
result = Gitea::Repository::Tags::ListService.call(@owner&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]})
|
||||
|
||||
@tags = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
||||
end
|
||||
|
@ -166,8 +173,12 @@ class RepositoriesController < ApplicationController
|
|||
if params[:filepath].present? || @project.educoder?
|
||||
@contributors = []
|
||||
else
|
||||
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier)
|
||||
@contributors = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
||||
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]})
|
||||
@total_count = result[:total_count]
|
||||
@contributors = result.is_a?(Hash) ? result[:body] : []
|
||||
|
||||
add_contributors_count = EduSetting.get("ProjectAddContributors-#{@project.id}")
|
||||
@total_count = @total_count + add_contributors_count.to_i
|
||||
end
|
||||
rescue
|
||||
@contributors = []
|
||||
|
@ -210,6 +221,21 @@ class RepositoriesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def replace_file
|
||||
#删除
|
||||
delete_interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, params[:delete_file].merge(identifier: @project.identifier))
|
||||
return render_error(delete_interactor.error) unless delete_interactor.success?
|
||||
#新建
|
||||
interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params)
|
||||
if interactor.success?
|
||||
@file = interactor.result
|
||||
render_result(0, "替换成功")
|
||||
else
|
||||
render_error(interactor.error)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def delete_file
|
||||
interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier))
|
||||
if interactor.success?
|
||||
|
@ -234,14 +260,15 @@ class RepositoriesController < ApplicationController
|
|||
|
||||
def readme
|
||||
if params[:filepath].present?
|
||||
result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], current_user&.gitea_token)
|
||||
result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], @owner&.gitea_token)
|
||||
else
|
||||
result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token)
|
||||
result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], @owner&.gitea_token)
|
||||
end
|
||||
@path = GiteaService.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/"
|
||||
@readme = result[:status] === :success ? result[:body] : nil
|
||||
@readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
||||
# replace_content 前置,防止被content改写
|
||||
@readme['replace_content'] = readme_decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
||||
@readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
||||
render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha", "replace_content")
|
||||
rescue
|
||||
render json: nil
|
||||
|
@ -261,7 +288,7 @@ class RepositoriesController < ApplicationController
|
|||
archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{Addressable::URI.escape(params[:archive])}"
|
||||
|
||||
file_path = [domain, api_url, archive_url].join
|
||||
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") if @repository.hidden?
|
||||
file_path = [file_path, "access_token=#{@owner&.gitea_token}"].join("?")
|
||||
|
||||
return render_not_found if !request.format.zip? && !request.format.gzip?
|
||||
|
||||
|
@ -272,9 +299,9 @@ class RepositoriesController < ApplicationController
|
|||
domain = GiteaService.gitea_config[:domain]
|
||||
api_url = GiteaService.gitea_config[:base_url]
|
||||
|
||||
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{Addressable::URI.escape(params[:filepath])}?ref=#{Addressable::URI.escape(params[:ref])}"
|
||||
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{CGI.escape(params[:filepath])}?ref=#{CGI.escape(params[:ref])}"
|
||||
file_path = [domain, api_url, url].join
|
||||
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&")
|
||||
file_path = [file_path, "access_token=#{@owner&.gitea_token}"].join("&")
|
||||
|
||||
redirect_to file_path
|
||||
end
|
||||
|
@ -302,16 +329,16 @@ class RepositoriesController < ApplicationController
|
|||
if params[:filepath].present?
|
||||
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
||||
Gitea::Repository::Commits::FileListService.new(@project.owner.login, @project.identifier, file_path_uri,
|
||||
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
||||
sha: get_ref, page: 1, limit: 1, token: @project&.owner&.gitea_token).call
|
||||
else
|
||||
Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
|
||||
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
||||
sha: get_ref, page: 1, limit: 1, token: @project&.owner&.gitea_token).call
|
||||
end
|
||||
end
|
||||
|
||||
def get_statistics
|
||||
@branches_count = @project.educoder? ? 0 : Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size
|
||||
@tags_count = @project.educoder? ? 0 : Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
|
||||
@tags_count = @project.educoder? ? 0 : Gitea::Repository::Tags::ListService.new(@project&.owner&.gitea_token, @project.owner.login, @project.identifier).call&.size
|
||||
end
|
||||
|
||||
def get_ref
|
||||
|
@ -321,7 +348,12 @@ class RepositoriesController < ApplicationController
|
|||
def get_latest_commit
|
||||
latest_commit = @project.educoder? ? nil : project_commits
|
||||
@latest_commit = latest_commit.present? ? latest_commit[:body][0] : nil
|
||||
@commits_count = latest_commit.present? ? latest_commit[:total_count] : 0
|
||||
cache_total_commits = $redis_cache.get("ProjectSpecialCommit:#{@project.id}")
|
||||
if cache_total_commits.present?
|
||||
@commits_count = cache_total_commits.to_i
|
||||
else
|
||||
@commits_count = latest_commit.present? ? latest_commit[:total_count] : 0
|
||||
end
|
||||
end
|
||||
|
||||
def content_params
|
||||
|
|
|
@ -2,6 +2,7 @@ class SettingsController < ApplicationController
|
|||
def show
|
||||
@old_projects_url = nil
|
||||
get_navbar
|
||||
site_page_deploy_domain
|
||||
get_add_menu
|
||||
get_common_menu
|
||||
get_sub_competitions
|
||||
|
@ -11,15 +12,33 @@ class SettingsController < ApplicationController
|
|||
get_top_system_notification
|
||||
end
|
||||
|
||||
def check_url
|
||||
url = params[:url]
|
||||
task_id = params[:task]
|
||||
term = params[:term]
|
||||
return normal_status(-1, "缺少url参数") unless url.present?
|
||||
return normal_status(-1, "缺少term参数") unless term.present?
|
||||
return normal_status(-1, "缺少task参数") unless task_id.present?
|
||||
glcc_mate = GlccMediumTermExamineMaterial.new(code_or_pr_url: url, task_id: task_id, term: term, created_on:Time.now)
|
||||
state = glcc_mate.check_pr_url
|
||||
errors = glcc_mate.gennerate_content(state)
|
||||
render_ok({ state:state, state_html: errors})
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def get_navbar
|
||||
@navbar = default_laboratory.navbar
|
||||
if User.current.logged?
|
||||
pernal_index = {"name"=>"个人主页", "link"=>get_site_url("url", "#{Rails.application.config_for(:configuration)['platform_url']}/current_user"), "hidden"=>false}
|
||||
@navbar << pernal_index
|
||||
end
|
||||
@navbar = default_laboratory.navbar.sort_by{|e| e["index"].to_i }
|
||||
# if User.current.logged?
|
||||
# pernal_index = {"name"=>"个人主页", "link"=>get_site_url("url", "#{Rails.application.config_for(:configuration)['platform_url']}/current_user"), "hidden"=>false}
|
||||
# @navbar << pernal_index
|
||||
# end
|
||||
end
|
||||
|
||||
def site_page_deploy_domain
|
||||
@deploy_domain = EduSetting.find_by_name("site_page_deploy_domain").try(:value)
|
||||
end
|
||||
|
||||
def get_add_menu
|
||||
@add = []
|
||||
Site.add.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site|
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
class SitePagesController < ApplicationController
|
||||
before_action :require_login, except: [:softbot_build, :themes]
|
||||
before_action :require_profile_completed, only: [:create]
|
||||
before_action :load_project, except: [:softbot_build, :index, :themes]
|
||||
before_action :authenticate_user!, except: [:softbot_build, :index, :themes, :show]
|
||||
before_action :authenticate_member!, only: [:show]
|
||||
|
||||
def index
|
||||
pages = PageQuery.call(params,current_user)
|
||||
@total_count = pages.size
|
||||
@pages = paginate(pages)
|
||||
end
|
||||
|
||||
def show
|
||||
@page = Page.find_by(project_id: @project.id)
|
||||
return render_ok({data:nil}) unless @page.present?
|
||||
end
|
||||
|
||||
def create
|
||||
return normal_status(-1, "你还未开通Page服务,无法进行部署") unless current_user.website_permission
|
||||
return normal_status(-1, "你已使用了 #{params[:identifier]} 作为page标识") if Page.exists?(identifier: params[:identifier], user: current_user)
|
||||
return normal_status(-1, "该仓库已开通Page服务") if Page.exists?(project: @project)
|
||||
@page = Page.new(create_params)
|
||||
@page.user = current_user
|
||||
@page.project = @project
|
||||
@page.save
|
||||
end
|
||||
|
||||
def build
|
||||
return normal_status(-1, "你还未开通Page服务,无法进行部署") unless current_user.website_permission
|
||||
return normal_status(-1, "该仓库还未开通Page服务,无法进行部署") unless Page.exists?(project: @project)
|
||||
@page = Page.find params[:id]
|
||||
return normal_status(-1, @page.state_description) unless @page.state
|
||||
response_str = @page.deploy_page(params[:branch])
|
||||
data = JSON.parse(response_str)["result"] || data = JSON.parse(response_str)["error"]
|
||||
if data.to_s.include?("部署成功")
|
||||
@page.update(last_build_at: Time.now, build_state: true, last_build_info: data)
|
||||
else
|
||||
@page.update(build_state:false, last_build_info: data)
|
||||
end
|
||||
render_ok({data: data.nil? ? nil : data.split("\n") })
|
||||
end
|
||||
|
||||
def softbot_build
|
||||
branch = params[:ref].split("/").last
|
||||
user = User.find_by_login params[:repository][:owner][:login]
|
||||
return normal_status(-1, "你还未开通Page服务,无法进行部署") unless user.website_permission
|
||||
|
||||
project = Project.where(identifier: params[:repository][:name],user_id: user.id)
|
||||
return normal_status(-1, "你没有权限操作") if project.owner?(user)
|
||||
return normal_status(-1, "该仓库还未开通Page服务,无法进行部署") if Page.exists?(user: user, project: project)
|
||||
|
||||
@page = Page.find_by(user: user, project: project)
|
||||
response_str = @page.deploy_page(branch)
|
||||
data = JSON.parse(response_str)["result"]
|
||||
if data.nil?
|
||||
data = JSON.parse(response_str)["error"]
|
||||
end
|
||||
|
||||
if data.include?("部署成功")
|
||||
@page.update(last_build_at: Time.now, build_state: true, last_build_info: data)
|
||||
else
|
||||
@page.update(build_state:false, last_build_info: data)
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
|
||||
def themes
|
||||
# data = YAML.load_file(Rails.root.join('config/admins', 'page_themes.yml'))
|
||||
# render_ok({themes:data[theme_params.downcase]})
|
||||
@themes = PageTheme.where(language_frame:theme_params).order(order_index: :asc)
|
||||
end
|
||||
|
||||
private
|
||||
def authenticate_user!
|
||||
unless @project.manager?(current_user) || current_user.admin?
|
||||
return render_forbidden('你不是管理员,没有权限操作')
|
||||
end
|
||||
end
|
||||
|
||||
def authenticate_member!
|
||||
unless @project.member?(current_user) || current_user.admin?
|
||||
return render_forbidden('你不是成员,没有权限操作')
|
||||
end
|
||||
end
|
||||
|
||||
def theme_params
|
||||
params[:language_frame] || "hugo"
|
||||
end
|
||||
|
||||
def create_params
|
||||
params.permit(:identifier, :language_frame, :theme, :site_name)
|
||||
end
|
||||
end
|
|
@ -12,7 +12,7 @@ class Traces::ProjectsController < Traces::BaseController
|
|||
return render_error("无可用检测次数") if @project.user_trace_tasks.size >= 5
|
||||
return render_error("分支名不能为空!") if branch_name.blank?
|
||||
@all_branches = Gitea::Repository::Branches::ListNameService.call(@project&.owner, @project.identifier)
|
||||
return render_error("请输入正确的分支名!") unless @all_branches["branch_name"].include?(branch_name)
|
||||
return render_error("请输入正确的分支名!") unless @all_branches.include?(branch_name)
|
||||
code, data, error = Trace::CheckService.call(current_user.trace_token, @project, "1", branch_name)
|
||||
if code == 200
|
||||
UserTraceTask.create!(
|
||||
|
@ -51,7 +51,7 @@ class Traces::ProjectsController < Traces::BaseController
|
|||
branch_name = params[:branch_name]
|
||||
return render_error("分支名不能为空!") if branch_name.blank?
|
||||
@all_branches = Gitea::Repository::Branches::ListNameService.call(@project&.owner, @project.identifier)
|
||||
return render_error("请输入正确的分支名!") unless @all_branches["branch_name"].include?(branch_name)
|
||||
return render_error("请输入正确的分支名!") unless @all_branches.include?(branch_name)
|
||||
code, data, error = Trace::ReloadCheckService.call(current_user.trace_token, params[:project_id])
|
||||
if code == 200
|
||||
UserTraceTask.create!(
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
class UserRankController < ApplicationController
|
||||
# 根据时间获取热门开发者
|
||||
def index
|
||||
def index
|
||||
limit = 3
|
||||
limit = params[:limit].to_i - 1 if params[:limit].present?
|
||||
limit = 99 if limit > 99
|
||||
$redis_cache.zunionstore("recent-days-user-rank", get_timeable_key_names)
|
||||
@user_rank = $redis_cache.zrevrange("recent-days-user-rank", 0, 3, withscores: true)
|
||||
@user_rank = $redis_cache.zrevrange("recent-days-user-rank", 0, limit, withscores: true)
|
||||
rescue Exception => e
|
||||
@user_rank = []
|
||||
end
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
class Users::ClasController < Users::BaseController
|
||||
before_action :require_login
|
||||
before_action :private_user_resources!
|
||||
def index
|
||||
@user_clas = UserCla.where(user: current_user)
|
||||
end
|
||||
|
||||
def show
|
||||
@user_cla = current_user.user_clas.find params[:id]
|
||||
end
|
||||
|
||||
def create
|
||||
@user_cla = current_user.user_clas.find_by(cla_id: params[:cla_id])
|
||||
if @user_cla.nil?
|
||||
ActiveRecord::Base.transaction do
|
||||
Users::UserClaForm.new(user_cla_params).validate!
|
||||
@user_cla = UserCla.build(user_cla_params, current_user.id)
|
||||
|
||||
end
|
||||
elsif @user_cla.state == "failed"
|
||||
@user_cla.update_by_params(user_cla_params)
|
||||
elsif @user_cla.state == "signed"
|
||||
return render_error('协议生效中,请勿重复签署')
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@user_cla = current_user.user_clas.find params[:id]
|
||||
@user_cla.update_attributes(state: 2)
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_cla_params
|
||||
params.permit(:email, :real_name, :cla_id)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,7 +1,17 @@
|
|||
class Users::HeadmapsController < Users::BaseController
|
||||
def index
|
||||
result = Gitea::User::HeadmapService.call(observed_user.login, start_stamp, end_stamp)
|
||||
result = Gitea::User::HeadmapService.call(observed_user.login, start_stamp, end_stamp, observed_user&.gitea_token)
|
||||
@headmaps = result[2].blank? ? [] : result[2]
|
||||
headmaps_result = {}
|
||||
@headmaps.each do |entry|
|
||||
date = Time.at(entry["timestamp"]).strftime("%Y-%m-%d")
|
||||
if headmaps_result[date].nil?
|
||||
headmaps_result[date] = { "contributions" => entry["contributions"] }
|
||||
else
|
||||
headmaps_result[date]["contributions"] += entry["contributions"]
|
||||
end
|
||||
end
|
||||
@headmaps = headmaps_result
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
|
@ -10,17 +20,17 @@ class Users::HeadmapsController < Users::BaseController
|
|||
private
|
||||
def start_stamp
|
||||
if params[:year].present?
|
||||
Date.new(params[:year], 1).to_time.to_i
|
||||
Date.new(params[:year].to_i, 1).to_time.to_i
|
||||
else
|
||||
Date.today.to_time.to_i - 365*24*60*60
|
||||
(Date.today - 1.years).to_time.to_i
|
||||
end
|
||||
end
|
||||
|
||||
def end_stamp
|
||||
if params[:year].present?
|
||||
Date.new(params[:year], 1).to_time.to_i + 365*24*60*60
|
||||
(Date.new(params[:year].to_i, 1) + 1.years).to_time.end_of_day.to_i
|
||||
else
|
||||
Date.today.to_time.to_i
|
||||
Date.today.to_time.end_of_day.to_i
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,7 @@
|
|||
class Users::MessagesController < Users::BaseController
|
||||
before_action :private_user_resources!
|
||||
before_action :find_receivers, only: [:create]
|
||||
before_action :check_auth
|
||||
|
||||
def index
|
||||
limit = params[:limit] || params[:per_page]
|
||||
|
@ -63,6 +64,10 @@ class Users::MessagesController < Users::BaseController
|
|||
end
|
||||
|
||||
private
|
||||
def check_auth
|
||||
return render_forbidden unless current_user.admin? || observed_logged_user?
|
||||
end
|
||||
|
||||
def message_type
|
||||
@message_type = begin
|
||||
case params[:type]
|
||||
|
|
|
@ -6,6 +6,7 @@ class Users::ProjectTrendsController < Users::BaseController
|
|||
else
|
||||
@project_trends = observed_user.project_trends
|
||||
end
|
||||
@project_trends = @project_trends.left_joins(:project).where("projects.is_public = TRUE")
|
||||
@project_trends = kaminari_paginate(@project_trends.includes(:trend, :project).order(created_at: :desc))
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ class Users::StatisticsController < Users::BaseController
|
|||
# 近期活动统计
|
||||
def activity
|
||||
date_range = (1.week.ago.to_date..Date.today).to_a
|
||||
commit_request = Gitea::User::HeadmapService.call(observed_user.login, 1.week.ago.to_date.to_time.to_i, Date.today.to_time.to_i)
|
||||
commit_request = Gitea::User::HeadmapService.call(observed_user.login, 1.week.ago.to_date.to_time.to_i, Date.today.end_of_day.to_time.to_i, observed_user.gitea_token)
|
||||
commit_data = commit_request[2]
|
||||
@date_data = []
|
||||
@issue_data = []
|
||||
|
@ -14,8 +14,11 @@ class Users::StatisticsController < Users::BaseController
|
|||
@date_data << date.strftime("%Y.%m.%d")
|
||||
@issue_data << observed_user.issues.issue_issue.where("DATE(created_on) = ?", date).size
|
||||
@pull_request_data << observed_user.pull_requests.where("DATE(created_at) = ?", date).size
|
||||
date_commit_data = commit_data.blank? ? nil : commit_data.select{|item| item["timestamp"] == date.to_time.to_i}
|
||||
@commit_data << (date_commit_data.blank? ? 0 : date_commit_data[0]["contributions"].to_i)
|
||||
contribution = 0
|
||||
commit_data.each do |item|
|
||||
contribution += item["contributions"] if Time.at(item["timestamp"]).strftime("%Y-%m-%d") == date.to_s
|
||||
end
|
||||
@commit_data << contribution
|
||||
end
|
||||
render :json => {dates: @date_data, issues_count: @issue_data, pull_requests_count: @pull_request_data, commits_count: @commit_data}
|
||||
end
|
||||
|
|
|
@ -2,8 +2,8 @@ class UsersController < ApplicationController
|
|||
include ApplicationHelper
|
||||
include Ci::DbConnectable
|
||||
|
||||
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 :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users, :hovercard, :hovercard4proj]
|
||||
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard, :hovercard4proj]
|
||||
before_action :require_login, only: %i[me sync_user_info]
|
||||
before_action :connect_to_ci_db, only: [:get_user_info]
|
||||
before_action :convert_image!, only: [:update, :update_image]
|
||||
|
@ -81,12 +81,141 @@ class UsersController < ApplicationController
|
|||
@watchers = paginate(watchers)
|
||||
end
|
||||
|
||||
def contribution_perc
|
||||
project_id = params[:project_id]
|
||||
@project = Project.find(project_id)
|
||||
user_id = params[:id]
|
||||
@user = User.find(user_id)
|
||||
|
||||
def cal_perc(count_user, count_all)
|
||||
(count_user * 1.0 / (count_all + 0.000000001)).round(5)
|
||||
end
|
||||
|
||||
if @project['use_blockchain'] == true or @project['use_blockchain'] == 1
|
||||
balance_user = Blockchain::BalanceQueryOneProject.call({"user_id": user_id, "project_id": project_id})
|
||||
balance_all = Blockchain::RepoBasicInfo.call({"project_id": project_id})["cur_supply"]
|
||||
scores = {
|
||||
"final" => cal_perc(balance_user, balance_all),
|
||||
"blockchain" => true
|
||||
}
|
||||
else
|
||||
# 获取所有行为对应的项目内记录总数和个人记录数
|
||||
features = {
|
||||
"requirement" => {},
|
||||
"development" => {},
|
||||
"review" => {}
|
||||
}
|
||||
|
||||
# 1. issue创建
|
||||
issues = Issue.where(project_id: project_id, issue_classify: 'issue')
|
||||
issue_all = issues.count
|
||||
issue_user = issues.where(author_id: user_id).count
|
||||
features["requirement"] = features["requirement"].merge({"issue" => {"all" => issue_all, "perc" => cal_perc(issue_user, issue_all)}})
|
||||
# 2. 里程碑创建
|
||||
milestones = Version.where(project_id: project_id)
|
||||
milestone_all = milestones.count
|
||||
milestone_user = milestones.where(user_id: user_id).count
|
||||
features["requirement"] = features["requirement"].merge({"milestone" => {"all" => milestone_all, "perc" => cal_perc(milestone_user, milestone_all)}})
|
||||
# 3. issue评论
|
||||
issue_comments = Journal.joins("INNER JOIN issues on journals.journalized_id=issues.id").where("issues.project_id=#{project_id} and journalized_type='Issue' and issues.issue_classify='issue'")
|
||||
issue_comment_all = issue_comments.count
|
||||
issue_comment_user = issue_comments.where("journals.user_id=#{user_id}").count
|
||||
features["requirement"] = features["requirement"].merge({"issue_comment" => {"all" => issue_comment_all, "perc" => cal_perc(issue_comment_user, issue_comment_all)}})
|
||||
# 4. 合并请求
|
||||
prs = PullRequest.where(project_id: project_id)
|
||||
pr_all = prs.count
|
||||
pr_user = prs.where(user_id: user_id).count
|
||||
features["development"] = features["development"].merge({"pr" => {"all" => pr_all, "perc" => cal_perc(pr_user, pr_all)}})
|
||||
# 5. pr评论
|
||||
pr_comments = Journal.joins("INNER JOIN issues on journals.journalized_id=issues.id").where("issues.project_id=#{project_id} and journalized_type='Issue' and issues.issue_classify='pull_request'")
|
||||
pr_comment_all = pr_comments.count
|
||||
pr_comment_user = pr_comments.where("journals.user_id=#{user_id}").count
|
||||
features["review"] = features["review"].merge({"pr_comment" => {"all" => pr_comment_all, "perc" => cal_perc(pr_comment_user, pr_comment_all)}})
|
||||
# 6. 代码行评论
|
||||
line_comments = Journal.joins("INNER JOIN pull_requests on journals.journalized_id=pull_requests.id").where("pull_requests.project_id=#{project_id} and journalized_type='PullRequest'")
|
||||
line_comment_all = line_comments.count
|
||||
line_comment_user = line_comments.where("journals.user_id=#{user_id}").count
|
||||
features["review"] = features["review"].merge({"line_comment" => {"all" => line_comment_all, "perc" => cal_perc(line_comment_user, line_comment_all)}})
|
||||
# 7. 代码行、commit贡献统计
|
||||
code_contributions = Api::V1::Projects::CodeStats::ListService.call(@project, {ref: nil})
|
||||
commit_all = code_contributions["commit_count"]
|
||||
addition_all = code_contributions["additions"]
|
||||
deletion_all = code_contributions["deletions"]
|
||||
|
||||
commit_user = 0
|
||||
addition_user = 0
|
||||
deletion_user = 0
|
||||
code_contributions["authors"].each do |author|
|
||||
if author["name"] == @user.login
|
||||
commit_user = author["commits"]
|
||||
addition_user = author["additions"]
|
||||
deletion_user = author["deletions"]
|
||||
end
|
||||
end
|
||||
|
||||
features["development"] = features["development"].merge({"commit" => {"all" => commit_all, "perc" => cal_perc(commit_user, commit_all)}})
|
||||
features["development"] = features["development"].merge({"addition" => {"all" => addition_all, "perc" => cal_perc(addition_user, addition_all)}})
|
||||
features["development"] = features["development"].merge({"deletion" => {"all" => deletion_all, "perc" => cal_perc(deletion_user, deletion_all)}})
|
||||
|
||||
def cal_weight(features)
|
||||
weights = {} # 计算每一项的权重
|
||||
categories = []
|
||||
features.each do |key, _|
|
||||
categories << key
|
||||
weights[key] = Hash.new
|
||||
end
|
||||
count_all = 0
|
||||
counts = {}
|
||||
categories.each do |category|
|
||||
count_1 = 0
|
||||
features[category].each do |_, value|
|
||||
count_1 += value["all"]
|
||||
end
|
||||
count_all += count_1
|
||||
counts[category] = count_1
|
||||
features[category].each do |key, value|
|
||||
weight = cal_perc(value["all"], count_1)
|
||||
weights[category] = weights[category].merge({key => weight})
|
||||
end
|
||||
end
|
||||
categories.each do |category|
|
||||
weight = cal_perc(counts[category], count_all)
|
||||
weights[category] = weights[category].merge({"category_weight" => weight})
|
||||
end
|
||||
return weights
|
||||
end
|
||||
|
||||
weights_categories = cal_weight(features)
|
||||
scores = {
|
||||
"final" => 0.0,
|
||||
"blockchain" => false
|
||||
}
|
||||
features.each do |category, value_1|
|
||||
category_score = 0.0
|
||||
value_1.each do |action, value_2|
|
||||
category_score += weights_categories[category][action] * value_2["perc"]
|
||||
end
|
||||
scores["final"] += weights_categories[category]["category_weight"] * category_score.round(4)
|
||||
scores = scores.merge({category => category_score.round(4)})
|
||||
end
|
||||
end
|
||||
render json: { scores: scores }
|
||||
end
|
||||
|
||||
def hovercard
|
||||
end
|
||||
|
||||
# author: zxh, 查询贡献者的贡献度
|
||||
def hovercard4proj
|
||||
end
|
||||
|
||||
def update
|
||||
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)
|
||||
if user_params[:nickname].present?
|
||||
keywords = user_params[:nickname].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
return normal_status(-1, "昵称中包含关键词:#{keywords},请重新命名") if ReversedKeyword.check_exists?(keywords)
|
||||
end
|
||||
Util.write_file(@image, avatar_path(@user)) if user_params[:image].present?
|
||||
@user.attributes = user_params.except(:image)
|
||||
unless @user.save
|
||||
|
@ -94,11 +223,11 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def update_image
|
||||
return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id])
|
||||
def update_image
|
||||
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)
|
||||
|
||||
Util.write_file(@image, avatar_path(@user))
|
||||
Util.write_file(@image, avatar_path(@user))
|
||||
return render_ok({message: '头像修改成功'})
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
|
@ -281,7 +410,253 @@ class UsersController < ApplicationController
|
|||
is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
|
||||
scope = Projects::ListMyQuery.call(params, @user,is_current_admin_user)
|
||||
@total_count = scope.size
|
||||
@projects = paginate(scope)
|
||||
@projects = kaminari_unlimit_paginate(scope)
|
||||
end
|
||||
|
||||
|
||||
# query all projects with tokens by a user
|
||||
def blockchain_balance
|
||||
#is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i)
|
||||
is_current_admin_user = true
|
||||
results = Blockchain::BalanceQuery.call(params, is_current_admin_user)
|
||||
if results[:status] == 0
|
||||
@total_count = results[:total_count]
|
||||
@projects = results[:projects]
|
||||
else
|
||||
@total_count = -1
|
||||
@projects = []
|
||||
end
|
||||
|
||||
# render json: { status: results[:status], projects: @projects, total_count: @total_count }
|
||||
end
|
||||
|
||||
# query one balance
|
||||
def blockchain_balance_one_project
|
||||
#is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i)
|
||||
is_current_admin_user = true
|
||||
if is_current_admin_user
|
||||
owner = User.find_by(login: params['owner_login'])
|
||||
if owner.nil?
|
||||
normal_status(-1, "创建者无法找到")
|
||||
else
|
||||
p = Project.find_by(user_id: owner.id, identifier: params['project_identifier'])
|
||||
balance = Blockchain::BalanceQueryOneProject.call({"user_id": params['user_id'].to_i, "project_id": p.id.to_i})
|
||||
render json: { status: 0, balance: balance}
|
||||
end
|
||||
else
|
||||
normal_status(-1, "缺少权限")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
def blockchain_transfer
|
||||
#is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['payer_id'].to_i)
|
||||
is_current_admin_user = true
|
||||
|
||||
if is_current_admin_user
|
||||
Blockchain::TransferService.call(params)
|
||||
render json: {status: 2} # 重新查询余额
|
||||
else
|
||||
normal_status(-1, "缺少权限")
|
||||
end
|
||||
rescue Exception => e
|
||||
normal_status(-1, e.to_s)
|
||||
end
|
||||
|
||||
# exchange money
|
||||
def blockchain_exchange
|
||||
#is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i)
|
||||
#require 'alipay'
|
||||
## setup the client to communicate with either production API or sandbox API
|
||||
## https://openapi.alipay.com/gateway.do (Production)
|
||||
## https://openapi.alipaydev.com/gateway.do (Sandbox)
|
||||
#api_url = 'https://openapi.alipay.com/gateway.do'
|
||||
#
|
||||
## setup your own credentials and certificates
|
||||
#app_id = '2021002140631434'
|
||||
#app_private_key="-----BEGIN RSA PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCPDsgc0n0RWRnbe9OMqtUbde8gu88OyjuZm8cJXeiSING18HX56C5zV4DsHQ6K9/JmQi/NYCc7/2Prh66Bei0L4Xm5TysJTPYi90+WlbJJESFF6fqULi8sSqZXUtaoMKRcUyeR144l2GQgXbZWBbVSQeZW5DqUDlurTF0I7vQ21wGqxQqBjQK8PSVw5hF+aIsNOfAY9M1tzdD5Jzo2Y3FJdsbXIJNMyhJJCZ+7KHFqma7lpjkXdCoyh/nOISkQdGtFI29gI94sqewI2AMU84uxuBIE3h90iLT+8xrd2dQKdBS7qfhQ3PgkBPVNs5jxsVBqSFdSFT6zcqFdHJzulCUJAgMBAAECggEAWocAGz0X5+J6emnhdSKluLrol85BORrAnHP3f/XtNouOKZQBFCPZQSQecUvx5/7/ZbZ8iXpPWahDkshJpaWq29nTLXDryvboyze1JZWVPKeaZqOp7htLvrt+h8PkEoq1d7cnUyMU0N4eflzPBaCXHXaWTGYgq5Bqcfvg48ZSxGBYeHt5WWU2+GW5fpsaVBBYkdyxxGMoy/bzYzGhvfSJkexqnl0XkAAODa02mu3WsHrzRid6Mf+3syYbq/MfUodU6Vng2tbCqwnWrHCyrD4RYl6rg1TKuAv2YAfBhLzwBxHYVC4SRqzjs+8AaOQoF+lCjr4JklPhEuRThzD31YwIAQKBgQDAg4S7ciMmxvbNxR+1eimoAYLLF9jPpPU6w3VFNPb4rDu4tX77bNf082YplfJX5TYtZKjKPKyYG87K6slGunyPL4AFRW81WPB9u1uP26dihyPCBSUE01jKRPPfRrQnnru5fpm8LL3L03V3yA6J+GyQ8wltRJJi1eBSSm+IWRsZewKBgQC+PBD9J1LYOEIVeK9KvN8BpkA1ZIkk//VuJaoGfVXn+1EzM1yFB05fnsEQkHFynisvuCIr7pH63HcdyffQhe1YOnw9iDCG1zPjsi5uTe9WAM0dnb7xdsaLPr/Q2LyoDOTN9344Qovy1AAnpWtGTn6omgHst5nZpp/mHOuBlKiqSwKBgBKRXM77fjpyPEGyfpFxW+0xYB0YirfUUDa/vWLUbfGkIwp4ruuvHtEoXLUsGjiyCdys9b6zxW3SWMqnhIxG1la1HSLlBInfryphVL52UBmnsSI4fs6NV+YCaocheaTMoYyNkmRc6F1tYsoPyJ80D7yXRFR+paPUvxMQzNsYxQ1bAoGAHd2uSSBQWFPUxCwzUQd/93FTaU6EXYO103okTGqG/ymsoN4ya0wvWMHCy8fxl64PV6mP69fDoV/Vb57SwjEUhyJ/eOWVwMWuhtPliDnCFn1/tmOao6wjFZ9fW/l6/OMxVMjDTy/bat8vuwm0YtBWAEBVhwV4KPyI5AasTqa5KCsCgYB/usnqhVx2zt+MxpBt2Q9Vxc0zXcZxMDs69UUdTY86gjcJyCFGe3bbumUcyfSJzIznC2hfFX5ZyS0oMwiAzWtslRMh9LRh3kofD/6BogL3RKOlBk3iekvQ8Gn0tbwk2Qzr4WJgfA7A4GTf5r7Y+bvOfazzsUQAfSK6nUTIlOj2Ew==\n-----END RSA PRIVATE KEY-----\n"
|
||||
#alipay_public_key="-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgHXLD1BshMymbqqtZVKNyo95FNfxzXzaw3P1eI0KeO6RaL+JzrWxzIBFfTjkWv/8WM9u/NcXMOFt2QO9q5KIDx6PkqjRDTd1hgP/cTgdjOHQqnVSihCrQDVCDBSOXIujC8Lk/P4pFVRhQkYeZqEb1qb8b/2tzTY8g9PKKBSCQv7SfgL2TBcpAVbb+9xdJ6VainC/wYGk8T+c+st1hXnuBJSS0m7LFxJOsYkNk0wbA0tfdZLrO3us2F7sjC9t4h/05nr+gSuDkzo+1kCEefYLqScexN+vnQiLoylp/C82wNiP6okxfhmHz3EcYfUqUyGTN/oFaFcPFPpUtFNS8jFV9QIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||
#
|
||||
## initialize a client to communicate with the Alipay API
|
||||
#@alipay_client = Alipay::Client.new(
|
||||
# url: api_url,
|
||||
# app_id: app_id,
|
||||
# app_private_key: app_private_key,
|
||||
# alipay_public_key: alipay_public_key
|
||||
#)
|
||||
#
|
||||
#return_result = @alipay_client.page_execute_url(
|
||||
# method: 'alipay.trade.page.pay',
|
||||
# biz_content: JSON.generate({
|
||||
# out_trade_no: '20210420104600',
|
||||
# product_code: 'FAST_INSTANT_TRADE_PAY',
|
||||
# total_amount: '0.01',
|
||||
# subject: 'test'
|
||||
# }, ascii_only: true), # ascii_only is important!
|
||||
# timestamp: '2021-04-20 10:46:00'
|
||||
#)
|
||||
#render json: { pay_url: return_result }
|
||||
#
|
||||
|
||||
# 替代解决方案
|
||||
# 读取所有交易信息
|
||||
end
|
||||
# #
|
||||
# # def blockchain_create_trade
|
||||
# # #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i)
|
||||
# # is_current_admin_user = true
|
||||
# # if is_current_admin_user
|
||||
# # user_id = params['user_id'].to_i
|
||||
# # project_id = params['project_id'].to_i
|
||||
# # money = params['money'].to_f
|
||||
# # #description = params['description']
|
||||
# # token_num = params['token_num'].to_i
|
||||
# # # 锁仓
|
||||
# # result = Blockchain::CreateTrade.call({user_id: user_id, project_id: project_id, token_num: token_num})
|
||||
# # if result == false
|
||||
# # normal_status(-1, "创建交易失败")
|
||||
# # else
|
||||
# # bt = BlockchainTrade.new(user_id: user_id, project_id: project_id, token_num: token_num, money: money, state: 0) # state=0表示创建交易; state=1表示执行中; state=2表示执行完成
|
||||
# # bt.save()
|
||||
# # status = 2 # 交易创建成功
|
||||
# # render json: { status: status }
|
||||
# # end
|
||||
# # else
|
||||
# # normal_status(-1, "缺少权限")
|
||||
# # end
|
||||
# # end
|
||||
# #
|
||||
# #
|
||||
# # def blockchain_get_trades
|
||||
# # trades = BlockchainTrade.where(state: 0).all()
|
||||
# # results = []
|
||||
# # trades.each do |t|
|
||||
# # project_id = t.project_id
|
||||
# # project = Project.find_by(id: project_id)
|
||||
# # if !project.nil?
|
||||
# # owner = User.find_by(id: project.user_id)
|
||||
# # else
|
||||
# # owner = nil
|
||||
# # end
|
||||
# # user_id = t.user_id
|
||||
# # creator = User.find_by(id: user_id)
|
||||
# # if project.nil? || owner.nil? || creator.nil?
|
||||
# # else
|
||||
# # results << [creator, owner, project, t]
|
||||
# # end
|
||||
# # end
|
||||
# # render json: { results: results }
|
||||
# # end
|
||||
# #
|
||||
# # def blockchain_trade
|
||||
# # #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i)
|
||||
# # is_current_admin_user = true
|
||||
# # if is_current_admin_user
|
||||
# # user_id2 = params['user_id2'].to_i
|
||||
# # trade_id = params['trade_id'].to_i
|
||||
# # BlockchainTrade.find(trade_id).update(user_id2: user_id2, state: 1) # state=1表示锁定了,等待线下卖家发货
|
||||
# # render json: {status: 2} # window.location.reload()
|
||||
# # else
|
||||
# # normal_status(-1, "缺少权限")
|
||||
# # end
|
||||
# # end
|
||||
#
|
||||
#
|
||||
# def blockchain_verify_trade
|
||||
# #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i)
|
||||
# is_current_admin_user = true
|
||||
# if is_current_admin_user
|
||||
# trade_id = params['trade_id'].to_i
|
||||
# BlockchainTrade.find(trade_id).update(state: 2) # state=2表示确认收货
|
||||
# render json: {status: 2} # window.location.reload()
|
||||
# else
|
||||
# normal_status(-1, "缺少权限")
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def blockchain_get_verify_trades
|
||||
# #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i)
|
||||
# is_current_admin_user = true
|
||||
# if is_current_admin_user
|
||||
# trades = BlockchainTrade.where(state: 1).all()
|
||||
# results = []
|
||||
# trades.each do |t|
|
||||
# project_id = t.project_id
|
||||
# project = Project.find_by(id: project_id)
|
||||
# if !project.nil?
|
||||
# owner = User.find_by(id: project.user_id)
|
||||
# else
|
||||
# owner = nil
|
||||
# end
|
||||
# user_id = t.user_id
|
||||
# creator = User.find_by(id: user_id)
|
||||
# user_id2 = t.user_id2
|
||||
# buyer = User.find_by(id: user_id2)
|
||||
# if project.nil? || owner.nil? || creator.nil? || buyer.nil?
|
||||
# else
|
||||
# results << [creator, owner, project, t, buyer]
|
||||
# end
|
||||
# end
|
||||
# render json: { results: results }
|
||||
# else
|
||||
# normal_status(-1, "缺少权限")
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def blockchain_get_history_trades
|
||||
# #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i)
|
||||
# is_current_admin_user = true
|
||||
# if is_current_admin_user
|
||||
# trades = BlockchainTrade.where(state: 2).all()
|
||||
# results = []
|
||||
# trades.each do |t|
|
||||
# project_id = t.project_id
|
||||
# project = Project.find_by(id: project_id)
|
||||
# if !project.nil?
|
||||
# owner = User.find_by(id: project.user_id)
|
||||
# else
|
||||
# owner = nil
|
||||
# end
|
||||
# user_id = t.user_id
|
||||
# creator = User.find_by(id: user_id)
|
||||
# user_id2 = t.user_id2
|
||||
# buyer = User.find_by(id: user_id2)
|
||||
# if project.nil? || owner.nil? || creator.nil? || buyer.nil?
|
||||
# else
|
||||
# results << [creator, owner, project, t, buyer]
|
||||
# end
|
||||
# end
|
||||
# render json: { results: results }
|
||||
# else
|
||||
# normal_status(-1, "缺少权限")
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
def blockchain_get_issue_token_num
|
||||
issue_id = params["issue_id"]['orderId'].to_i
|
||||
issue = Issue.find_by(id: issue_id)
|
||||
project = Project.find(issue.project_id)
|
||||
if project[:use_blockchain]
|
||||
render json: {"blockchain_token_num": issue.blockchain_token_num}
|
||||
else
|
||||
render json: {"blockchain_token_num": -1} # 未使用blockchain
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def blockchain_get_unclosed_issue_list
|
||||
ownername = params["ownername"]
|
||||
identifier = params["reponame"]
|
||||
owner = User.find_by(login: ownername)
|
||||
project = Project.find_by(user_id: owner.id, identifier: identifier)
|
||||
unclosed_issues = Issue.where(project_id: project.id, issue_classify: "issue").where.not(status_id: 5)
|
||||
results = []
|
||||
unclosed_issues.each do |i|
|
||||
results << [i.id, i.subject]
|
||||
end
|
||||
render json: {unclosed_issues: results}
|
||||
end
|
||||
|
||||
# TODO 其他平台登录时同步修改gitea平台对应用户的密码
|
||||
|
@ -322,7 +697,7 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def email_search
|
||||
def email_search
|
||||
return render_error('请输入email') if params[:email].blank?
|
||||
@user = User.find_by(mail: params[:email])
|
||||
end
|
||||
|
@ -388,10 +763,11 @@ class UsersController < ApplicationController
|
|||
password = "12345678"
|
||||
|
||||
# 没有用户时,新建用户并登录
|
||||
user = User.where("login = ? or phone = ? or mail = ? ", "#{login}", phone, email).first
|
||||
user = phone.present? ? User.find_by(phone: phone) : nil
|
||||
user = User.where("login = ? or phone = ? or mail = ? ", "#{login}", phone, email).first if user.nil?
|
||||
if user.present?
|
||||
# 手机号先记录,后续用
|
||||
user.update_column(:phone, "#{phone}") if phone.present?
|
||||
user.update_column(:phone, "#{phone}") if phone.present? && user.phone.blank?
|
||||
else
|
||||
ActiveRecord::Base.transaction do
|
||||
email = "#{login}@gitlink.org.cn" if email.blank?
|
||||
|
|
|
@ -163,7 +163,7 @@ class VersionReleasesController < ApplicationController
|
|||
end
|
||||
|
||||
def check_release_authorize
|
||||
return render_forbidden("您没有权限进行此操作.") unless current_user.admin? || @project.manager?(current_user)
|
||||
return render_forbidden("您没有权限进行此操作.") unless current_user.admin? || @project.manager?(current_user) || @project.develper?(current_user)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -30,6 +30,14 @@ class BaseForm
|
|||
raise "项目名称已被使用." if Project.where(user_id: user_id, name: project_name.strip).exists?
|
||||
end
|
||||
|
||||
def check_blockchain_token_all(blockchain_token_all)
|
||||
raise "请正确填写项目token总数." if (Float(blockchain_token_all) rescue false) == false or blockchain_token_all.to_i < 0 or Float(blockchain_token_all) != blockchain_token_all.to_i
|
||||
end
|
||||
|
||||
def check_blockchain_init_token(blockchain_init_token)
|
||||
raise "请正确填写项目创始人token占比." if (Float(blockchain_init_token) rescue false) == false or blockchain_init_token.to_i < 0 or Float(blockchain_init_token) != blockchain_init_token.to_i
|
||||
end
|
||||
|
||||
def check_reversed_keyword(repository_name)
|
||||
raise "项目标识已被占用." if ReversedKeyword.check_exists?(repository_name)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class Organizations::CreateClaForm < BaseForm
|
||||
KEY_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||
attr_accessor :name, :key, :content, :pr_need
|
||||
validates :name , :key, presence: true
|
||||
validates :key, format: { with: KEY_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||
end
|
|
@ -1,9 +1,10 @@
|
|||
class Projects::CreateForm < BaseForm
|
||||
attr_accessor :user_id, :name, :description, :repository_name, :project_category_id,
|
||||
:project_language_id, :ignore_id, :license_id, :private, :owner
|
||||
:project_language_id, :ignore_id, :license_id, :private, :owner,
|
||||
:blockchain, :blockchain_token_all, :blockchain_init_token
|
||||
|
||||
validates :user_id, :name, :repository_name, presence: true
|
||||
validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||
validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "长度为2~100, 只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾" }
|
||||
|
||||
validates :name, length: { maximum: 50 }
|
||||
validates :repository_name, length: { maximum: 100 }
|
||||
|
@ -15,6 +16,8 @@ class Projects::CreateForm < BaseForm
|
|||
check_project_language(project_language_id)
|
||||
check_project_name(user_id, name) unless name.blank?
|
||||
check_repository_name(user_id, repository_name) unless repository_name.blank?
|
||||
check_blockchain_token_all(blockchain_token_all) unless blockchain_token_all.blank?
|
||||
check_blockchain_init_token(blockchain_init_token) unless blockchain_init_token.blank?
|
||||
end
|
||||
|
||||
def check_license
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
class Projects::MigrateForm < BaseForm
|
||||
attr_accessor :user_id, :name, :repository_name, :project_category_id, :description,
|
||||
attr_accessor :user_id, :name, :repository_name, :project_category_id, :description, :auth_token,
|
||||
:project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :owner
|
||||
|
||||
validates :user_id, :name, :repository_name, :clone_addr, presence: true
|
||||
validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||
validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "长度为2~100, 只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾" }
|
||||
validates :clone_addr, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" }
|
||||
validates :name, length: { maximum: 50 }
|
||||
validates :repository_name, length: { maximum: 100 }
|
||||
|
|
|
@ -3,7 +3,7 @@ class Projects::UpdateForm < BaseForm
|
|||
validates :name, presence: true
|
||||
validates :name, length: { maximum: 50 }
|
||||
validates :description, length: { maximum: 200 }
|
||||
validates :identifier, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||
validates :identifier, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: '长度为2~100, 只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾' }
|
||||
|
||||
validate do
|
||||
check_project_category(project_category_id)
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
module Register
|
||||
class RemoteForm < Register::BaseForm
|
||||
# login 登陆方式,支持邮箱、登陆、手机号等
|
||||
attr_accessor :username, :email, :password, :platform
|
||||
attr_accessor :username, :email, :password, :platform, :user_id
|
||||
|
||||
validates :username, :email, :password, presence: true
|
||||
validate :check!
|
||||
|
||||
def check!
|
||||
Rails.logger.info "Register::RemoteForm params: username: #{username}; email: #{email}; password: #{password}; platform: #{platform}"
|
||||
check_login(username)
|
||||
check_mail(email)
|
||||
user = User.find_by(id: user_id)
|
||||
Rails.logger.info "Register::RemoteForm params: id: #{user&.id}; username: #{username}; email: #{email}; password: #{password}; platform: #{platform}"
|
||||
check_login(username, user)
|
||||
check_mail(email,user)
|
||||
check_password(password)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class Users::UserClaForm
|
||||
include ActiveModel::Model
|
||||
attr_accessor :email, :real_name, :cla_id
|
||||
validates :email, presence: true, format: { with: CustomRegexp::EMAIL }
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
module Admins::GlccPrCheckHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Admins::IdentityVerificationsHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Admins::OrganizationsHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Admins::PageThemesHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Admins::SitePagesHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module IdentityVerificationsHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Organizations::ClasHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module PagesHelper
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue