Compare commits

..

40 Commits

Author SHA1 Message Date
xxq250 55e9409d9a Merge pull request '部署说明调整' (#337) from dev_local_v1 into docker 2023-08-15 14:46:24 +08:00
xxq250 d13ac9e9fe 部署调整去掉ssl_mode 2023-07-20 09:18:07 +08:00
xxq250 253196e000 部署说明调整 2023-07-18 15:46:45 +08:00
xxq250 4d751e6b3e 前端文件更新 2023-07-18 15:29:04 +08:00
xxq250 755fff03a1 fix 本地版调整 2023-07-18 15:15:05 +08:00
xxq250 a117f0bf73 gitea admin 2023-06-26 18:32:50 +08:00
xxq250 7176d3d2d5 开启redis缓存 2023-06-14 14:43:45 +08:00
xxq250 8874898ff3 Merge pull request '整理docker打包' (#336) from docker into dev_local_v1 2023-06-14 14:42:26 +08:00
xxq250 9e814ee16a Merge pull request '细化' (#335) from Trustie/forgeplus:dev_local_v1 into dev_local_v1 2023-06-14 14:14:42 +08:00
xxq250 fe47840e53 init Gemfile.lock 2023-06-01 14:53:12 +08:00
xxqfamous afecd95947 gemfile 2023-05-31 14:30:26 +08:00
xxq250 2ec14f6665 Delete 'Gemfile.lock' 2023-05-31 14:28:15 +08:00
xxqfamous 1c7e74ed1d gitea admin 禁用 2023-05-29 18:41:20 +08:00
xxqfamous 0a6957f193 gitea文件位置变化 2023-05-29 18:40:32 +08:00
xxqfamous 4bd3d98021 整理初始菜单sql 2023-05-29 18:18:00 +08:00
xxqfamous 14df764275 整理初始菜单sql 2023-05-29 17:16:50 +08:00
xxqfamous 24be0501b7 docker部署整理-gitea更新小镜像 2023-05-29 16:53:58 +08:00
xxqfamous b45fb35ea1 docker部署整理-gitea环境变量 2023-05-29 16:50:24 +08:00
xxqfamous 3646822ec3 docker部署整理 ssl禁用 2023-05-25 18:35:19 +08:00
xxqfamous 9d5609e544 docker部署整理 ssl禁用 2023-05-25 18:30:12 +08:00
xxqfamous 3f9a3aacfa docker部署整理 ssl禁用 2023-05-25 17:45:03 +08:00
xxqfamous 38458764b4 docker部署整理 启动 2023-05-25 14:06:44 +08:00
xxqfamous dd94480486 docker部署整理 启动 2023-05-25 13:58:24 +08:00
xxqfamous 3dd62f40df docker部署整理 启动 2023-05-25 11:33:29 +08:00
xxqfamous a0f13e3a0c docker部署整理 log目录 2023-05-25 11:19:40 +08:00
xxqfamous 600235effa docker部署整理 gem 2023-05-25 11:06:03 +08:00
xxqfamous 7578fb9e0a docker部署整理 2023-05-25 10:59:24 +08:00
xxqfamous c8a356b836 docker部署整理 2023-05-25 10:24:51 +08:00
xxqfamous eb38b3fda4 docker部署整理 2023-05-24 18:28:12 +08:00
xxqfamous 2c5c03f77c docker部署整理 2023-05-24 17:50:26 +08:00
xxq250 67f3a87afc fixed 审批utf8mb4 2023-05-18 09:37:16 +08:00
xxq250 b5553e2c97 fixed js zip 2023-05-16 20:51:27 +08:00
xxq250 a542b02181 fixed js zip 2023-05-16 20:44:11 +08:00
xxq250 b7786fc870 fixed js zip 2023-05-16 20:07:01 +08:00
xxq250 31f44685d9 fixed emj 2023-05-16 09:55:59 +08:00
xxq250 41e6d6ab09 fixed 用户项目包含私有 2023-05-16 09:20:00 +08:00
xxq250 d24703be75 完善资料去掉 2023-05-12 15:20:14 +08:00
xxq250 487d548e9f 本地版去掉触发的“引擎”相关通知 2023-05-12 10:11:56 +08:00
xxq250 07696682ca 本地版去掉三方登录 2023-05-12 10:06:40 +08:00
xxq250 c64f241cf8 本地版取消验证码 2023-05-08 15:55:54 +08:00
1857 changed files with 214353 additions and 115715 deletions

6
.gitignore vendored
View File

@ -10,8 +10,7 @@
# Ignore lock config file # Ignore lock config file
*.log *.log
.rubocop.yml
.env
# mac # mac
*.DS_Store *.DS_Store
.bashrc .bashrc
@ -85,5 +84,4 @@ redis_data/
dump.rdb dump.rdb
.tags* .tags*
ceshi_user.xlsx ceshi_user.xlsx
public/trace_task_results public/trace_task_results
public/项目活跃度排行.xls

View File

@ -1,59 +1,29 @@
FROM ubuntu:20.04 FROM registry.cn-hangzhou.aliyuncs.com/gitlink/ruby:2.4.5
RUN apt-get update
ADD ./ /home/pdl/gitlink
WORKDIR /home/pdl/gitlink
RUN DEBIAN_FRONTEND=noninteractive apt install -y tzdata
# basics
RUN apt-get install -y libssl-dev curl libmysqlclient-dev imagemagick nodejs mysql-server redis-server
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
# rvm environment variable
RUN /bin/bash -l -c "source /etc/profile.d/rvm.sh" RUN /bin/bash -l -c "source /etc/profile.d/rvm.sh"
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-get install -y nodejs
WORKDIR /home/app/gitlink
ADD ./ /home/app/gitlink
RUN cd /home/app/gitlink
RUN /bin/bash -l -c 'gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/' RUN /bin/bash -l -c 'gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/'
RUN /bin/bash -l -c 'gem update --system' 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 rm -rf Gemfile.lock
RUN cp config/configuration.yml.example config/configuration.yml RUN cp config/configuration.yml.example config/configuration.yml
RUN cp config/database-docker.yml.example config/database.yml RUN cp config/database.yml.example config/database.yml
RUN cp config/environments/production.rb.example config/environments/production.rb
RUN cp config/secrets.yml.example config/secrets.yml
RUN touch config/redis.yml RUN touch config/redis.yml
RUN touch config/elasticsearch.yml RUN touch config/elasticsearch.yml
RUN mkdir log
RUN /bin/bash -l -c 'bundle install' RUN /bin/bash -l -c 'bundle install'
#RUN /bin/bash -l -c 'RAILS_ENV=production rails db:create'
#RUN /bin/bash -l -c 'RAILS_ENV=production bundle exec rake sync_table_structure:import_csv'
#RUN /bin/bash -l -c 'RAILS_ENV=production rails db:migrate'
RUN redis-server & #EXPOSE 4000
#RUN /bin/bash -l -c 'RAILS_ENV=production puma'
RUN /bin/bash -l -c 'bundle exec rake sync_table_structure:import_csv'
RUN /bin/bash -l -c 'rails db:migrate RAILS_ENV=development'
RUN /bin/bash -l -c 'bundle exec sidekiq -C config/sidekiq.yml -e production -d'
EXPOSE 4000
RUN /bin/bash -l -c 'RAILS_ENV=production puma -C config/puma.rb'

11
Gemfile
View File

@ -1,6 +1,5 @@
#source 'https://gems.ruby-china.com' #source 'https://gems.ruby-china.com'
source 'https://mirrors.cloud.tencent.com/rubygems/' source 'https://mirrors.cloud.tencent.com/rubygems/'
#source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" } git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'rails', '~> 5.2.0' gem 'rails', '~> 5.2.0'
@ -21,13 +20,15 @@ gem 'bootsnap', '>= 1.1.0', require: false
gem 'chinese_pinyin' gem 'chinese_pinyin'
# gem 'loofah','~> 2.20.0'
gem 'rack-cors' gem 'rack-cors'
gem 'redis-rails' gem 'redis-rails'
gem 'roo-xls' gem 'roo-xls'
gem 'simple_xlsx_reader', '~>1.0.4' gem 'simple_xlsx_reader', '~>1.0.4'
gem 'rubyzip' gem 'rubyzip'
gem 'sonarqube', :git => 'https://gitlink.org.cn/KingChan/sonarqube.git'
gem 'spreadsheet' gem 'spreadsheet'
gem 'ruby-ole' gem 'ruby-ole'
# 导出为xlsx # 导出为xlsx
@ -71,7 +72,6 @@ group :development do
gem 'web-console', '>= 3.3.0' gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2' gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring' gem 'spring'
gem 'pry-rails'
gem 'spring-watcher-listen', '~> 2.0.0' gem 'spring-watcher-listen', '~> 2.0.0'
gem "annotate", "~> 2.6.0" gem "annotate", "~> 2.6.0"
end end
@ -116,6 +116,7 @@ gem 'aasm'
gem 'enumerize' gem 'enumerize'
gem 'diffy' gem 'diffy'
gem 'deep_cloneable', '~> 3.0.0' gem 'deep_cloneable', '~> 3.0.0'
# oauth2 # oauth2
@ -142,6 +143,4 @@ gem 'doorkeeper'
gem 'doorkeeper-jwt' gem 'doorkeeper-jwt'
gem 'gitea-client', '~> 1.6.1' gem 'gitea-client', '~> 1.4.2'
gem 'loofah', '~> 2.20.0'

View File

@ -1,47 +1,47 @@
GEM GEM
remote: https://mirrors.cloud.tencent.com/rubygems/ remote: https://mirrors.cloud.tencent.com/rubygems/
specs: specs:
aasm (5.0.6) aasm (5.5.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
actioncable (5.2.4.1) actioncable (5.2.8.1)
actionpack (= 5.2.4.1) actionpack (= 5.2.8.1)
nio4r (~> 2.0) nio4r (~> 2.0)
websocket-driver (>= 0.6.1) websocket-driver (>= 0.6.1)
actionmailer (5.2.4.1) actionmailer (5.2.8.1)
actionpack (= 5.2.4.1) actionpack (= 5.2.8.1)
actionview (= 5.2.4.1) actionview (= 5.2.8.1)
activejob (= 5.2.4.1) activejob (= 5.2.8.1)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
actionpack (5.2.4.1) actionpack (5.2.8.1)
actionview (= 5.2.4.1) actionview (= 5.2.8.1)
activesupport (= 5.2.4.1) activesupport (= 5.2.8.1)
rack (~> 2.0, >= 2.0.8) rack (~> 2.0, >= 2.0.8)
rack-test (>= 0.6.3) rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.4.1) actionview (5.2.8.1)
activesupport (= 5.2.4.1) activesupport (= 5.2.8.1)
builder (~> 3.1) builder (~> 3.1)
erubi (~> 1.4) erubi (~> 1.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3) rails-html-sanitizer (~> 1.0, >= 1.0.3)
active_decorator (1.3.2) active_decorator (1.4.0)
activesupport activesupport
activejob (5.2.4.1) activejob (5.2.8.1)
activesupport (= 5.2.4.1) activesupport (= 5.2.8.1)
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (5.2.4.1) activemodel (5.2.8.1)
activesupport (= 5.2.4.1) activesupport (= 5.2.8.1)
activerecord (5.2.4.1) activerecord (5.2.8.1)
activemodel (= 5.2.4.1) activemodel (= 5.2.8.1)
activesupport (= 5.2.4.1) activesupport (= 5.2.8.1)
arel (>= 9.0) arel (>= 9.0)
activestorage (5.2.4.1) activestorage (5.2.8.1)
actionpack (= 5.2.4.1) actionpack (= 5.2.8.1)
activerecord (= 5.2.4.1) activerecord (= 5.2.8.1)
marcel (~> 0.3.1) marcel (~> 1.0.0)
activesupport (5.2.4.1) activesupport (5.2.8.1)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2) i18n (>= 0.7, < 2)
minitest (~> 5.1) minitest (~> 5.1)
@ -50,20 +50,20 @@ GEM
activerecord (>= 5.0, < 6.1) activerecord (>= 5.0, < 6.1)
acts_as_list (0.9.19) acts_as_list (0.9.19)
activerecord (>= 3.0) activerecord (>= 3.0)
addressable (2.7.0) addressable (2.8.4)
public_suffix (>= 2.0.2, < 5.0) public_suffix (>= 2.0.2, < 6.0)
ancestry (3.0.7) ancestry (4.0.0)
activerecord (>= 3.2.0) activerecord (>= 5.2.4.5)
annotate (2.6.5) annotate (2.6.7)
activerecord (>= 2.3.0) activerecord (>= 2.3.0)
rake (>= 0.8.7) rake (~> 10.4.2, >= 10.4.2)
archive-zip (0.12.0) archive-zip (0.12.0)
io-like (~> 0.3.0) io-like (~> 0.3.0)
arel (9.0.0) arel (9.0.0)
ast (2.4.0) ast (2.4.2)
autoprefixer-rails (9.7.4) autoprefixer-rails (10.4.13.0)
execjs execjs (~> 2)
awesome_print (1.8.0) awesome_print (1.9.2)
axlsx (3.0.0.pre) axlsx (3.0.0.pre)
htmlentities (~> 4.3, >= 4.3.4) htmlentities (~> 4.3, >= 4.3.4)
mimemagic (~> 0.3) mimemagic (~> 0.3)
@ -72,41 +72,40 @@ GEM
axlsx_rails (0.5.2) axlsx_rails (0.5.2)
actionpack (>= 3.1) actionpack (>= 3.1)
axlsx (>= 2.0.1) axlsx (>= 2.0.1)
backport (1.1.2) backport (1.2.0)
benchmark (0.1.0) benchmark (0.2.1)
bindex (0.8.1) bindex (0.8.1)
bootsnap (1.4.6) bootsnap (1.12.0)
msgpack (~> 1.0) msgpack (~> 1.2)
bootstrap (4.3.1) bootstrap (4.3.1)
autoprefixer-rails (>= 9.1.0) autoprefixer-rails (>= 9.1.0)
popper_js (>= 1.14.3, < 2) popper_js (>= 1.14.3, < 2)
sassc-rails (>= 2.0.0) sassc-rails (>= 2.0.0)
builder (3.2.4) builder (3.2.4)
bulk_insert (1.7.0) bulk_insert (1.9.0)
activerecord (>= 3.2.0) activerecord (>= 3.2.0)
capybara (3.15.1) capybara (3.32.2)
addressable addressable
mini_mime (>= 0.1.3) mini_mime (>= 0.1.3)
nokogiri (~> 1.8) nokogiri (~> 1.8)
rack (>= 1.6.0) rack (>= 1.6.0)
rack-test (>= 0.6.3) rack-test (>= 0.6.3)
regexp_parser (~> 1.2) regexp_parser (~> 1.5)
xpath (~> 3.2) xpath (~> 3.2)
chartkick (3.3.1) chartkick (3.4.2)
childprocess (3.0.0) childprocess (3.0.0)
chinese_pinyin (1.0.2) chinese_pinyin (1.1.0)
chromedriver-helper (2.1.1) chromedriver-helper (2.1.1)
archive-zip (~> 0.10) archive-zip (~> 0.10)
nokogiri (~> 1.8) nokogiri (~> 1.8)
chunky_png (1.3.11) chunky_png (1.4.0)
coderay (1.1.3) concurrent-ruby (1.2.2)
concurrent-ruby (1.1.6) connection_pool (2.2.5)
connection_pool (2.2.2)
crass (1.0.6) crass (1.0.6)
deep_cloneable (3.0.0) deep_cloneable (3.0.0)
activerecord (>= 3.1.0, < 7) activerecord (>= 3.1.0, < 7)
diff-lcs (1.3) diff-lcs (1.5.0)
diffy (3.3.0) diffy (3.4.2)
domain_name (0.5.20190701) domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
doorkeeper (5.5.1) doorkeeper (5.5.1)
@ -122,21 +121,21 @@ GEM
elasticsearch-transport (7.5.0) elasticsearch-transport (7.5.0)
faraday (>= 0.14, < 1) faraday (>= 0.14, < 1)
multi_json multi_json
enumerize (2.3.1) enumerize (2.5.0)
activesupport (>= 3.2) activesupport (>= 3.2)
erubi (1.9.0) erubi (1.12.0)
et-orbi (1.2.4) et-orbi (1.2.7)
tzinfo tzinfo
execjs (2.7.0) execjs (2.8.1)
faraday (0.15.4) faraday (0.15.4)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
ffi (1.12.2) ffi (1.15.5)
font-awesome-sass (4.7.0) font-awesome-sass (4.7.0)
sass (>= 3.2) sass (>= 3.2)
fugit (1.4.1) fugit (1.8.1)
et-orbi (~> 1.1, >= 1.1.8) et-orbi (~> 1, >= 1.2.7)
raabro (~> 1.4) raabro (~> 1.4)
gitea-client (1.5.9) gitea-client (1.4.2)
rest-client (~> 2.1.0) rest-client (~> 2.1.0)
globalid (0.4.2) globalid (0.4.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
@ -146,80 +145,78 @@ GEM
groupdate (4.1.2) groupdate (4.1.2)
activesupport (>= 4.2) activesupport (>= 4.2)
harmonious_dictionary (0.0.1) harmonious_dictionary (0.0.1)
hashie (3.6.0) hashie (5.0.0)
htmlentities (4.3.4) htmlentities (4.3.4)
http-accept (1.7.0) http-accept (1.7.0)
http-cookie (1.0.8) http-cookie (1.0.5)
domain_name (~> 0.5) domain_name (~> 0.5)
i18n (1.8.2) i18n (1.13.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
io-like (0.3.1) io-like (0.3.1)
jaro_winkler (1.5.4) jaro_winkler (1.5.5)
jbuilder (2.10.0) jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
jquery-rails (4.3.5) jquery-rails (4.5.1)
rails-dom-testing (>= 1, < 3) rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
jwt (2.2.1) jwt (2.3.0)
kaminari (1.2.0) kaminari (1.2.2)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.0) kaminari-actionview (= 1.2.2)
kaminari-activerecord (= 1.2.0) kaminari-activerecord (= 1.2.2)
kaminari-core (= 1.2.0) kaminari-core (= 1.2.2)
kaminari-actionview (1.2.0) kaminari-actionview (1.2.2)
actionview actionview
kaminari-core (= 1.2.0) kaminari-core (= 1.2.2)
kaminari-activerecord (1.2.0) kaminari-activerecord (1.2.2)
activerecord activerecord
kaminari-core (= 1.2.0) kaminari-core (= 1.2.2)
kaminari-core (1.2.0) kaminari-core (1.2.2)
letter_avatar (0.3.8) letter_avatar (0.3.9)
listen (3.1.5) listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4) rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7) rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2) ruby_dep (~> 1.2)
logger (1.6.6)
loofah (2.20.0) loofah (2.20.0)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.7.1) mail (2.7.1)
mini_mime (>= 0.1.1) mini_mime (>= 0.1.1)
marcel (0.3.3) marcel (1.0.2)
mimemagic (~> 0.3.2)
maruku (0.7.3) maruku (0.7.3)
method_source (0.9.2) method_source (1.0.0)
mime-types (3.6.0) mime-types (3.4.1)
logger
mime-types-data (~> 3.2015) mime-types-data (~> 3.2015)
mime-types-data (3.2025.0220) mime-types-data (3.2023.0218.1)
mimemagic (0.3.10) mimemagic (0.4.3)
nokogiri (~> 1) nokogiri (~> 1)
rake rake
mini_mime (1.0.2) mini_mime (1.1.2)
mini_portile2 (2.4.0) mini_portile2 (2.4.0)
minitest (5.14.0) minitest (5.15.0)
msgpack (1.3.3) msgpack (1.6.1)
multi_json (1.14.1) multi_json (1.15.0)
multi_xml (0.6.0) multi_xml (0.6.0)
multipart-post (2.1.1) multipart-post (2.3.0)
mustermann (1.1.1) mustermann (1.1.2)
ruby2_keywords (~> 0.0.1) ruby2_keywords (~> 0.0.1)
mysql2 (0.5.3) mysql2 (0.5.5)
netrc (0.11.0) netrc (0.11.0)
nio4r (2.5.2) nio4r (2.5.9)
nokogiri (1.10.8) nokogiri (1.10.10)
mini_portile2 (~> 2.4.0) mini_portile2 (~> 2.4.0)
oauth2 (1.4.4) oauth2 (1.4.8)
faraday (>= 0.8, < 2.0) faraday (>= 0.8, < 3.0)
jwt (>= 1.0, < 3.0) jwt (>= 1.0, < 3.0)
multi_json (~> 1.3) multi_json (~> 1.3)
multi_xml (~> 0.5) multi_xml (~> 0.5)
rack (>= 1.2, < 3) rack (>= 1.2, < 3)
omniauth (1.9.0) omniauth (1.9.2)
hashie (>= 3.4.6, < 3.7.0) hashie (>= 3.4.6)
rack (>= 1.6.2, < 3) rack (>= 1.6.2, < 3)
omniauth-cas (1.1.1) omniauth-cas (2.0.0)
addressable (~> 2.3) addressable (~> 2.3)
nokogiri (~> 1.5) nokogiri (~> 1.5)
omniauth (~> 1.2) omniauth (~> 1.2)
@ -238,89 +235,81 @@ GEM
omniauth-wechat-oauth2 (0.2.2) omniauth-wechat-oauth2 (0.2.2)
omniauth (>= 1.3.2) omniauth (>= 1.3.2)
omniauth-oauth2 (>= 1.1.1) omniauth-oauth2 (>= 1.1.1)
parallel (1.19.1) parallel (1.20.1)
parser (2.7.1.1) parser (2.7.2.0)
ast (~> 2.4.0) ast (~> 2.4.1)
pdfkit (0.8.4.1) pdfkit (0.8.4.3.2)
polyamorous (2.3.2) popper_js (1.16.1)
activerecord (>= 5.2.1) powerpack (0.1.3)
popper_js (1.16.0) prettier (2.1.0)
powerpack (0.1.2) public_suffix (4.0.7)
prettier (0.18.2)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.3)
puma (5.6.5) puma (5.6.5)
nio4r (~> 2.0) nio4r (~> 2.0)
raabro (1.4.0) raabro (1.4.0)
rack (2.0.9) rack (2.0.9.3)
rack-cors (1.1.1) rack-cors (2.0.1)
rack (>= 2.0.0) rack (>= 2.0.0)
rack-protection (2.0.8.1) rack-protection (2.0.8.1)
rack rack
rack-test (1.1.0) rack-test (2.1.0)
rack (>= 1.0, < 3) rack (>= 1.3)
rails (5.2.4.1) rails (5.2.8.1)
actioncable (= 5.2.4.1) actioncable (= 5.2.8.1)
actionmailer (= 5.2.4.1) actionmailer (= 5.2.8.1)
actionpack (= 5.2.4.1) actionpack (= 5.2.8.1)
actionview (= 5.2.4.1) actionview (= 5.2.8.1)
activejob (= 5.2.4.1) activejob (= 5.2.8.1)
activemodel (= 5.2.4.1) activemodel (= 5.2.8.1)
activerecord (= 5.2.4.1) activerecord (= 5.2.8.1)
activestorage (= 5.2.4.1) activestorage (= 5.2.8.1)
activesupport (= 5.2.4.1) activesupport (= 5.2.8.1)
bundler (>= 1.3.0) bundler (>= 1.3.0)
railties (= 5.2.4.1) railties (= 5.2.8.1)
sprockets-rails (>= 2.0.0) sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3) rails-dom-testing (2.0.3)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
nokogiri (>= 1.6) nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0) rails-html-sanitizer (1.5.0)
loofah (~> 2.3) loofah (~> 2.19, >= 2.19.1)
rails-i18n (5.1.3) rails-i18n (5.1.3)
i18n (>= 0.7, < 2) i18n (>= 0.7, < 2)
railties (>= 5.0, < 6) railties (>= 5.0, < 6)
railties (5.2.4.1) railties (5.2.8.1)
actionpack (= 5.2.4.1) actionpack (= 5.2.8.1)
activesupport (= 5.2.4.1) activesupport (= 5.2.8.1)
method_source method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0) thor (>= 0.19.0, < 2.0)
rainbow (3.0.0) rainbow (3.1.1)
rake (13.0.1) rake (10.4.2)
ransack (2.3.2) ransack (2.4.1)
activerecord (>= 5.2.1) activerecord (>= 5.2.4)
activesupport (>= 5.2.1) activesupport (>= 5.2.4)
i18n i18n
polyamorous (= 2.3.2) rb-fsevent (0.11.2)
rb-fsevent (0.10.3)
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
rchardet (1.8.0) rchardet (1.8.0)
redcarpet (3.5.0) redcarpet (3.6.0)
redis (4.1.3) redis (4.8.1)
redis-actionpack (5.2.0) redis-actionpack (5.3.0)
actionpack (>= 5, < 7) actionpack (>= 5, < 8)
redis-rack (>= 2.1.0, < 3) redis-rack (>= 2.1.0, < 3)
redis-store (>= 1.1.0, < 2) redis-store (>= 1.1.0, < 2)
redis-activesupport (5.2.0) redis-activesupport (5.3.0)
activesupport (>= 3, < 7) activesupport (>= 3, < 8)
redis-store (>= 1.3, < 2) redis-store (>= 1.3, < 2)
redis-rack (2.1.2) redis-rack (2.1.4)
rack (>= 2.0.8, < 3) rack (>= 2.0.8, < 3)
redis-store (>= 1.2, < 2) redis-store (>= 1.2, < 2)
redis-rails (5.0.2) redis-rails (5.0.2)
redis-actionpack (>= 5.0, < 6) redis-actionpack (>= 5.0, < 6)
redis-activesupport (>= 5.0, < 6) redis-activesupport (>= 5.0, < 6)
redis-store (>= 1.2, < 2) redis-store (>= 1.2, < 2)
redis-store (1.8.2) redis-store (1.9.2)
redis (>= 4, < 5) redis (>= 4, < 6)
regexp_parser (1.7.0) regexp_parser (1.8.2)
request_store (1.5.0) request_store (1.5.1)
rack (>= 1.4) rack (>= 1.4)
rest-client (2.1.0) rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0) http-accept (>= 1.7.0, < 2.0)
@ -341,15 +330,15 @@ GEM
rqrcode_png (0.1.5) rqrcode_png (0.1.5)
chunky_png chunky_png
rqrcode rqrcode
rspec-core (3.9.1) rspec-core (3.9.3)
rspec-support (~> 3.9.1) rspec-support (~> 3.9.3)
rspec-expectations (3.9.0) rspec-expectations (3.9.4)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0) rspec-support (~> 3.9.0)
rspec-mocks (3.9.1) rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0) rspec-support (~> 3.9.0)
rspec-rails (3.9.0) rspec-rails (3.9.1)
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
railties (>= 3.0) railties (>= 3.0)
@ -357,7 +346,7 @@ GEM
rspec-expectations (~> 3.9.0) rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0) rspec-mocks (~> 3.9.0)
rspec-support (~> 3.9.0) rspec-support (~> 3.9.0)
rspec-support (3.9.2) rspec-support (3.9.4)
rubocop (0.52.1) rubocop (0.52.1)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 2.4.0.2, < 3.0) parser (>= 2.4.0.2, < 3.0)
@ -366,8 +355,8 @@ GEM
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1) unicode-display_width (~> 1.0, >= 1.0.1)
ruby-ole (1.2.12.2) ruby-ole (1.2.12.2)
ruby-progressbar (1.10.1) ruby-progressbar (1.13.0)
ruby2_keywords (0.0.2) ruby2_keywords (0.0.5)
ruby_dep (1.5.0) ruby_dep (1.5.0)
rubyzip (1.3.0) rubyzip (1.3.0)
sass (3.7.4) sass (3.7.4)
@ -375,13 +364,13 @@ GEM
sass-listen (4.0.0) sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4) rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7) rb-inotify (~> 0.9, >= 0.9.7)
sass-rails (5.0.7) sass-rails (5.1.0)
railties (>= 4.0.0, < 6) railties (>= 5.2.0)
sass (~> 3.1) sass (~> 3.1)
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3) tilt (>= 1.1, < 3)
sassc (2.2.1) sassc (2.4.0)
ffi (~> 1.9) ffi (~> 1.9)
sassc-rails (2.1.2) sassc-rails (2.1.2)
railties (>= 4.0.0) railties (>= 4.0.0)
@ -389,9 +378,9 @@ GEM
sprockets (> 3.0) sprockets (> 3.0)
sprockets-rails sprockets-rails
tilt tilt
searchkick (3.1.3) searchkick (4.6.3)
activemodel (>= 4.2) activemodel (>= 5)
elasticsearch (>= 5) elasticsearch (>= 6, < 7.14)
hashie hashie
selenium-webdriver (3.142.7) selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0) childprocess (>= 0.5, < 4.0)
@ -406,10 +395,10 @@ GEM
sidekiq (>= 4.2.1) sidekiq (>= 4.2.1)
sidekiq-failures (1.0.4) sidekiq-failures (1.0.4)
sidekiq (>= 4.0.0) sidekiq (>= 4.0.0)
simple_form (5.0.2) simple_form (5.0.3)
actionpack (>= 5.0) actionpack (>= 5.0)
activemodel (>= 5.0) activemodel (>= 5.0)
simple_xlsx_reader (1.0.4) simple_xlsx_reader (1.0.5)
nokogiri nokogiri
rubyzip rubyzip
sinatra (2.0.8.1) sinatra (2.0.8.1)
@ -431,44 +420,45 @@ GEM
thor (~> 1.0) thor (~> 1.0)
tilt (~> 2.0) tilt (~> 2.0)
yard (~> 0.9) yard (~> 0.9)
spreadsheet (1.2.6) spreadsheet (1.3.0)
ruby-ole (>= 1.0) ruby-ole
spring (2.0.2) spring (2.1.1)
activesupport (>= 4.2)
spring-watcher-listen (2.0.1) spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0) listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0) spring (>= 1.2, < 3.0)
sprockets (3.7.2) sprockets (3.7.2)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
sprockets-rails (3.2.1) sprockets-rails (3.2.2)
actionpack (>= 4.0) actionpack (>= 4.0)
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
thor (1.0.1) thor (1.2.2)
thread_safe (0.3.6) thread_safe (0.3.6)
tilt (2.0.10) tilt (2.1.0)
turbolinks (5.2.1) turbolinks (5.2.1)
turbolinks-source (~> 5.2) turbolinks-source (~> 5.2)
turbolinks-source (5.2.0) turbolinks-source (5.2.0)
tzinfo (1.2.6) tzinfo (1.2.11)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (4.2.0) uglifier (4.2.0)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
unf (0.2.0) unf (0.1.4)
unicode-display_width (1.6.1) unf_ext
unf_ext (0.0.8.2)
unicode-display_width (1.8.0)
web-console (3.7.0) web-console (3.7.0)
actionview (>= 5.0) actionview (>= 5.0)
activemodel (>= 5.0) activemodel (>= 5.0)
bindex (>= 0.4.0) bindex (>= 0.4.0)
railties (>= 5.0) railties (>= 5.0)
websocket-driver (0.7.1) websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4) websocket-extensions (0.1.5)
wkhtmltopdf-binary (0.12.5.4) wkhtmltopdf-binary (0.12.6.6)
xpath (3.2.0) xpath (3.2.0)
nokogiri (~> 1.8) nokogiri (~> 1.8)
yard (0.9.24) yard (0.9.34)
PLATFORMS PLATFORMS
ruby ruby
@ -497,7 +487,7 @@ DEPENDENCIES
enumerize enumerize
faraday (~> 0.15.4) faraday (~> 0.15.4)
font-awesome-sass (= 4.7.0) font-awesome-sass (= 4.7.0)
gitea-client (~> 1.5.8) gitea-client (~> 1.4.2)
grape-entity (~> 0.7.1) grape-entity (~> 0.7.1)
groupdate (~> 4.1.0) groupdate (~> 4.1.0)
harmonious_dictionary (~> 0.0.1) harmonious_dictionary (~> 0.0.1)
@ -520,7 +510,6 @@ DEPENDENCIES
parallel (~> 1.19, >= 1.19.1) parallel (~> 1.19, >= 1.19.1)
pdfkit pdfkit
prettier prettier
pry-rails
puma (~> 5.6.5) puma (~> 5.6.5)
rack-cors rack-cors
rails (~> 5.2.0) rails (~> 5.2.0)
@ -557,4 +546,4 @@ DEPENDENCIES
wkhtmltopdf-binary wkhtmltopdf-binary
BUNDLED WITH BUNDLED WITH
2.1.4 1.17.3

View File

@ -3,8 +3,7 @@
GitLink确实开源是中国计算机学会CCF官方指定的开源创新服务平台旨在以“为开源创新服务”为使命以“成为开源创新的汇聚地”为愿景秉承“创新、开放、协作、共享”的价值观致力于为大规模开源开放协同创新助力赋能打造创新成果孵化和新工科人才培养的开源创新生态 GitLink确实开源是中国计算机学会CCF官方指定的开源创新服务平台旨在以“为开源创新服务”为使命以“成为开源创新的汇聚地”为愿景秉承“创新、开放、协作、共享”的价值观致力于为大规模开源开放协同创新助力赋能打造创新成果孵化和新工科人才培养的开源创新生态
<center> <center>
<img src="docs/figs/gitlink.png" width=80% /></center> <img src="https://code.gitlink.org.cn/young/forgeplus/raw/branch/master/docs/figs/gitlink.png?raw=true" width=80% /></center>
## 特色功能 ## 特色功能
@ -175,31 +174,31 @@ http://localhost:3000/
- 项目列表 - 项目列表
<center> <center>
<img src="docs/figs/project_list.png" width=80% /> <img src="https://code.gitlink.org.cn/young/forgeplus/raw/branch/master/docs/figs/project_list.png?raw=true" width=50% />
</center> </center>
- 代码仓库 - 代码仓库
<center> <center>
<img src="docs/figs/repo.png" width=80% /> <img src="https://code.gitlink.org.cn/young/forgeplus/raw/branch/master/docs/figs/repo.png?raw=true" width=50% />
</center> </center>
- 任务管理 - 任务管理
<center> <center>
<img src="docs/figs/issues.png" width=80% /> <img src="https://code.gitlink.org.cn/young/forgeplus/raw/branch/master/docs/figs/issues.png?raw=true" width=50% />
</center> </center>
- 合并请求 - 合并请求
<center> <center>
<img src="docs/figs/PR.png" width=80% /> <img src="https://code.gitlink.org.cn/young/forgeplus/raw/branch/master/docs/figs/PR.png?raw=true" width=50% />
</center> </center>
- 引擎配置 - 引擎配置
<center> <center>
<img src="docs/figs/engine.png" width=80% /> <img src="https://code.gitlink.org.cn/young/forgeplus/raw/branch/master/docs/figs/engine.png?raw=true" width=50% />
</center> </center>

View File

@ -24,7 +24,7 @@
//= require codemirror/mode/shell/shell //= require codemirror/mode/shell/shell
//= require editormd/editormd //= require editormd/editormd
//= require editormd/languages/zh-tw //= require editormd/languages/zh-tw
//= require dragula/dragula
//= require_tree ./i18n //= require_tree ./i18n
//= require_tree ./admins //= require_tree ./admins

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -63,7 +63,7 @@ $(document).on('turbolinks:load', function() {
if(!valid) return; if(!valid) return;
$.ajax({ $.ajax({
method: 'PUT', method: 'PATCH',
dataType: 'json', dataType: 'json',
url: $form.attr('action'), url: $form.attr('action'),
data: new FormData($form[0]), data: new FormData($form[0]),

View File

@ -1,65 +0,0 @@
$(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' });
}
});
}
})
});
}
});

View File

@ -1,3 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -40,13 +40,6 @@ body {
} }
} }
} }
.editormd .CodeMirror{
margin-top: 35px!important;
}
.CodeMirror-gutter .CodeMirror-linenumbers {
width: 28px!important;
}
input.form-control { input.form-control {
font-size: 14px; font-size: 14px;

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,3 +0,0 @@
// Place all the styles related to the api/pm/issue_links controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -1,3 +0,0 @@
// Place all the styles related to the api/pm/projects controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -1,3 +0,0 @@
// Place all the styles related to the api/v1/pm_issues controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -1,3 +0,0 @@
// Place all the styles related to the api/v1/sonarqube/issues controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -1,3 +0,0 @@
// Place all the styles related to the api/v1/sonarqubes controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,3 +0,0 @@
// Place all the styles related to the pm/journals controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,20 +1,18 @@
class AccountsController < ApplicationController class AccountsController < ApplicationController
before_action :require_login, only: [:login_check, :simple_update, :change_password] before_action :require_login, only: [:login_check, :simple_update]
include ApplicationHelper include ApplicationHelper
include AesCryptHelper
#skip_before_action :check_account, :only => [:logout] #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!(username: params[:username]&.gsub(/\s+/, ""))
simple_update_params.merge!(email: params[:email]&.gsub(/\s+/, "")) simple_update_params.merge!(email: params[:email]&.gsub(/\s+/, ""))
simple_update_params.merge!(platform: (params[:platform] || 'forge')&.gsub(/\s+/, "")) simple_update_params.merge!(platform: (params[:platform] || 'forge')&.gsub(/\s+/, ""))
Register::RemoteForm.new(simple_update_params.merge(user_id: current_user.id)).validate! Register::RemoteForm.new(simple_update_params).validate!
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
result = auto_update(current_user, simple_update_params) result = auto_update(current_user, simple_update_params)
if result[:message].blank? 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 render_ok
else else
render_error(result[:message]) render_error(result[:message])
@ -32,12 +30,11 @@ class AccountsController < ApplicationController
username = params[:username]&.gsub(/\s+/, "") username = params[:username]&.gsub(/\s+/, "")
tip_exception("无法使用以下关键词:#{username},请重新命名") if ReversedKeyword.check_exists?(username) tip_exception("无法使用以下关键词:#{username},请重新命名") if ReversedKeyword.check_exists?(username)
email = params[:email]&.gsub(/\s+/, "") email = params[:email]&.gsub(/\s+/, "")
phone = params[:phone]&.gsub(/\s+/, "")
password = params[:password] password = params[:password]
platform = (params[:platform] || 'forge')&.gsub(/\s+/, "") platform = (params[:platform] || 'forge')&.gsub(/\s+/, "")
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
result = autologin_register(username, email, password, platform, phone) result = autologin_register(username, email, password, platform)
if result[:message].blank? if result[:message].blank?
render_ok({user: result[:user]}) render_ok({user: result[:user]})
else else
@ -145,8 +142,7 @@ class AccountsController < ApplicationController
user = Users::RegisterService.call(register_params) user = Users::RegisterService.call(register_params)
user.mail = "#{user.login}@example.org" if user.mail.blank? user.mail = "#{user.login}@example.org" if user.mail.blank?
password = decrypt(register_params[:password]) rescue register_params[:password].to_s password = register_params[:password].strip
password = password.strip
# gitea用户注册, email, username, password # gitea用户注册, email, username, password
interactor = Gitea::RegisterInteractor.call({username: user.login, email: user.mail, password: password}) interactor = Gitea::RegisterInteractor.call({username: user.login, email: user.mail, password: password})
@ -164,11 +160,8 @@ class AccountsController < ApplicationController
successful_authentication(user) successful_authentication(user)
render_ok render_ok
end 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 else
tip_exception(-1, interactor.result[:message]) tip_exception(-1, interactor.error)
end end
rescue Register::BaseForm::EmailError => e rescue Register::BaseForm::EmailError => e
render_result(-2, e.message) render_result(-2, e.message)
@ -183,34 +176,28 @@ class AccountsController < ApplicationController
rescue Register::BaseForm::VerifiCodeError => e rescue Register::BaseForm::VerifiCodeError => e
render_result(-6, e.message) render_result(-6, e.message)
rescue Exception => e rescue Exception => e
if user.present? && !e.message.to_s.include?("user already exists") Gitea::User::DeleteService.call(user.login) unless user.nil?
# Gitea::User::DeleteService.call(user.login) uid_logger_error(e.message)
# user.destroy tip_exception(-1, e.message)
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
end end
# 用户登录 # 用户登录
def login def login
password = decrypt(login_params[:password]) rescue login_params[:password].to_s Users::LoginForm.new(login_params).validate!
Users::LoginForm.new(login_params.merge!({password: password})).validate! @user = User.try_to_login(params[:login], params[:password])
@user = User.try_to_login(params[:login], password)
return normal_status(-2, "错误的账号或密码") if @user.blank? return normal_status(-2, "错误的账号或密码") if @user.blank?
# user is already in local database # user is already in local database
return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked? return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked?
login_control = LimitForbidControl::UserLogin.new(@user) login_control = LimitForbidControl::UserLogin.new(@user)
return normal_status(-2, "登录密码出错已达上限,账号已被锁定#{login_control.forbid_expires/60}分钟后重新登录或找回密码") if login_control.forbid? return normal_status(-2, "登录密码出错已达上限,账号已被锁定, #{login_control.forbid_expires/60}分钟后重新登录或找回密码") if login_control.forbid?
password_ok = @user.check_password?(password.to_s) password_ok = @user.check_password?(params[:password].to_s)
unless password_ok unless password_ok
if login_control.remain_times-1 == 0 if login_control.remain_times-1 == 0
normal_status(-2, "登录密码出错已达上限,账号已被锁定#{login_control.forbid_expires/60}分钟后重新登录或找回密码") normal_status(-2, "登录密码出错已达上限,账号已被锁定, #{login_control.forbid_expires/60}分钟后重新登录或找回密码")
else else
normal_status(-2, "你已经输错密码#{login_control.error_times+1}次,还剩余#{login_control.remain_times-1}次机会") normal_status(-2, "你已经输错密码#{login_control.error_times+1}次,还剩余#{login_control.remain_times-1}次机会")
end end
@ -220,24 +207,19 @@ class AccountsController < ApplicationController
LimitForbidControl::UserLogin.new(@user).clear LimitForbidControl::UserLogin.new(@user).clear
successful_authentication(@user) successful_authentication(@user)
sync_pwd_to_gitea!(@user, {password: password.to_s}) # TODO用户密码未同步 sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步
# session[:user_id] = @user.id # session[:user_id] = @user.id
end end
def change_password def change_password
password = decrypt(params[:password]) rescue params[:password].to_s
new_password_repeat = decrypt(params[:new_password_repeat]) rescue params[:new_password_repeat].to_s
old_password = decrypt(params[:old_password]) rescue params[:old_password]
return render_error("两次输入的密码不一致") if password.to_s != new_password_repeat.to_s
@user = User.find_by(login: params[:login]) @user = User.find_by(login: params[:login])
return render_forbidden unless User.current.login == @user&.login
return render_error("此用户禁止修改密码!") if @user.id.to_i === 104691 return render_error("此用户禁止修改密码!") if @user.id.to_i === 104691
return render_error("未找到相关用户!") if @user.blank? return render_error("未找到相关用户!") if @user.blank?
return render_error("旧密码不正确") unless @user.check_password?(old_password) return render_error("旧密码不正确") unless @user.check_password?(params[:old_password])
sync_params = { sync_params = {
password: password.to_s, password: params[:password].to_s,
email: @user.mail, email: @user.mail,
login_name: @user.name, login_name: @user.name,
source_id: 0 source_id: 0
@ -245,7 +227,7 @@ class AccountsController < ApplicationController
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params) interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
if interactor.success? if interactor.success?
@user.update_attribute(:password, password) @user.update_attribute(:password, params[:password])
render_ok render_ok
else else
render_error(interactor.error) render_error(interactor.error)
@ -368,17 +350,6 @@ class AccountsController < ApplicationController
Register::LoginCheckColumnsForm.new(check_params.merge(user: current_user)).validate! Register::LoginCheckColumnsForm.new(check_params.merge(user: current_user)).validate!
render_ok render_ok
end 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 private

View File

@ -1,75 +0,0 @@
class Action::NodeInputsController < ApplicationController
before_action :require_admin, except: [:index]
before_action :find_action_node
def index
@node_inputs = @node.action_node_inputs
respond_to do |format|
format.html
format.json{ render_ok(data: @node_inputs.as_json) }
end
end
def create
@node_input = Action::NodeInput.new(node_input_params)
@node_input.action_node = @node
respond_to do |format|
if @node_input.save
format.html { redirect_to action_node_node_inputs_path(@node), notice: '创建成功.' }
format.json { render_ok(data: @node_input.as_json) }
else
format.html { render :new }
format.json { render json: @node_input.errors, status: -1 }
end
end
end
def new
end
def show
end
def edit
end
def update
@node_input.update(node_input_params)
respond_to do |format|
format.html { redirect_to action_node_node_inputs_path(@node), notice: '更新成功.' }
format.json { render_ok(data: @node_input.as_json) }
end
end
def destroy
if @node_input.destroy!
flash[:success] = '删除成功'
else
flash[:danger] = '删除失败'
end
redirect_to "api/actions/nodes"
end
private
def find_action_node
@node = Action::Node.find(params[:node_id])
if params[:id].present?
@node_input = @node.action_node_inputs.find(params[:id])
else
@node_input = Action::NodeInput.new
end
end
def node_input_params
if params.require(:action_node_input)
params.require(:action_node_input).permit(:name, :input_type, :description, :is_required, :sort_no, :default_value)
else
params.permit(:name, :input_type, :description, :is_required, :sort_no, :default_value)
end
end
end

View File

@ -1,76 +0,0 @@
class Action::NodeSelectsController < ApplicationController
before_action :require_admin, except: [:index]
before_action :find_action_node
def index
@node_selects = @node.action_node_selects
respond_to do |format|
format.html
format.json
end
end
def create
@node_select = Action::NodeSelect.new(node_select_params)
@node_select.action_node = @node
respond_to do |format|
if @node_select.save
format.html { redirect_to action_node_node_selects_path(@node), notice: '创建成功.' }
format.json { render_ok(data: @node_select.as_json) }
else
format.html { render :new }
format.json { render json: @node_select.errors, status: -1 }
end
end
end
def new
end
def show
end
def edit
end
def update
@node_select.update(node_select_params)
respond_to do |format|
format.html { redirect_to action_node_node_selects_path(@node), notice: '更新成功.' }
format.json { render_ok(data: @node_select.as_json) }
end
end
def destroy
if @node_select.destroy!
flash[:success] = '删除成功'
else
flash[:danger] = '删除失败'
end
redirect_to "api/actions/nodes"
end
private
def find_action_node
@node = Action::Node.find(params[:node_id])
if params[:id].present?
@node_select = @node.action_node_selects.find(params[:id])
else
@node_select = Action::NodeSelect.new
end
end
def node_select_params
if params.require(:action_node_select)
params.require(:action_node_select).permit(:name, :val, :val_ext, :description, :sort_no)
else
params.permit(:name, :val, :val_ext, :description, :sort_no)
end
end
end

View File

@ -1,74 +0,0 @@
class Action::NodeTypesController < ApplicationController
before_action :require_admin, except: [:index]
before_action :find_node_type, except: [:index, :create, :new]
def index
@node_types = Action::NodeType.all
respond_to do |format|
format.html
format.json { render_ok(data: @node_types.as_json) }
end
end
def create
@node_type = Action::NodeType.new(node_types_params)
respond_to do |format|
if @node_type.save
format.html { redirect_to action_node_types_path, notice: '创建成功.' }
format.json { render_ok(data: @node_type.as_json) }
else
format.html { render :new }
format.json { render json: @node_type.errors, status: -1 }
end
end
end
def show
respond_to do |format|
format.html
format.json { render_ok(data: @node_type.as_json) }
end
end
def new
@node_type = Action::NodeType.new
end
def edit
end
def update
@node_type.update(node_types_params)
respond_to do |format|
format.html { redirect_to action_node_types_path, notice: '更新成功.' }
format.json { render_ok(data: @node_type.as_json) }
end
end
def destroy
if @node_type.destroy!
flash[:success] = '删除成功'
else
flash[:danger] = '删除失败'
end
respond_to do |format|
format.html { redirect_to action_node_types_path }
format.json { render_ok }
end
end
private
def find_node_type
@node_type = Action::NodeType.find(params[:id])
end
def node_types_params
if params.require(:action_node_type)
params.require(:action_node_type).permit(:name, :description, :sort_no)
else
params.permit(:name, :description, :sort_no)
end
end
end

View File

@ -1,87 +0,0 @@
class Action::NodesController < ApplicationController
# before_action :require_admin, except: [:index]
before_action :require_login
before_action :find_action_node, except: [:index, :create, :new]
def index
@node_types = Action::NodeType.all
no_node_type = Action::NodeType.find_by(name: "未分类")
@no_type_nodes = Action::Node.where(action_node_types_id: nil)
@no_type_nodes = Action::Node.where(action_node_types_id: nil).or(Action::Node.where(action_node_types_id: no_node_type.id)) if no_node_type.present?
respond_to do |format|
format.html { @nodes = Action::Node.where("name LIKE :search OR full_name LIKE :search", :search => "%#{params[:search]}%") }
format.json
end
end
def create
@node = Action::Node.new(node_params)
if params.require(:node).present? && params.require(:node)[:link_type_array].present?
@node.link_type = (params.require(:node)[:link_type_array] - [""]).join(",")
end
@node.user_id = current_user.id
respond_to do |format|
if @node.save
format.html { redirect_to action_nodes_path, notice: '创建成功.' }
format.json { render_ok(data: @node.as_json) }
else
format.html { render :new }
format.json { render json: @node.errors, status: -1 }
end
end
end
def new
@node = Action::Node.new
end
def show
end
def edit
if @node.link_type.present?
@node.link_type_array = @node.link_type.to_s.split(",")
end
end
def update
if params.require(:node).present? && params.require(:node)[:link_type_array].present?
@node.link_type = (params.require(:node)[:link_type_array] - [""]).join(",")
end
@node.user_id = current_user.id if @node.user_id.blank?
@node.update(node_params)
respond_to do |format|
format.html { redirect_to action_nodes_path, notice: '更新成功.' }
format.json { render_ok(data: @node.as_json) }
end
end
def destroy
if @node.destroy!
flash[:success] = '删除成功'
else
flash[:danger] = '删除失败'
end
respond_to do |format|
format.html { redirect_to action_nodes_path }
format.json { render_ok() }
end
end
private
def find_action_node
@node = Action::Node.find(params[:id])
end
def node_params
if params.require(:action_node)
params.require(:action_node).permit(:name, :label, :full_name, :description, :icon, :action_node_types_id,
:is_local, :local_url, :yaml, :sort_no, :node_type, :is_mutil_link, :link_type, :link_type_array)
else
params.permit(:name, :label, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url,
:yaml, :sort_no, :node_type, :is_mutil_link, :link_type, :link_type_array)
end
end
end

View File

@ -1,71 +0,0 @@
class Action::TemplatesController < ApplicationController
before_action :require_admin, except: [:index]
before_action :find_action_template, except: [:index, :create, :new]
def index
@templates = Action::Template.all
respond_to do |format|
format.html
format.json
end
end
def create
@template = Action::Template.new(templates_params)
respond_to do |format|
if @template.save
format.html { redirect_to action_templates_path, notice: '创建成功.' }
format.json { render_ok(data: @template.as_json) }
else
format.html { render :new }
format.json { render json: @template.errors, status: -1 }
end
end
end
def show
end
def new
@template = Action::Template.new
end
def edit
end
def update
@template.update(templates_params)
respond_to do |format|
format.html { redirect_to action_templates_path, notice: '更新成功.' }
format.json { render_ok(data: @template.as_json) }
end
end
def destroy
if @template.destroy!
flash[:success] = '删除成功'
else
flash[:danger] = '删除失败'
end
respond_to do |format|
format.html { redirect_to action_templates_path }
format.json { render_ok }
end
end
private
def find_action_template
@template = Action::Template.find(params[:id])
end
def templates_params
if params.require(:action_template)
params.require(:action_template).permit(:name, :description, :img, :sort_no, :json, :yaml)
else
params.permit(:name, :description, :img, :sort_no, :json, :yaml)
end
end
end

View File

@ -23,23 +23,10 @@ class Admins::BaseController < ApplicationController
def require_admin! def require_admin!
return if current_user.blank? || !current_user.logged? return if current_user.blank? || !current_user.logged?
return if current_user.admin_or_business? return if current_user.admin_or_business?
return if current_user.admin_or_glcc_admin?
render_forbidden render_forbidden
end end
def require_admin
render_forbidden unless User.current.admin?
end
def require_business
render_forbidden unless admin_or_business?
end
def require_glcc_admin
render_forbidden unless admin_or_glcc_admin?
end
# 触发after ajax render partial hooks执行一些因为局部刷新后失效的绑定事件 # 触发after ajax render partial hooks执行一些因为局部刷新后失效的绑定事件
def rebind_event_if_ajax_render_partial def rebind_event_if_ajax_render_partial
return if request.format.symbol != :js return if request.format.symbol != :js

View File

@ -1,13 +1,9 @@
class Admins::DashboardsController < Admins::BaseController class Admins::DashboardsController < Admins::BaseController
def index def index
# 查询优化
week_greater_id = CommitLog.where(created_at: current_week).limit(1)[0]&.id
#月份统计还需要优化
month_greater_id = CommitLog.where(created_at: current_month).limit(1)[0]&.id
# 用户活跃数 # 用户活跃数
day_user_ids = CommitLog.where(created_at: today).pluck(:user_id).uniq day_user_ids = CommitLog.where(created_at: today).pluck(:user_id).uniq
weekly_user_ids = CommitLog.where(created_at: current_week).where("id>= ?", week_greater_id).distinct.pluck(:user_id) weekly_user_ids = CommitLog.where(created_at: current_week).pluck(:user_id).uniq
month_user_ids = CommitLog.where(created_at: current_month).where("id>= ?", month_greater_id).distinct.pluck(:user_id) month_user_ids = CommitLog.where(created_at: current_month).pluck(:user_id).uniq
@active_user_count = User.where(last_login_on: today).or(User.where(id: day_user_ids)).count @active_user_count = User.where(last_login_on: today).or(User.where(id: day_user_ids)).count
@weekly_active_user_count = User.where(last_login_on: current_week).or(User.where(id: weekly_user_ids)).count @weekly_active_user_count = User.where(last_login_on: current_week).or(User.where(id: weekly_user_ids)).count
@month_active_user_count = User.where(last_login_on: current_month).or(User.where(id: month_user_ids)).count @month_active_user_count = User.where(last_login_on: current_month).or(User.where(id: month_user_ids)).count
@ -22,78 +18,16 @@ class Admins::DashboardsController < Admins::BaseController
# 活跃项目数 # 活跃项目数
day_project_ids = (CommitLog.where(created_at: today).pluck(:project_id).uniq + Issue.where(created_on: today).pluck(:project_id).uniq).uniq day_project_ids = (CommitLog.where(created_at: today).pluck(:project_id).uniq + Issue.where(created_on: today).pluck(:project_id).uniq).uniq
weekly_project_ids = (CommitLog.where(created_at: current_week).where("id>= ?", week_greater_id).distinct.pluck(:project_id) + Issue.where(created_on: current_week).pluck(:project_id).uniq).uniq weekly_project_ids = (CommitLog.where(created_at: current_week).pluck(:project_id).uniq + Issue.where(created_on: current_week).pluck(:project_id).uniq).uniq
month_project_ids = (CommitLog.where(created_at: current_month).where("id>= ?", month_greater_id).distinct.pluck(:project_id) + Issue.where(created_on: current_month).pluck(:project_id).uniq).uniq month_project_ids = (CommitLog.where(created_at: current_month).pluck(:project_id).uniq + Issue.where(created_on: current_month).pluck(:project_id).uniq).uniq
@day_active_project_count = Project.where(updated_on: today).or(Project.where(id: day_project_ids)).count @day_active_project_count = Project.where(updated_on: today).or(Project.where(id: day_project_ids)).count
@weekly_active_project_count = Rails.cache.fetch("dashboardscontroller:weekly_active_project_count", expires_in: 10.minutes) do @weekly_active_project_count = Project.where(updated_on: current_week).or(Project.where(id: weekly_project_ids)).count
Project.where(updated_on: current_week).or(Project.where(id: weekly_project_ids)).count @month_active_project_count = Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count
end
@month_active_project_count = Rails.cache.fetch("dashboardscontroller:month_active_project_count", expires_in: 1.hours) do
Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count
end
# 新增项目数 # 新增项目数
@day_new_project_count = Rails.cache.fetch("dashboardscontroller:day_new_project_count", expires_in: 10.minutes) do @day_new_project_count = Project.where(created_on: today).count
Project.where(created_on: today).count @weekly_new_project_count = Project.where(created_on: current_week).count
end @month_new_project_count = Project.where(created_on: current_month).count
@weekly_new_project_count = Rails.cache.fetch("dashboardscontroller:weekly_new_project_count", expires_in: 10.minutes) do
Project.where(created_on: current_week).count
end
@month_new_project_count = Rails.cache.fetch("dashboardscontroller:month_new_project_count", expires_in: 1.hours) do
Project.where(created_on: current_month).count
end
# 总的平台用户数
# 总的平台项目数
# 总的平台组织数
# 总的平台Issue数、评论数、PR数、Commit数
@user_count = Rails.cache.fetch("dashboardscontroller:platform:user_count", expires_in: 1.days) do
User.count
end
@project_count = Rails.cache.fetch("dashboardscontroller:platform:project_count", expires_in: 1.days) do
Project.count
end
@organization_count = Rails.cache.fetch("dashboardscontroller:platform:organization_count", expires_in: 1.days) do
Organization.count
end
@issue_count = Rails.cache.fetch("dashboardscontroller:platform:issue_count", expires_in: 1.days) do
Issue.count
end
@comment_count = Rails.cache.fetch("dashboardscontroller:platform:comment_count", expires_in: 1.days) do
Journal.count
end
@pr_count = Rails.cache.fetch("dashboardscontroller:platform:pr_count", expires_in: 1.days) do
PullRequest.count
end
@commit_count = Rails.cache.fetch("dashboardscontroller:platform:commit_count", expires_in: 1.days) do
CommitLog.count
end
@subject_name = ["用户数", "项目数", "组织数", "Issue数", "Issue评论数", "PR数", "Commit数"]
@subject_icon = ["fa-user","fa-git", "fa-sitemap", "fa-warning", "fa-comments", "fa-share-alt", "fa-upload"]
@subject_data = [@user_count, @project_count, @organization_count, @issue_count, @comment_count, @pr_count, @commit_count]
if EduSetting.get("open_baidu_tongji").to_s == "true"
tongji_service = Baidu::TongjiService.new
@access_token = tongji_service.access_token
Rails.logger.info "baidu_tongji_auth access_token ===== #{@access_token}"
# @overview_data = tongji_service.api_overview
last_date = DailyPlatformStatistic.order(:date).last || Time.now
start_date = last_date.date
end_date = Time.now
if @access_token.present?
@overview_data = Rails.cache.fetch("dashboardscontroller:baidu_tongji:overview_data", expires_in: 10.minutes) do
tongji_service.source_from_batch_add(start_date, end_date)
@overview_data = tongji_service.overview_batch_add(start_date, end_date)
@overview_data
end
end
@current_week_statistic = DailyPlatformStatistic.where(date: current_week)
@pre_week_statistic = DailyPlatformStatistic.where(date: pre_week)
end
end end
def month_active_user def month_active_user
@ -108,19 +42,6 @@ class Admins::DashboardsController < Admins::BaseController
render_ok(data: data) render_ok(data: data)
end end
def baidu_tongji
tongji_service = Baidu::TongjiService.new
redirect_to tongji_service.code_url
end
def baidu_tongji_auth
if params[:code].present?
tongji_service = Baidu::TongjiService.new
tongji_service.get_access_token(params[:code])
end
redirect_to "/admins/"
end
def evaluate def evaluate
names = [] names = []
data = [] data = []
@ -142,12 +63,8 @@ class Admins::DashboardsController < Admins::BaseController
Time.now.beginning_of_day..Time.now.end_of_day Time.now.beginning_of_day..Time.now.end_of_day
end end
def pre_7_days
7.days.ago.end_of_day..Time.now.end_of_day
end
def current_week def current_week
Time.now.beginning_of_week..Time.now.end_of_day 7.days.ago.end_of_day..Time.now.end_of_day
end end
def current_month def current_month
@ -155,7 +72,6 @@ class Admins::DashboardsController < Admins::BaseController
end end
def pre_week def pre_week
# 14.days.ago.end_of_day..7.days.ago.end_of_day 14.days.ago.end_of_day..7.days.ago.end_of_day
Time.now.prev_week..Time.now.prev_week.end_of_week
end end
end end

View File

@ -1,5 +1,4 @@
class Admins::EduSettingsController < Admins::BaseController class Admins::EduSettingsController < Admins::BaseController
before_action :require_admin
before_action :find_setting, only: [:edit,:update, :destroy] before_action :find_setting, only: [:edit,:update, :destroy]
def index def index

View File

@ -1,5 +1,4 @@
class Admins::FaqsController < Admins::BaseController class Admins::FaqsController < Admins::BaseController
before_action :require_business
before_action :find_faq, only: [:edit,:update, :destroy] before_action :find_faq, only: [:edit,:update, :destroy]
def index def index

View File

@ -1,5 +1,4 @@
class Admins::FeedbacksController < Admins::BaseController class Admins::FeedbacksController < Admins::BaseController
before_action :require_business
before_action :get_feedback, only: [:new_history, :create_history, :destroy] before_action :get_feedback, only: [:new_history, :create_history, :destroy]
def index def index

View File

@ -1,34 +0,0 @@
class Admins::GlccPrCheckController < Admins::BaseController
before_action :require_glcc_admin
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

View File

@ -1,38 +0,0 @@
class Admins::IdentityVerificationsController < Admins::BaseController
before_action :require_business
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 update_params[:state] == "已拒绝" && update_params[:description].blank?
flash[:danger] = '拒绝理由不能为空'
render 'edit'
else
UserAction.create(action_id: @identity_verification.id, action_type: "UpdateIdentityVerifications", user_id: current_user.id, :ip => request.remote_ip, data_bank: @identity_verification.attributes.to_json)
@identity_verification.update(update_params)
redirect_to admins_identity_verifications_path
flash[:success] = "更新成功"
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

View File

@ -1,30 +0,0 @@
class Admins::IssuesRankController < Admins::BaseController
before_action :require_admin
def index
@statistics = DailyProjectStatistic.where('date >= ? AND date <= ?', begin_date, end_date)
@statistics = @statistics.group(:project_id).joins(:project).select("project_id,
sum(issues) as issues,
sum(closed_issues) as closed_issues,
projects.issues_count as issues_count")
@statistics = @statistics.order("#{sort_by} #{sort_direction}").limit(50)
end
private
def begin_date
params.fetch(:begin_date, (Date.yesterday-7.days).to_s)
end
def end_date
params.fetch(:end_date, Date.yesterday.to_s)
end
def sort_by
DailyProjectStatistic.column_names.include?(params.fetch(:sort_by, "issues")) ? params.fetch(:sort_by, "issues") : "issues"
end
def sort_direction
%w(desc asc).include?(params.fetch(:sort_direction, "desc")) ? params.fetch(:sort_direction, "desc") : "desc"
end
end

View File

@ -1,5 +1,4 @@
class Admins::LaboratoriesController < Admins::BaseController class Admins::LaboratoriesController < Admins::BaseController
before_action :require_admin
def index def index
default_sort('id', 'desc') default_sort('id', 'desc')

View File

@ -25,6 +25,6 @@ class Admins::LaboratorySettingsController < Admins::BaseController
params.permit(:identifier, :name, params.permit(:identifier, :name,
:nav_logo, :login_logo, :tab_logo, :oj_banner, :nav_logo, :login_logo, :tab_logo, :oj_banner,
:subject_banner, :course_banner, :competition_banner, :moop_cases_banner, :subject_banner, :course_banner, :competition_banner, :moop_cases_banner,
:footer, navbar: %i[name link hidden index]) :footer, navbar: %i[name link hidden])
end end
end end

View File

@ -1,5 +1,4 @@
class Admins::MessageTemplatesController < Admins::BaseController class Admins::MessageTemplatesController < Admins::BaseController
before_action :require_admin
before_action :get_template, only: [:edit, :update, :destroy] before_action :get_template, only: [:edit, :update, :destroy]
def index def index
@ -8,12 +7,12 @@ class Admins::MessageTemplatesController < Admins::BaseController
end end
def new def new
@message_template = MessageTemplate::CustomTip.new @message_template = MessageTemplate.new
end end
def create def create
@message_template = MessageTemplate::CustomTip.new @message_template = MessageTemplate::CustomTip.new(message_template_params)
@message_template.attributes = message_template_params @message_template.type = "MessageTemplate::CustomTip"
if @message_template.save! if @message_template.save!
redirect_to admins_message_templates_path redirect_to admins_message_templates_path
flash[:success] = "创建消息模板成功" flash[:success] = "创建消息模板成功"
@ -48,7 +47,9 @@ class Admins::MessageTemplatesController < Admins::BaseController
private private
def message_template_params def message_template_params
params.require(@message_template.type.split("::").join("_").underscore.to_sym).permit! # type = @message_template.present? ? @message_template.type : "MessageTemplate::CustomTip"
# params.require(type.split("::").join("_").underscore.to_sym).permit!
params.require(:message_template).permit!
end end
def get_template def get_template

View File

@ -1,8 +1,7 @@
class Admins::NpsController < Admins::BaseController class Admins::NpsController < Admins::BaseController
before_action :require_business
def index def index
@on_off_switch = EduSetting.get("nps-on-off-switch").to_s == 'true' @on_off_switch = EduSetting.get("nps-on-off-switch").to_s == 'true'
@user_nps = UserNp.order(created_at: :desc) @user_nps = UserNp.joins(:user).order(created_at: :desc)
keyword = params[:keyword].to_s.strip.presence keyword = params[:keyword].to_s.strip.presence
if keyword if keyword
sql = 'CONCAT(users.lastname, users.firstname) LIKE :keyword OR users.nickname LIKE :keyword OR users.login LIKE :keyword OR users.mail LIKE :keyword OR users.phone LIKE :keyword' sql = 'CONCAT(users.lastname, users.firstname) LIKE :keyword OR users.nickname LIKE :keyword OR users.login LIKE :keyword OR users.mail LIKE :keyword OR users.phone LIKE :keyword'

View File

@ -1,6 +1,5 @@
class Admins::OrganizationsController < Admins::BaseController class Admins::OrganizationsController < Admins::BaseController
before_action :require_admin before_action :finder_org, except: [:index]
before_action :finder_org, except: [:index]
def index def index
params[:sort_by] = params[:sort_by].presence || 'created_on' params[:sort_by] = params[:sort_by].presence || 'created_on'
@ -10,29 +9,12 @@ class Admins::OrganizationsController < Admins::BaseController
@orgs = paginate orgs @orgs = paginate orgs
end 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 def show
end end
def destroy def destroy
@org.destroy! @org.destroy!
Admins::DeleteOrganizationService.call(@org.login) 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 render_delete_success
end end

View File

@ -1,80 +0,0 @@
class Admins::PageThemesController < Admins::BaseController
before_action :require_admin
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

View File

@ -1,5 +1,4 @@
class Admins::ProjectCategoriesController < Admins::BaseController class Admins::ProjectCategoriesController < Admins::BaseController
before_action :require_admin
before_action :get_category, only: [:edit,:update, :destroy] before_action :get_category, only: [:edit,:update, :destroy]
before_action :validate_names, only: [:create, :update] before_action :validate_names, only: [:create, :update]

View File

@ -1,5 +1,4 @@
class Admins::ProjectIgnoresController < Admins::BaseController class Admins::ProjectIgnoresController < Admins::BaseController
before_action :require_admin
before_action :set_ignore, only: [:edit,:update, :destroy,:show] before_action :set_ignore, only: [:edit,:update, :destroy,:show]
# before_action :validate_params, only: [:create, :update] # before_action :validate_params, only: [:create, :update]

View File

@ -1,5 +1,4 @@
class Admins::ProjectLanguagesController < Admins::BaseController class Admins::ProjectLanguagesController < Admins::BaseController
before_action :require_admin
before_action :get_language, only: [:edit,:update, :destroy] before_action :get_language, only: [:edit,:update, :destroy]
before_action :validate_names, only: [:create, :update] before_action :validate_names, only: [:create, :update]

View File

@ -1,5 +1,4 @@
class Admins::ProjectLicensesController < Admins::BaseController class Admins::ProjectLicensesController < Admins::BaseController
before_action :require_admin
before_action :set_license, only: [:edit,:update, :destroy,:show] before_action :set_license, only: [:edit,:update, :destroy,:show]
# before_action :validate_params, only: [:create, :update] # before_action :validate_params, only: [:create, :update]
@ -7,7 +6,7 @@ class Admins::ProjectLicensesController < Admins::BaseController
sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc' sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
q = License.ransack(name_cont: params[:search]) q = License.ransack(name_cont: params[:search])
project_licenses = q.result(distinct: true).reorder("#{sort_by} #{sort_direction}") project_licenses = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
@project_licenses = paginate(project_licenses) @project_licenses = paginate(project_licenses)
end end
@ -96,7 +95,7 @@ class Admins::ProjectLicensesController < Admins::BaseController
end end
def license_params def license_params
params.require(:license).permit(:name,:content,:position) params.require(:license).permit(:name,:content)
end end
# def validate_params # def validate_params

View File

@ -1,22 +1,11 @@
class Admins::ProjectsController < Admins::BaseController class Admins::ProjectsController < Admins::BaseController
before_action :require_admin
before_action :find_project, only: [:edit, :update] before_action :find_project, only: [:edit, :update]
def index def index
sort_by = Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_on' sort_by = Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_on'
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc' sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
search = params[:search].to_s.strip search = params[:search].to_s.strip
projects = Project.where("id = ? OR name like ? OR identifier LIKE ?", search, "%#{search}%", "%#{search}%").order("#{sort_by} #{sort_direction}") projects = Project.where("name like ?", "%#{search}%").order("#{sort_by} #{sort_direction}")
case params[:category]
when 'public'
projects = projects.where(is_public: true)
when 'private'
projects = projects.where(is_public: false)
when 'fork'
projects = projects.where.not(forked_from_project_id: nil)
when 'original'
projects = projects.where(forked_from_project_id: nil, project_type: 'common')
end
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score) @projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
end end
@ -43,14 +32,9 @@ class Admins::ProjectsController < Admins::BaseController
def destroy def destroy
project = Project.find_by!(id: params[:id]) project = Project.find_by!(id: params[:id])
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
close_fork_pull_requests_by(project) Gitea::Repository::DeleteService.new(project.owner, project.identifier).call
Gitea::Repository::DeleteService.new(project.owner, project.identifier, current_user.gitea_token).call
project.destroy! project.destroy!
project.forked_projects.update_all(forked_from_project_id: nil)
# 如果该项目有所属的项目分类以及为私有项目,需要更新对应数量
project.project_category.decrement!(:private_projects_count, 1) if project.project_category.present? && !project.is_public
# render_delete_success # 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 redirect_to admins_projects_path
flash[:success] = "删除成功" flash[:success] = "删除成功"
end end
@ -67,19 +51,4 @@ class Admins::ProjectsController < Admins::BaseController
def project_update_params def project_update_params
params.require(:project).permit(:is_pinned, :recommend, :recommend_index) params.require(:project).permit(:is_pinned, :recommend, :recommend_index)
end end
def close_fork_pull_requests_by(project)
open_pull_requests = PullRequest.where(fork_project_id: project.id)
if open_pull_requests.present?
open_pull_requests.each do |pull_request|
closed = PullRequests::CloseService.call(pull_request&.project.owner, pull_request&.project.repository, pull_request, current_user)
if closed === true
pull_request.project_trends.create!(user: current_user, project: pull_request&.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 end

View File

@ -1,60 +1,16 @@
class Admins::ProjectsRankController < Admins::BaseController class Admins::ProjectsRankController < Admins::BaseController
before_action :require_admin
def index def index
@statistics = DailyProjectStatistic.where("date >= ? AND date <= ?", begin_date, end_date) @rank_date = rank_date
@statistics = @statistics.group(:project_id).select("project_id, deleted_data = $redis_cache.smembers("v2-project-rank-deleted")
sum(score) as score, $redis_cache.zrem("v2-project-rank-#{rank_date}", deleted_data) unless deleted_data.blank?
sum(visits) as visits, @date_rank = $redis_cache.zrevrange("v2-project-rank-#{rank_date}", 0, -1, withscores: true)
sum(watchers) as watchers,
sum(praises) as praises,
sum(forks) as forks,
sum(issues) as issues,
sum(pullrequests) as pullrequests,
sum(commits) as commits").includes(:project)
@statistics = paginate @statistics.order("#{sort_by} #{sort_direction}")
export_excel(@statistics.limit(50))
end end
private private
def begin_date def rank_date
params.fetch(:begin_date, (Date.yesterday-7.days).to_s) params.fetch(:date, Date.today.to_s)
end
def end_date
params.fetch(:end_date, Date.yesterday.to_s)
end
def sort_by
DailyProjectStatistic.column_names.include?(params.fetch(:sort_by, "score")) ? params.fetch(:sort_by, "score") : "score"
end
def sort_direction
%w(desc asc).include?(params.fetch(:sort_direction, "desc")) ? params.fetch(:sort_direction, "desc") : "desc"
end
def export_excel(data)
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet :name => "项目活跃度排行"
sheet.row(0).concat %w(排名 项目全称 项目地址 项目分类 首次创建时间 外部迁移/独立创建 得分 访问数 关注数 点赞数 fork数 疑修数 合并请求数 提交数)
data.each_with_index do |d, index|
sheet[index+1,0] = index+1
sheet[index+1,1] = "#{d&.project&.owner&.real_name}/#{d&.project&.name}"
sheet[index+1,2] = "#{Rails.application.config_for(:configuration)['platform_url']}/#{d&.project&.owner&.login}/#{d&.project&.identifier}"
sheet[index+1,3] = d&.project&.project_category&.name
sheet[index+1,4] = d&.project&.created_on.present? ? d&.project&.created_on.strftime("%Y-%m-%d %H:%M:%S") : ""
sheet[index+1,5] = d&.project&.common? ? "独立创建" : "外部迁移"
sheet[index+1,6] = d.score
sheet[index+1,7] = d.visits
sheet[index+1,8] = d.watchers
sheet[index+1,9] = d.praises
sheet[index+1,10] = d.forks
sheet[index+1,11] = d.issues
sheet[index+1,12] = d.pullrequests
sheet[index+1,13] = d.commits
end
book.write "#{Rails.root}/public/项目活跃度排行.xls"
end end
end end

View File

@ -1,5 +1,4 @@
class Admins::ReversedKeywordsController < Admins::BaseController class Admins::ReversedKeywordsController < Admins::BaseController
before_action :require_admin
before_action :get_keyword, only: [:edit,:update, :destroy] before_action :get_keyword, only: [:edit,:update, :destroy]
# before_action :validate_identifer, only: [:create, :update] # before_action :validate_identifer, only: [:create, :update]

View File

@ -1,51 +0,0 @@
class Admins::SitePagesController < Admins::BaseController
before_action :require_admin
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
if update_params[:state] == "false" && update_params[:state_description].blank?
flash[:danger] = '关闭站点理由不能为空'
else
@site_page.update(update_params)
flash[:success] = '保存成功'
end
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

View File

@ -1,5 +1,4 @@
class Admins::SitesController < Admins::BaseController class Admins::SitesController < Admins::BaseController
before_action :require_admin
before_action :find_site, only: [:edit,:update, :destroy] before_action :find_site, only: [:edit,:update, :destroy]
def index def index

View File

@ -1,5 +1,4 @@
class Admins::SystemNotificationsController < Admins::BaseController class Admins::SystemNotificationsController < Admins::BaseController
before_action :require_business
before_action :get_notification, only: [:history, :edit,:update, :destroy] before_action :get_notification, only: [:history, :edit,:update, :destroy]
# before_action :validate_identifer, only: [:create, :update] # before_action :validate_identifer, only: [:create, :update]
@ -26,7 +25,7 @@ class Admins::SystemNotificationsController < Admins::BaseController
@notification = SystemNotification.new(notification_params) @notification = SystemNotification.new(notification_params)
if @notification.save if @notification.save
redirect_to admins_system_notifications_path redirect_to admins_system_notifications_path
flash[:success] = '系统公告创建成功' flash[:success] = '系统消息创建成功'
else else
redirect_to admins_system_notifications_path redirect_to admins_system_notifications_path
flash[:danger] = @notification.errors.full_messages.join(",") flash[:danger] = @notification.errors.full_messages.join(",")
@ -38,7 +37,7 @@ class Admins::SystemNotificationsController < Admins::BaseController
if @notification.update_attributes(notification_params) if @notification.update_attributes(notification_params)
format.html do format.html do
redirect_to admins_system_notifications_path redirect_to admins_system_notifications_path
flash[:success] = '系统公告更新成功' flash[:success] = '系统消息更新成功'
end end
format.js {render_ok} format.js {render_ok}
else else
@ -54,10 +53,10 @@ class Admins::SystemNotificationsController < Admins::BaseController
def destroy def destroy
if @notification.destroy if @notification.destroy
redirect_to admins_system_notifications_path redirect_to admins_system_notifications_path
flash[:success] = "系统公告删除成功" flash[:success] = "系统消息删除成功"
else else
redirect_to admins_system_notifications_path redirect_to admins_system_notifications_path
flash[:danger] = "系统公告删除失败" flash[:danger] = "系统消息删除失败"
end end
end end

View File

@ -1,5 +1,4 @@
class Admins::Topic::ActivityForumsController < Admins::Topic::BaseController class Admins::Topic::ActivityForumsController < Admins::Topic::BaseController
before_action :require_business
before_action :find_activity_forum, only: [:edit, :update, :destroy] before_action :find_activity_forum, only: [:edit, :update, :destroy]
def index def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::BannersController < Admins::Topic::BaseController class Admins::Topic::BannersController < Admins::Topic::BaseController
before_action :require_business
before_action :find_banner, only: [:edit, :update, :destroy] before_action :find_banner, only: [:edit, :update, :destroy]
def index def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::CardsController < Admins::Topic::BaseController class Admins::Topic::CardsController < Admins::Topic::BaseController
before_action :require_business
before_action :find_card, only: [:edit, :update, :destroy] before_action :find_card, only: [:edit, :update, :destroy]
def index def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::CooperatorsController < Admins::Topic::BaseController class Admins::Topic::CooperatorsController < Admins::Topic::BaseController
before_action :require_business
before_action :find_cooperator, only: [:edit, :update, :destroy] before_action :find_cooperator, only: [:edit, :update, :destroy]
def index def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::ExcellentProjectsController < Admins::Topic::BaseController class Admins::Topic::ExcellentProjectsController < Admins::Topic::BaseController
before_action :require_business
before_action :find_excellent_project, only: [:edit, :update, :destroy] before_action :find_excellent_project, only: [:edit, :update, :destroy]
def index def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::ExperienceForumsController < Admins::Topic::BaseController class Admins::Topic::ExperienceForumsController < Admins::Topic::BaseController
before_action :require_business
before_action :find_experience_forum, only: [:edit, :update, :destroy] before_action :find_experience_forum, only: [:edit, :update, :destroy]
def index def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::GlccNewsController < Admins::Topic::BaseController class Admins::Topic::GlccNewsController < Admins::Topic::BaseController
before_action :require_glcc_admin
before_action :find_glcc, only: [:edit, :update, :destroy] before_action :find_glcc, only: [:edit, :update, :destroy]
def index def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::PinnedForumsController < Admins::Topic::BaseController class Admins::Topic::PinnedForumsController < Admins::Topic::BaseController
before_action :require_business
before_action :find_pinned_forum, only: [:edit, :update, :destroy] before_action :find_pinned_forum, only: [:edit, :update, :destroy]
def index def index

View File

@ -1,14 +0,0 @@
class Admins::UserActionsController < Admins::BaseController
before_action :require_admin
def index
@user_actions = UserAction.order(created_at: :desc)
@user_actions = @user_actions.where(action_type: params[:action_type]) if params[:action_type].present?
keyword = params[:keyword].to_s.strip.presence
if keyword
sql = 'login LIKE :keyword OR phone LIKE :keyword OR email LIKE :keyword'
@user_actions = @user_actions.where(sql, keyword: "%#{keyword}%")
end
@user_actions = paginate @user_actions
end
end

View File

@ -1,6 +1,5 @@
class Admins::UsersController < Admins::BaseController class Admins::UsersController < Admins::BaseController
before_action :require_admin before_action :finder_user, except: [:index]
before_action :finder_user, except: [:index]
def index def index
params[:sort_by] = params[:sort_by].presence || 'created_on' params[:sort_by] = params[:sort_by].presence || 'created_on'
@ -26,36 +25,15 @@ class Admins::UsersController < Admins::BaseController
end end
def destroy 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!
# org_ids = TeamUser.where(user_id: @user.id).pluck(:organization_id) | OrganizationUser.where(user_id: @user.id).pluck(:organization_id) Gitea::User::DeleteService.call(@user.login)
# organizations = Organization.where(id: org_ids)
# organizations.each do |org|
# # org.team_users.joins(:team).where(user_id: @user.id, teams: {authorize: %w(owner)})
# owner_count = org.team_users.joins(:team).where(teams: {authorize: %w(owner)}).count
# # 多个owner时,仅将用户从组织移除, 一个时直接删除
# if owner_count > 1
# org.team_users.joins(:team).where(user_id: @user.id, teams: {authorize: %w(owner)}).destroy_all
# org.organization_users.where(user_id: @user.id, organization_id: org.id).destroy_all
# else
# org.destroy
# end
# end
# @user.destroy!
# Gitea::User::DeleteService.call(@user.login, true)
#
# render_delete_success
@result_object = Api::V1::Users::DeleteUserService.call(@user) render_delete_success
if @result_object
render_delete_success
else
render_js_error('删除失败!')
end
end end
def lock def lock
@user.lock! @user.lock!
UserAction.create(action_id: @user.id, action_type: "LockUser", user_id: current_user.id, :ip => request.remote_ip)
render_ok render_ok
end end
@ -94,6 +72,6 @@ class Admins::UsersController < Admins::BaseController
def update_params def update_params
params.require(:user).permit(%i[lastname nickname gender technical_title is_shixun_marker params.require(:user).permit(%i[lastname nickname gender technical_title is_shixun_marker
mail phone location location_city school_id department_id admin mail phone location location_city school_id department_id admin
password login website_permission business glcc_admin]) password login])
end end
end end

View File

@ -1,5 +1,4 @@
class Admins::UsersRankController < Admins::BaseController class Admins::UsersRankController < Admins::BaseController
before_action :require_admin
def index def index
@rank_date = rank_date @rank_date = rank_date

View File

@ -1,45 +0,0 @@
class Api::Pm::ActionRunsController < Api::Pm::BaseController
before_action :require_login
def index
tip_exception('请输入workflows') if params[:workflows].blank?
@owner = Owner.find_by(login: params[:owner_id].to_s) || Owner.find_by(id: params[:owner_id].to_s)
tip_exception('组织未找到') if @owner.blank?
action_runs = Gitea::ActionRun.where(owner_id: @owner.gitea_uid)
group_data = action_runs.where(workflow_id: params[:workflows].to_s.split(",")).where(status: [1,2]).group(:workflow_id, :status).count
@result = []
params[:workflows].to_s.split(",").each do |file|
last_action_run = action_runs.where(workflow_id: file).order(updated: :desc).first
last_action_run_json = last_action_run.present? ? {
id: last_action_run.id,
schedule: last_action_run.schedule_id > 0,
title: last_action_run.title,
index: last_action_run.index,
status: last_action_run.status,
started: last_action_run.started,
stopped: last_action_run.stopped,
length: last_action_run.stopped - last_action_run.started,
created: last_action_run.created,
updated: last_action_run.updated,
} : {}
total = 0
success = 0
failure = 0
group_data.each do |k,v|
total += v if k[0] == file
success += v if k[0] == file && k[1] == 1
failure += v if k[0] == file && k[1] == 2
end
@result << {
name: file,
total: total,
success: success,
failure: failure
}.merge(last_action_run_json)
end
render :json => {data: @result}
end
end

View File

@ -1,60 +0,0 @@
class Api::Pm::BaseController < ApplicationController
include Api::ProjectHelper
include Api::UserHelper
include Api::PullHelper
# before_action :doorkeeper_authorize!
# skip_before_action :user_setup
protected
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
def load_project
@project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm', is_public:true)
end
def load_issue
# return render_parameter_missing if params[:pm_project_id].blank?
@issue = Issue.issue_issue.find_by_id(params[:issue_id])
render_not_found('疑修不存在!') if @issue.blank?
end
# 具有对仓库的管理权限
def require_manager_above
@project = load_project
return render_forbidden if !current_user.admin? && !@project.manager?(current_user)
end
# 具有对仓库的操作权限
def require_operate_above
@project = load_project
return render_forbidden if !current_user.admin? && !@project.operator?(current_user)
end
# 具有仓库的操作权限或者fork仓库的操作权限
def require_operate_above_or_fork_project
@project = load_project
return render_forbidden if !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
end
# 具有对仓库的访问权限
def require_public_and_member_above
@project = load_project
return render_forbidden if !@project.is_public && !current_user.admin? && !@project.member?(current_user)
end
end

View File

@ -1,138 +0,0 @@
class Api::Pm::DashboardsController < Api::Pm::BaseController
before_action :require_login
def index
end
def todo
return render_error('请输入正确的pm_project_ids.') if params[:pm_project_ids].blank?
pm_project_ids = params[:pm_project_ids].split(",") rescue []
date = params[:date].present? ? params[:date].to_date : Date.today rescue Date.today
@issues = Issue.where("start_date <= ? and due_date >= ?", date, date)
@issues = @issues.where(pm_project_id: pm_project_ids).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'})
@issues = @issues.where.not(status_id: 5)
@issues = kaminari_paginate(@issues.distinct.pm_includes)
end
def my_issues
return render_error('请输入正确的pm_project_ids.') if params[:pm_project_ids].blank?
return render_error('请输入正确的pm_issue_types.') if params[:pm_issue_types].blank?
pm_project_ids = params[:pm_project_ids].split(",") rescue []
pm_issue_types = params[:pm_issue_types].split(",") rescue []
@all_issues = Issue.where(pm_project_id: pm_project_ids, pm_issue_type: pm_issue_types)
@issues = @all_issues.joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'})
@issues = @issues.where.not(status_id: 5) if params[:category] == "opened"
@issues = kaminari_paginate(@issues.distinct.pm_includes)
@my_assign_requirements_count = @all_issues.where(pm_issue_type: 1).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}).size
@my_assign_tasks_count = @all_issues.where(pm_issue_type: 2).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}).size
@my_assign_bugs_count = @all_issues.where(pm_issue_type: 3).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}).size
end
def my_pm_projects
return render_error('请输入正确的pm_project_id.') if params[:pm_project_id].blank?
@all_issues = Issue.where(pm_project_id: params[:pm_project_id])
time_now = Time.now
@last_week_create_issues_count = @all_issues.where("created_on > ? and created_on < ?", time_now - 7.days, time_now).size
@before_last_week_create_issue_count = @all_issues.where("created_on > ? and created_on < ?", time_now - 14.days, time_now - 7.days).size
@compare_last_week_create_issues = @before_last_week_create_issue_count.zero? ? 0 :(@last_week_create_issues_count - @before_last_week_create_issue_count).to_f / @before_last_week_create_issue_count rescue 0
@last_week_close_issues_count = @all_issues.where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size
@before_last_week_close_issue_count = @all_issues.where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 14.days, time_now - 7.days).size
@compare_last_week_close_issues = @before_last_week_close_issue_count.zero? ? 0 :(@last_week_close_issues_count - @before_last_week_close_issue_count).to_f / @before_last_week_close_issue_count rescue 0
@all_requirement_issues_count = @all_issues.where(pm_issue_type: 1).size
@open_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where.not(status_id: 5).size
@last_week_close_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size
@last_month_close_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size
@all_task_issues_count = @all_issues.where(pm_issue_type: 2).size
@open_task_issues_count = @all_issues.where(pm_issue_type: 2).where.not(status_id: 5).size
@last_week_close_tast_issues_count = @all_issues.where(pm_issue_type: 2).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size
@last_month_close_task_issues_count = @all_issues.where(pm_issue_type: 2).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size
@all_bug_issues_count = @all_issues.where(pm_issue_type: 3).size
@open_bug_issues_count = @all_issues.where(pm_issue_type: 3).where.not(status_id: 5).size
@last_week_close_bug_issues_count = @all_issues.where(pm_issue_type: 3).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size
@last_month_close_bug_issues_count = @all_issues.where(pm_issue_type: 3).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size
@requirement_close_trend = [[],[]]
@task_close_trend = [[],[]]
@bug_close_trend = [[],[]]
((time_now-29.days).to_date..time_now.to_date).to_a.each do |i|
@requirement_close_trend[0] << i.strftime("%Y.%m.%d")
@task_close_trend[0] << i.strftime("%Y.%m.%d")
@bug_close_trend[0] << i.strftime("%Y.%m.%d")
@requirement_close_trend[1] << @all_issues.where(pm_issue_type: 1, status_id: 5).where("DATE(updated_on) = ?", i).size
@task_close_trend[1] << @all_issues.where(pm_issue_type: 2, status_id: 5).where("DATE(updated_on) = ?", i).size
@bug_close_trend[1] << @all_issues.where(pm_issue_type: 3, status_id: 5).where("DATE(updated_on) = ?", i).size
end
@close_trend = {requirement: @requirement_close_trend, task: @task_close_trend, bug: @bug_close_trend}
render_ok(data: {
last_week_close_issues_count: @last_week_close_issues_count,
before_last_week_close_issue_count: @before_last_week_close_issue_count,
compare_last_week_close_issues: @compare_last_week_close_issues,
last_week_create_issues_count: @last_week_create_issues_count,
before_last_week_create_issue_count: @before_last_week_create_issue_count,
compare_last_week_create_issues: @compare_last_week_create_issues,
all_requirement_issues_count: @all_requirement_issues_count,
open_requirement_issues_count: @open_requirement_issues_count,
last_week_close_requirement_issues_count: @last_week_close_requirement_issues_count,
last_month_close_requirement_issues_count: @last_month_close_requirement_issues_count,
all_task_issues_count: @all_task_issues_count,
open_task_issues_count: @open_task_issues_count,
last_week_close_task_issues_count: @last_week_close_tast_issues_count,
last_month_close_task_issues_count: @last_month_close_task_issues_count,
all_bug_issues_count: @all_bug_issues_count,
open_bug_issues_count: @open_bug_issues_count,
last_week_close_bug_issues_count: @last_week_close_bug_issues_count,
last_month_close_bug_issues_count: @last_month_close_bug_issues_count,
close_trend: @close_trend
})
end
def my_projects
return render_error('请输入正确的project_id.') if params[:project_id].blank?
@project = Project.find_by_id params[:project_id]
return render_error('请输入正确的project_id.') unless @project.present?
time_now = Time.now
branch_tag_result = $gitea_hat_client.get_repos_branch_tag_count_by_owner_repo(@project&.owner&.login, @project&.identifier) rescue {}
languages_result = $gitea_client.get_repos_languages_by_owner_repo(@project&.owner&.login, @project&.identifier) rescue {}
@open_pull_requests_count = @project.pull_requests.opening.size
@last_week_close_pull_requests_count = @project.pull_requests.where(status: 1).where("updated_at > ? and updated_at < ?", time_now - 7.days, time_now).size
@last_month_close_pull_requets_count = @project.pull_requests.where(status: 1).where("updated_at > ? and updated_at < ?", time_now - 30.days, time_now).size
@commits_count = @project.commit_logs.size
@last_week_commits_count = @project.commit_logs.where("created_at > ? and created_at < ?", time_now - 7.days, time_now).size
@last_month_commits_count = @project.commit_logs.where("created_at > ? and created_at < ?", time_now - 30.days, time_now).size
render_ok(data: {
branch_count: branch_tag_result["branch_count"].to_i,
tag_count: branch_tag_result["tag_count"].to_i,
license_name: @project.license&.name,
open_pull_requests_count: @open_pull_requests_count,
last_week_close_pull_requests_count: @last_week_close_pull_requests_count,
last_month_close_pull_requets_count: @last_month_close_pull_requets_count,
commits_count: @commits_count,
last_week_commits_count: @last_week_commits_count,
last_month_commits_count: @last_month_commits_count,
language: hash_transform_precentagable(languages_result),
})
end
def my_operate_journals
return render_error('请输入正确的pm_project_id.') if params[:pm_project_id].blank?
@journals = Journal.operate_journals.joins(:issue).where(issues: {pm_project_id: params[:pm_project_id], pm_issue_type: [1,2,3]})
@journals = kaminari_paginate(@journals.order(updated_on: :desc))
end
private
def hash_transform_precentagable(hash)
total_byte_size = hash.values.sum
hash.transform_values { |v|
ActionController::Base.helpers
.number_to_percentage((v * 100.0 / total_byte_size), precision: 1)
}.select{|k,v| v != "0.0%"}
end
end

View File

@ -1,46 +0,0 @@
class Api::Pm::IssueLinksController < Api::Pm::BaseController
before_action :load_project
before_action :load_issue
def index
@links = PmLink.where(be_linkable_id: @issue.id,be_linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id,linkable_type: 'Issue'))
end
def create
begin
ActiveRecord::Base.transaction do
params[:link_ids].each do |e|
@issue.pm_links.find_or_create_by!(be_linkable_type: 'Issue', be_linkable_id: e)
tag_issue = Issue.find_by_id(e)
next unless tag_issue.present?
journal = tag_issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", value: @issue.id.to_s})
end
journal = @issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: "tag_link_issue", prop_key: "#{params[:link_ids].size}", value: params[:link_ids].join(",")})
end
render_ok
rescue
render_error('创建失败!')
end
end
def destroy
begin
ActiveRecord::Base.transaction do
@links = PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue', linkable_id: params[:id], linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue', be_linkable_id: params[:id], be_linkable_type: 'Issue'))
journal = @issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", old_value: params[:id].to_s})
another_issue = Issue.find_by_id(params[:id])
if another_issue.present?
journal = another_issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", old_value: @issue.id.to_s})
end
@link = @links.last
@link.destroy!
end
render_ok
rescue
render_error('删除失败!')
end
end
end

View File

@ -1,71 +0,0 @@
class Api::Pm::IssueTagsController < Api::Pm::BaseController
def index
@issue_tags = IssueTag.pm_able
if params[:organization_id].present?
IssueTag.pm_org_init_data(params[:organization_id]) unless $redis_cache.hget("pm_org_init_issue_tags", params[:organization_id])
@issue_tags = @issue_tags.where(organization_id: params[:organization_id])
end
@issue_tags = @issue_tags.where(pm_project_id: params[:pm_project_id]) if params[:pm_project_id].present?
@issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
@issue_tags = @issue_tags.reorder("#{tag_sort_by} #{tag_sort_direction}")
@issue_tags = kaminari_paginate(@issue_tags)
render "api/v1/issues/issue_tags/index"
end
def create
return render_error("请输入正确的OrganizationID") unless Organization.exists?(id: issue_tag_create_params[:organization_id])
return render_error("项目标记名称不能为空!") unless issue_tag_create_params[:name].present?
@issue_tag = IssueTag.new(issue_tag_create_params.merge!(project_id: 0))
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_update_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 tag_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 tag_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_create_params
params.permit(:name, :description, :color, :pm_project_id, :organization_id)
end
def issue_tag_update_params
params.permit(:name, :description, :color)
end
def load_issue_tag
@issue_tag = IssueTag.pm_able.find_by_id(params[:id])
end
end

View File

@ -1,376 +0,0 @@
class Api::Pm::IssuesController < Api::Pm::BaseController
before_action :require_login, except: [:index]
before_action :load_project
before_action :load_issue, only: %i[show update destroy link_index link_issues parent_issues]
before_action :load_issues, only: %i[batch_update batch_destroy]
before_action :check_issue_operate_permission, only: %i[update destroy]
def index
@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]
@complete_issues_count = @object_result[:complete_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
render 'api/v1/issues/index'
end
def link_index
pm_issue_type = params[:pm_issue_type] || [1, 2, 3]
not_join_id = case params[:issue_filter_type]
when 'leaf_issue'
Issue.where(root_id: @issue.id).pluck(:id)
when 'link_issue'
@issue.pm_links.pluck(:be_linkable_id)
end
not_join_id << @issue.id
object_issues = Issue.where(
pm_project_id: params[:pm_project_id],
pm_issue_type: pm_issue_type
).where.not(id: not_join_id).order(updated_on: :desc)
object_issues = object_issues.where(root_id: nil, child_count: 0) if params[:issue_filter_type] == 'leaf_issue'
@issues = kaminari_paginate(object_issues)
render 'api/v1/issues/index'
end
def parent_issues
@issues = Issue.where(pm_project_id: params[:pm_project_id])
.where.not(id: @issue.id)
.where.not(id: Issue.full_children_issues(@issue).map{|i|i.id})
@issues = @issues.where(pm_issue_type: params[:pm_issue_type]) if params[:pm_issue_type].present?
@issues = @issues.ransack(id_or_project_issues_index_eq: params[:keyword]).result.or(@issues.ransack(subject_or_description_cont: params[:keyword]).result) if params[:keyword].present?
@issues = @issues.reorder("#{issue_sort_by} #{issue_sort_direction}")
if params[:only_name].present?
@issues = kaminary_select_paginate(
@issues.select(:id, :subject, :project_issues_index, :updated_on, :created_on))
else
@issues = @issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals)
@issues = kaminari_paginate(@issues)
end
end
def show
@issue.associate_attachment_container
render 'api/v1/issues/show'
end
def create
@object_result = Api::Pm::Issues::CreateService.call(@project, issue_params, current_user)
render 'api/v1/issues/create'
end
def update
@object_result = Api::Pm::Issues::UpdateService.call(@project, @issue, issue_params, current_user)
render 'api/v1/issues/update'
end
def batch_update
@object_result = Api::Pm::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user)
if @object_result
render_ok
else
render_error('批量更新疑修失败!')
end
end
def batch_destroy
return render_ok if params[:ids].is_a?(Array) && params[:ids].blank?
@object_result = Api::Pm::Issues::BatchDeleteService.call(@project, @issues, current_user)
if @object_result
render_ok
else
render_error('批量删除疑修失败!')
end
end
def priorities
@priorities = IssuePriority.order(position: :asc)
@priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword]
@priorities = kaminary_select_paginate(@priorities)
render "api/v1/issues/issue_priorities/index"
end
def tags
# IssueTag.pm_init_data(params[:pm_project_id]) unless $redis_cache.hget("pm_project_init_issue_tags", params[:pm_project_id])
@issue_tags = IssueTag.where(pm_project_id: params[:pm_project_id]).reorder("#{tag_sort_by} #{tag_sort_direction}")
@issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
params[:only_name] = true #强制渲染 不走project
@issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color))
render "api/v1/issues/issue_tags/index"
end
def statues
@statues = IssueStatus.order("position asc")
@statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
@statues = kaminary_select_paginate(@statues)
render "api/v1/issues/statues/index"
end
def destroy
@object_result = Api::Pm::Issues::DeleteService.call(@project, @issue, current_user)
if @object_result
render_ok
else
render_error('删除疑修失败!')
end
end
def export
return render_error('请输入正确的项目ID.') if params[:pm_project_id].blank?
Axlsx::Package.new do |p|
[['requirement', 1], ['task', 2], ['bug', 3]].each do |type|
p.workbook.add_worksheet(:name => type[0]) do |sheet|
@issues = Issue.where(pm_project_id: params[:pm_project_id], pm_issue_type: type[1])
sheet.add_row ["ID", "标题*", "正文", "创建者*", "创建时间", "修改者", "更新时间", "状态", "负责人", "优先级", "标记", "开始时间","结束时间", "预估工时"]
@issues.each do |issue|
sheet.add_row [issue.id, issue.subject, issue.description, issue.user.try(:login), issue.created_on.strftime("%Y-%m-%d %H:%M:%S"), issue.changer.try(:login), issue.updated_on.strftime("%Y-%m-%d %H:%M:%S"), issue.status_id, issue.assigners.pluck(:login).join(","), issue.priority_id, issue.issue_tags.pluck(:name, :color).join(","), issue.start_date.present? ? issue.start_date.strftime("%Y-%m-%d") : "", issue.due_date.present? ? issue.due_date.strftime("%Y-%m-%d") : "", issue.time_scale]
end
end
end
p.workbook.add_worksheet(:name => 'leaf_relations') do |sheet|
leaf_issues = Issue.where(pm_project_id: params[:pm_project_id]).where.not(root_id: nil)
sheet.add_row ["ID", "父工作项ID"]
leaf_issues.each do |issue|
sheet.add_row [issue.id, issue.root_id]
end
end
p.workbook.add_worksheet(:name => 'link_relations') do |sheet|
# links = PmLink.joins(:linkable_issue).where(issues: {pm_project_id: params[:pm_project_id]})
links = PmLink.find_by_sql("SELECT `pm_links`.* FROM `pm_links` INNER JOIN `issues` ON `issues`.`id` = `pm_links`.`linkable_id` AND `pm_links`.`linkable_type` = 'Issue' WHERE `issues`.`pm_project_id` = #{params[:pm_project_id]}")
sheet.add_row ["ID", "被关联工作项ID"]
links.each do |link|
sheet.add_row [link.linkable_id, link.be_linkable_id]
end
end
p.serialize('public/导出工作项.xlsx')
end
send_file('public/导出工作项.xlsx', :type => 'application/octet-stream;charset=utf-8')
end
def import
begin
return render_error('请上传正确的文件') if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile)
return render_error('请输入正确的项目ID.') if params[:pm_project_id].blank?
return render_error('请输入正确的组织ID.') if params[:organization_id].blank?
ActiveRecord::Base.transaction do
types = {requirement: 1, task: 2, bug: 3}
doc = SimpleXlsxReader.open(params[:file].tempfile)
doc.sheets.each do |sheet|
case sheet.name
when 'requirement', 'task', 'bug'
type = types["#{sheet.name}".to_sym]
sheet.rows.each.with_index do |row, index|
next if index == 0
issue = Issue.new(issue_classify: "issue", project_id: 0, pm_project_id: params[:pm_project_id], pm_issue_type: type, tracker_id: Tracker.first.id)
issue.fake_id = row[0]
issue.subject = row[1]
issue.description = row[2]
author = User.find_by(login: row[3])
issue.user = author
issue.created_on = row[4]
changer = User.find_by(login: row[5])
issue.changer = changer
issue.updated_on = row[6]
issue.status_id = row[7].to_i
if row[8].present?
row[8].split(',').each do |a|
u = User.find_by(login: a)
next unless u.present?
issue.assigners << u
end
end
issue.priority_id = row[9]
if row[10].present?
row[10].split(',').each_slice(2).to_a.each do |t|
tag = IssueTag.find_by(project_id: 0, organization_id: params[:organization_id], name: t[0])
if tag.present?
issue.issue_tags << tag
else
tag = IssueTag.create(project_id: 0,organization_id: params[:organization_id], name: t[0], color: t[1])
issue.issue_tags << tag
end
end
end
issue.start_date = row[11]
issue.due_date = row[12]
issue.time_scale = row[13]
issue.save!
end
when 'leaf_relations'
sheet.rows.each.with_index do |row, index|
next if index == 0
children_issue = Issue.where(fake_id: row[0]).last
parent_issue = Issue.where(fake_id: row[1]).last
next if children_issue.blank? || parent_issue.blank?
children_issue.root_id = parent_issue.id
children_issue.save(touch: false)
end
when 'link_relations'
sheet.rows.each.with_index do |row, index|
next if index == 0
link_issue = Issue.where(fake_id: row[0]).last
be_link_issue = Issue.where(fake_id: row[1]).last
next if link_issue.blank? || be_link_issue.blank?
PmLink.create!(linkable_type: 'Issue', linkable_id: link_issue.id, be_linkable_type: 'Issue', be_linkable_id: be_link_issue.id)
end
else
return render_error('导入失败请上传正确格式的excel文件')
end
end
end
render_ok
rescue
return render_error('导入失败请上传正确格式的excel文件')
end
end
def link_issues
children_issues = @issue.pm_issue_type == 1 ? @issue.child_count > 0 ? Issue.where(id: @issue.id) : Issue.none : Issue.where(root_id: @issue.id)
linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: @issue.id).pluck(:be_linkable_id))
belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: @issue.id).pluck(:linkable_id))
full_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id)
compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id)
i = compare_link_issues_ids.count
while i > 0 do
children_issues = Issue.where(root_id: compare_link_issues_ids)
linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: compare_link_issues_ids).pluck(:be_linkable_id))
belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: compare_link_issues_ids).pluck(:linkable_id))
compare_link_issues_ids = (children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id)) - full_link_issues_ids
full_link_issues_ids = full_link_issues_ids | compare_link_issues_ids
i = compare_link_issues_ids.count
end
exclude_issues_ids = []
exclude_issues = Issue.where(id: full_link_issues_ids).where.not(root_id: nil)
exclude_issues.each do |i|
exclude_issues_ids << i.id if i.pm_issue_type == 1 && full_link_issues_ids.include?(i.root_id)
end
full_link_issues_ids = full_link_issues_ids - exclude_issues_ids
@requirement_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:1, root_id: nil).pm_includes
@task_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:2).pm_includes
@bug_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:3).pm_includes
end
private
def circle_link_issues(issue_ids)
if issue_ids.present?
children_issues = Issue.joins(:parent_issue).where(issues: {id: issue_ids})
linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: issue_ids))
belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: issue_ids))
return circle_link_issues(children_issues.pluck(:id))
else
return []
end
end
def check_issue_operate_permission
return if params[:project_id].to_i.zero?
render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user
end
def load_issue
# return render_parameter_missing if params[:pm_project_id].blank?
@issue = Issue.issue_issue.find_by_id(params[:id])
render_not_found('疑修不存在!') if @issue.blank?
end
# def load_issue_by_index
# return render_parameter_missing if params[:pm_project_id].blank? || params[:pm_issue_type].blank? || params[:enterprise_identifier].blank?
# @issue = Issue.find_issues_by_pm(params[:enterprise_identifier], params[:pm_issue_type])
# .find_by(pm_issue_type_index3: params[:index])
# render_not_found('疑修不存在!') if @issue.blank?
# 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, pm_project_id: params[:pm_project_id])
return render_not_found("ID为#{id}的疑修不存在!") if @issue.blank?
end
if params[:ids].blank?
@issues = Issue.where(pm_project_id: params[:pm_project_id])
else
@issues = Issue.where(id: params[:ids], pm_project_id: params[:pm_project_id])
end
end
def query_params
params.permit(
:only_name,
:category,
:participant_category,
:keyword, :author_id,
:milestone_id, :assigner_id,
:status_id, :priority_id,
:begin_date, :end_date,
:update_begin_date, :update_end_date,
:sort_by, :sort_direction, :root_id,
:issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type, :pm_project_ids,
:status_ids, :ids, :exclude_ids, :pm_issue_types, :participator_id, :enterprise_identifier
)
end
def issue_params
params.permit(
:status_id, :priority_id, :milestone_id,
:branch_name, :start_date, :due_date, :time_scale,
:subject, :description, :blockchain_token_num, :root_subject,
:pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :link_able_id, :project_id,
:status_msg, :enterprise_identifier,
issue_tag_ids: [],
assigner_ids: [],
attachment_ids: [],
receivers_login: []
)
end
def batch_issue_params
params.permit(
:status_id, :priority_id, :milestone_id, :pm_sprint_id, :due_date, :pm_issue_type, :root_id, :target_pm_project_id, :project_id,
:issue_tag_ids => [],
:assigner_ids => [] )
end
def issue_sort_by
sort_by = params.fetch(:sort_by, "updated_on")
sort_by = Issue.column_names.include?(sort_by) ? sort_by : "updated_on"
sort_by
end
def issue_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 tag_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 tag_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

View File

@ -1,61 +0,0 @@
class Api::Pm::JournalsController < Api::Pm::BaseController
before_action :require_login, except: [:index, :children_journals]
before_action :load_project
before_action :load_issue
before_action :load_journal, only: [:children_journals, :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])
render 'api/pm/issues/journals/index'
end
def create
@object_result = Api::V1::Issues::Journals::CreateService.call(@issue, journal_params, current_user)
render 'api/v1/issues/journals/create'
end
def children_journals
@object_results = Api::V1::Issues::Journals::ChildrenListService.call(@issue, @journal, query_params, current_user)
@journals = kaminari_paginate(@object_results)
render 'api/v1/issues/journals/children_journals'
end
def update
@object_result = Api::V1::Issues::Journals::UpdateService.call(@issue, @journal, journal_params, current_user)
render 'api/v1/issues/journals/update'
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 = Issue.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:issue_id])
render_not_found('疑修不存在!') if @issue.blank?
end
def load_journal
@journal = Journal.find_by_id(params[:id])
render_not_found('评论不存在!') unless @journal.present?
end
end

View File

@ -1,77 +0,0 @@
class Api::Pm::PipelinesController < Api::Pm::BaseController
include RepositoriesHelper
def index
@owner = Owner.find_by(login: params[:owner_id].to_s) || Owner.find_by(id: params[:owner_id].to_s)
tip_exception('组织未找到') if @owner.blank?
unless @owner.is_a?(Organization) && @owner.is_member?(current_user.id)
tip_exception('没有查看组织的权限')
end
@project_ids = @owner.projects.ids
project_gpids = @owner.projects.pluck(:gpid)
action_runs = Gitea::ActionRun.where(owner_id: @owner.gitea_uid)
group_data = action_runs.where(status: [1,2]).group(:workflow_id, :status).count
pipelines = Action::Pipeline.where(project_id: @project_ids).order(updated_at: :desc)
run_files = Gitea::ActionRun.select(:workflow_id, :repo_id).where(owner_id: @owner.gitea_uid).group(:workflow_id, :repo_id)
db_files = pipelines.pluck(:file_name)
@run_result = []
run_files.each do |file_info|
file = file_info.workflow_id
project = Project.find_by(gpid: file_info.repo_id)
next if project.blank?
unless db_files.include?(".gitea/workflows/#{file}")
pipeline = Action::Pipeline.find_or_initialize_by(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""),
file_name: ".gitea/workflows/#{file}",
branch: project.default_branch,
is_graphic_design: false,
disable: false,
project_id: project.id)
interactor = Repositories::EntriesInteractor.call(@owner, project.identifier, ".gitea/workflows/#{file}", ref: project.default_branch)
if interactor.success?
pipeline.yaml = decode64_content(interactor.result, @owner, project.repository, project.default_branch, nil)
end
pipeline.user_id = current_user.id
pipeline.save
# 导入的流水线统一先禁用
$gitea_hat_client.post_repos_actions_disable(project&.owner&.login, project&.identifier, {query: {workflow: file}}) rescue nil
end
last_action_run = action_runs.where(repo_id: project.gpid).where(workflow_id: file).order(updated: :desc).first
last_action_run_json = last_action_run.present? ? {
id: last_action_run.id,
schedule: last_action_run.schedule_id > 0,
title: last_action_run.title,
index: last_action_run.index,
status: last_action_run.status,
started: last_action_run.started,
stopped: last_action_run.stopped,
length: last_action_run.stopped-last_action_run.started,
created: last_action_run.created,
updated: last_action_run.updated,
} : {}
total = 0
success = 0
failure = 0
group_data.each do |k,v|
total += v if k[0] == file
success += v if k[0] == file && k[1] == 1
failure += v if k[0] == file && k[1] == 2
end
@run_result << {
repo_id: last_action_run.repo_id,
filename: ".gitea/workflows/#{file}",
total: total,
success: success,
failure: failure
}.merge(last_action_run_json)
end
# Rails.logger.info("@run_result======#{@run_result}")
@disabled_workflows = Gitea::RepoUnit.where(repo_id: project_gpids, type: 10).where("config is not null")
@pipelines = Action::Pipeline.select("distinct project_id,max(updated_at) as updated_at")
.where(project_id: @project_ids).group(:project_id).order("updated_at desc")
@pipelines = @pipelines.where("pipeline_name like ?", "%#{params[:pipeline_name]}%") if params[:pipeline_name].present?
@pipelines = @pipelines.where(pipeline_type: params[:pipeline_type]) if params[:pipeline_type].present?
@pipelines = kaminari_paginate(@pipelines)
end
end

View File

@ -1,156 +0,0 @@
class Api::Pm::ProjectsController < Api::Pm::BaseController
before_action :require_login, except: [:convert]
before_action :load_project, only: [:convert]
def convert
data = {
owner: @project.owner.try(:login),
identifier: @project.identifier,
name: @project.name
}
render_ok(data: data)
end
def issues_count
return tip_exception '参数错误' unless params[:pm_project_id].present?
@issues = Issue.where(pm_project_id: params[:pm_project_id])
case params[:category].to_s
when 'closed'
@issues = @issues.closed
when 'opened'
@issues = @issues.opened
end
@participant_category_count = {}
if params[:participant_category].to_s == "authoredme" or params[:participant_category].to_s == "assignedme"
issues_category = @issues.joins(:issue_participants).where(pm_issue_type: [1, 2, 3]).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: current_user&.id})
@participant_category_count = issues_category.group(:pm_project_id, "issue_participants.participant_type").count
end
case params[:participant_category].to_s
when 'aboutme' # 关于我的
@issues = @issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: current_user&.id})
when 'authoredme' # 我创建的
@issues = @issues.joins(:issue_participants).where(issue_participants: {participant_type: 'authored', participant_id: current_user&.id})
when 'assignedme' # 我负责的
@issues = @issues.joins(:issue_participants).where(issue_participants: {participant_type: 'assigned', participant_id: current_user&.id})
when 'atme' # @我的
@issues = @issues.joins(:issue_participants).where(issue_participants: {participant_type: 'atme', participant_id: current_user&.id})
end
data = {}
@issues_count = @issues.group(:pm_project_id).count
# requirement 1 task 2 bug 3
@issues_type_count = @issues.group(:pm_project_id, :pm_issue_type).count
params[:pm_project_id].map(&:to_i).map do |project_id|
data[project_id] = {
total: @issues_count[project_id] || 0,
requirement: @issues_type_count[[project_id, 1]] || 0,
task: @issues_type_count[[project_id, 2]] || 0,
bug: @issues_type_count[[project_id, 3]] || 0,
authoredme: @participant_category_count[[project_id, 0]] || 0,
assignedme: @participant_category_count[[project_id, 1]] || 0,
atme: @participant_category_count[[project_id, 4]] || 0,
}
end
render_ok(data: data)
end
def statistics
return tip_exception '参数错误' if params[:pm_project_id].blank?
@issues = Issue.where(pm_project_id: params[:pm_project_id], pm_issue_type:[1, 2, 3])
@last_week_close_issues = @issues.where(status_id: 5).where("updated_on > ? and updated_on < ?", Time.now - 7.days, Time.now)
last_week_close_type_count_data = @last_week_close_issues.group(:pm_issue_type).count
type_count_data = @issues.group(:pm_issue_type).count
type_status = @issues.group(:pm_issue_type,:status_id).count
type_status_data = {}
IssueStatus.all.map do |e|
# next if e.id == 5
[1,2,3].map{ |type|
next if type == 1 && [1, 6].include?(e.id)
type_status_data[type] = {} if type_status_data[type].nil?
if type_status[[type,e.id]].nil?
type_status_data[type][e.id] = 0
else
type_status_data[type][e.id] = type_status[[type,e.id]]
end
}
end
open_data = {
"1": type_status_data[1][1].to_i + type_status_data[1][2].to_i + type_status_data[1][3].to_i + type_status_data[1][6].to_i,
"2": type_status_data[2][1].to_i + type_status_data[2][2].to_i + type_status_data[2][3].to_i + type_status_data[2][6].to_i,
"3": type_status_data[3][1].to_i + type_status_data[3][2].to_i + type_status_data[3][3].to_i + type_status_data[3][6].to_i,
}
if type_count_data.keys.size < 3
nedd_add = [1,2,3] - type_count_data.keys
nedd_add.map{ |e|
type_count_data[e] = 0
}
end
if last_week_close_type_count_data.keys.size < 3
nedd_add = [1,2,3] - last_week_close_type_count_data.keys
nedd_add.map{ |e|
last_week_close_type_count_data[e] = 0
}
end
data = {
pie_chart: type_count_data,
bar_chart: type_status_data,
open_data: open_data,
last_week_close_data: last_week_close_type_count_data,
}
render_ok(data: data)
end
def polyline
return tip_exception '参数错误' if params[:pm_project_id].blank?
time_line = (Time.current.beginning_of_day - 29.day) .. Time.current
@create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line)
@due_issues = Issue.where(pm_project_id: params[:pm_project_id],status_id:[3,5],due_date: time_line)
@create_issues_count = @create_issues.group(:pm_issue_type,"DATE(created_on)").count
@due_issues_count = @due_issues.group(:pm_issue_type,"DATE(due_date)").count
data = {
create_issues: {},
due_issues: {}
}
30.times do |time|
current_time = Date.current - time.day
if @create_issues_count.present?
data[:create_issues][current_time] = {
"1": @create_issues_count[[1,current_time]] || 0,
"2": @create_issues_count[[2,current_time]] || 0,
"3": @create_issues_count[[3,current_time]] || 0
}
else
data[:create_issues][current_time] = {
"1": 0,
"2": 0,
"3": 0
}
end
if @due_issues_count.present?
data[:due_issues][current_time] = {
"1": @due_issues_count[[1,current_time]] || 0,
"2": @due_issues_count[[2,current_time]] || 0,
"3": @due_issues_count[[3,current_time]] || 0
}
else
data[:due_issues][current_time] = {
"1": 0,
"2": 0,
"3": 0
}
end
end
render_ok(data: data)
end
def bind_project
return render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin?
Issue.where(pm_project_id: params[:pm_project_id], user_id: current_user).update_all(project_id: params[:project_id])
end
private
def load_project
@project = Project.joins(:owner).find params[:project_id]
end
end

View File

@ -1,109 +0,0 @@
class Api::Pm::SprintIssuesController < Api::Pm::BaseController
before_action :require_login, except: [:index]
def index
@issues = Api::Pm::SprintIssues::ListService.call(query_params, current_user)
@issues = kaminari_paginate(@issues)
render 'api/v1/issues/index'
end
def burndown_charts
return tip_exception '参数错误' if params[:pm_sprint_id].blank? || params[:start_time].blank? || params[:end_time].blank?
@issues = Issue.where(pm_sprint_id: params[:pm_sprint_id])
start_time = Date.parse params[:start_time]
end_time = Date.parse params[:end_time]
time_count = (end_time - start_time).to_i + 1 # 计算间隔时间 加上最后一天
data = []
curren_issues = @issues.group(:status_id, :due_date).count
total_count = @issues.count
cardinality = (total_count.zero? || time_count.zero?) ? 0 : total_count.to_f / time_count.to_f
# cardinality = BigDecimal.new(total_count) / BigDecimal.new(time_count)
time_count.times do |x|
e_time = start_time + x
completed = curren_issues[[5, e_time]].to_i + curren_issues[[3, e_time]].to_i - @issues.where(pm_issue_type: 3, status_id: 3).size
total_count = total_count - completed
data << { time: e_time, undone: total_count, completed: completed, base_number: (cardinality * (time_count - x - 1)).to_f.round(2) }
end
render_ok(data: data)
end
def statistics
pm_sprint_ids = params[:pm_sprint_ids].split(",") rescue []
return tip_exception '参数错误' if pm_sprint_ids.blank?
@issues = Issue.where(pm_sprint_id: pm_sprint_ids)
data = {}
# requirement 1 task 2 bug 3
@issues_count = @issues.group(:pm_sprint_id).count
@issues_type_count = @issues.group(:pm_sprint_id, :status_id).count
@issues_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type).count
@issues_hour_count = @issues.group(:pm_sprint_id).sum(:time_scale)
@issues_hour_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale)
@issues_hour_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type).sum(:time_scale)
@issues_status_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type, :status_id).count
pm_sprint_ids.map(&:to_i).map do |sprint_id|
# count_closed 工作项已完成/已关闭数量,需排除已修复的缺陷数量
count_closed = @issues_type_count[[sprint_id, 5]].to_i + @issues_type_count[[sprint_id, 3]].to_i - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).size
# hour_closed 已完成/已关闭 预估工时之和,需排除已修复的缺陷预估工时
hour_closed = @issues_hour_type_count[[sprint_id, 5]].to_f + @issues_hour_type_count[[sprint_id, 3]].to_f - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).sum(:time_scale).to_f
data[sprint_id] = {
count_total: @issues_count[sprint_id] || 0,
count_closed: count_closed || 0,
hour_total: @issues_hour_count[sprint_id].to_f || 0,
hour_closed: hour_closed || 0,
requirement: @issues_pm_type_count[[sprint_id, 1]] || 0,
task: @issues_pm_type_count[[sprint_id, 2]] || 0,
bug: @issues_pm_type_count[[sprint_id, 3]] || 0,
requirement_hour: @issues_hour_pm_type_count[[sprint_id, 1]].to_i || 0,
task_hour: @issues_hour_pm_type_count[[sprint_id, 2]].to_i || 0,
bug_hour: @issues_hour_pm_type_count[[sprint_id, 3]].to_i || 0,
requirement_open: (@issues_status_pm_type_count[[sprint_id, 1, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 1, 2]].to_i) || 0,
task_open: @issues_status_pm_type_count[[sprint_id, 2, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 2, 2]].to_i || 0,
bug_open: @issues_status_pm_type_count[[sprint_id, 3, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 3, 2]].to_i || 0
}
end
render_ok(data: data)
end
before_action :load_uncomplete_issues, only: [:complete]
def complete
begin
case complete_params[:complete_type].to_i
when 1
@issues.update_all(status_id: 5, due_date: Time.now)
when 2
@issues.update_all(pm_sprint_id: 0)
when 3
@issues.update_all(pm_sprint_id: complete_params[:target_pm_project_sprint_id])
end
render_ok
rescue => e
render_error(e.message)
end
end
private
def load_uncomplete_issues
@issues = Issue.where(pm_sprint_id: complete_params[:pm_project_sprint_id]).where.not(status_id: 5)
end
def complete_params
params.permit(:pm_project_sprint_id, :complete_type, :target_pm_project_sprint_id)
end
def query_params
params.permit(
:category,
:pm_project_id,
:pm_issue_type, # 需求1 任务2 缺陷3
:assigner_id,
:priority_id,
:status_id,
:keyword, :status_ids, :pm_issue_types,
:sort_by, :sort_direction
)
end
end

View File

@ -1,82 +0,0 @@
class Api::Pm::WeeklyIssuesController < Api::Pm::BaseController
def personal
@enterprise_identifier = params[:enterprise_identifier] || ''
return render_error('请输入正确的用户ID.') if params[:user_id].blank?
@all_issues = Issue.joins(:issue_participants).where(issue_participants: {participant_id: params[:user_id], participant_type: ['assigned']})
@all_issues = @all_issues.where(enterprise_identifier: @enterprise_identifier, pm_issue_type: [1,2,3])
@this_week_all_issues = @all_issues.where("due_date >= ? and start_date <= ?", Date.today.beginning_of_week.to_s, Date.today.end_of_week.to_s).distinct
@this_week_all_issues = @this_week_all_issues.order('created_on desc')
@next_week_all_issues = @all_issues.where("due_date >= ? and start_date <=?", (Date.today.beginning_of_week+1.week).to_s, (Date.today.end_of_week+1.week).to_s).distinct
@next_week_all_issues = @next_week_all_issues.order('created_on desc')
@this_week_requirement_issues = @this_week_all_issues.where(pm_issue_type: 1)
@this_week_task_issues = @this_week_all_issues.where(pm_issue_type: 2)
@this_week_bug_issues = @this_week_all_issues.where(pm_issue_type: 3)
@close_requirement_issues = @this_week_requirement_issues.where(status_id: [3,5])
@close_task_issues = @this_week_task_issues.where(status_id: [3,5])
@close_bug_issues = @this_week_bug_issues.where(status_id: [3,5])
this_week_page = params[:this_week_page] || 1
this_week_limit = params[:this_week_limit] || 15
@this_week_all_issues = @this_week_all_issues.page(this_week_page).per(this_week_limit)
next_week_page = params[:next_week_page] || 1
next_week_limit = params[:next_week_limit] || 15
@next_week_all_issues = @next_week_all_issues.page(next_week_page).per(next_week_limit)
end
def group
@enterprise_identifier = params[:enterprise_identifier] || ''
@all_issues = Issue.where(enterprise_identifier: @enterprise_identifier, pm_issue_type: [1,2,3])
@all_issues = @all_issues.where(pm_project_id: params[:pm_project_ids].split(",")) if params[:pm_project_ids].present?
@this_week_all_issues = @all_issues.where("due_date >= ? and start_date <= ?", Date.today.beginning_of_week.to_s, Date.today.end_of_week.to_s)
@this_week_all_issues_group_count = @this_week_all_issues.group(:pm_project_id).count
data = {}
@this_week_all_issues_group_count.keys.each do |pm_project_id|
this_project_id_requirements = @this_week_all_issues.where(pm_project_id: pm_project_id, pm_issue_type: 1)
this_project_id_tasks = @this_week_all_issues.where(pm_project_id: pm_project_id, pm_issue_type: 2)
this_project_id_bugs = @this_week_all_issues.where(pm_project_id: pm_project_id, pm_issue_type: 3)
this_project_id_close_requirements = this_project_id_requirements.where(status_id: [3,5])
this_project_id_close_tasks = this_project_id_tasks.where(status_id: [3,5])
this_project_id_close_bugs = this_project_id_bugs.where(status_id: [3,5])
data[pm_project_id] = {
this_week_requirement_issues_count: this_project_id_requirements.count,
this_week_task_issues_count: this_project_id_tasks.count,
this_week_bug_issues_count: this_project_id_bugs.count,
close_requirement_issues_count: this_project_id_close_requirements.count,
close_task_issues_count: this_project_id_close_tasks.count,
close_bug_issues_count: this_project_id_close_bugs.count,
this_week_task_issues: this_project_id_tasks
}
end
render :json => data
end
def group_issues
@enterprise_identifier = params[:enterprise_identifier] || ''
@all_issues = Issue.where(enterprise_identifier: @enterprise_identifier, pm_issue_type: [1,2,3])
@all_issues = @all_issues.where(pm_project_id: params[:pm_project_ids].split(",")) if params[:pm_project_ids].present?
@all_issues = @all_issues.where(pm_issue_type: params[:pm_issue_type].to_i) if params[:pm_issue_type].present?
@this_week_all_issues = @all_issues.where("due_date >= ? and start_date <= ?", Date.today.beginning_of_week.to_s, Date.today.end_of_week.to_s)
@this_week_all_issues = @this_week_all_issues.order('created_on desc')
@this_week_all_issues = kaminari_paginate(@this_week_all_issues)
end
def personal_issues
@enterprise_identifier = params[:enterprise_identifier] || ''
return render_error('请输入正确的用户ID.') if params[:user_id].blank?
@all_issues = Issue.joins(:issue_participants).where(issue_participants: {participant_id: params[:user_id], participant_type: ['assigned']})
@all_issues = @all_issues.where(enterprise_identifier: @enterprise_identifier, pm_issue_type: [1,2,3])
@this_week_all_issues = @all_issues.where("due_date >= ? and start_date <= ?", Date.today.beginning_of_week.to_s, Date.today.end_of_week.to_s).distinct
@this_week_all_issues = @this_week_all_issues.order('created_on desc')
@next_week_all_issues = @all_issues.where("due_date >= ? and start_date <=?", (Date.today.beginning_of_week+1.week).to_s, (Date.today.end_of_week+1.week).to_s).distinct
@next_week_all_issues = @next_week_all_issues.order('created_on desc')
this_week_page = params[:this_week_page] || 1
this_week_limit = params[:this_week_limit] || 15
@this_week_all_issues = @this_week_all_issues.page(this_week_page).per(this_week_limit)
next_week_page = params[:next_week_page] || 1
next_week_limit = params[:next_week_limit] || 15
@next_week_all_issues = @next_week_all_issues.page(next_week_page).per(next_week_limit)
end
end

View File

@ -55,14 +55,9 @@ class Api::V1::BaseController < ApplicationController
return render_forbidden if !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 end
def require_member_above
@project = load_project
return render_forbidden if !current_user.admin? && !@project.member?(current_user)
end
# 具有对仓库的访问权限 # 具有对仓库的访问权限
def require_public_and_member_above def require_public_and_member_above
@project = load_project @project = load_project
return render_forbidden if !@project.is_public && !current_user.admin? && !@project.member?(current_user) return render_forbidden if !@project.is_public && !current_user.admin? && !@project.member?(current_user)
end end
end end

View File

@ -1,37 +0,0 @@
class Api::V1::GitlinkCompetitionAppliesController < Api::V1::BaseController
def create
return render_error("请输入正确的竞赛ID") unless params[:competition_id].present?
return render_error("请输入正确的队伍ID") unless params[:team_id].present?
return render_error("请输入正确的队伍成员信息") unless params[:team_members].is_a?(Array)
params[:team_members].each do |member|
apply = GitlinkCompetitionApply.find_or_create_by(competition_id: params[:competition_id], team_id: params[:team_id], educoder_login: member[:login])
apply.competition_identifier = params[:competition_identifier]
apply.team_name = params[:team_name]
apply.school_name = member[:school_name]
apply.nickname = member[:nickname]
apply.identity = member[:identity]
apply.role = member[:role]
apply.email = member[:email]
user_info = get_user_info_by_educoder_login(member[:login])
apply.phone = user_info["phone"]
apply.save
end
render_ok
end
def get_user_info_by_educoder_login(edu_login)
req_params = { "login" => "#{edu_login}", "private_token" => "hriEn3UwXfJs3PmyXnqQ" }
api_url= "https://data.educoder.net"
client = Faraday.new(url: api_url)
response = client.public_send("get", "/api/sources/get_user_info_by_login", req_params)
result = JSON.parse(response.body)
return nil if result["status"].to_s != "0"
# login 邮箱 手机号 姓名 学校/单位
user_info = result["data"]
return user_info
end
end

View File

@ -1,5 +1,5 @@
class Api::V1::Issues::IssueTagsController < Api::V1::BaseController class Api::V1::Issues::IssueTagsController < Api::V1::BaseController
before_action :require_login, except: [:index, :pm_index] before_action :require_login, except: [:index]
before_action :require_public_and_member_above, only: [:index] before_action :require_public_and_member_above, only: [:index]
before_action :require_operate_above, only: [:create, :update, :destroy] before_action :require_operate_above, only: [:create, :update, :destroy]
@ -7,13 +7,13 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController
@issue_tags = @project.issue_tags.reorder("#{sort_by} #{sort_direction}") @issue_tags = @project.issue_tags.reorder("#{sort_by} #{sort_direction}")
@issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present? @issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
if params[:only_name] if params[:only_name]
@issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color)) @issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color))
else else
@issue_tags = kaminari_paginate(@issue_tags.includes(:project, :user, :issue_issues, :pull_request_issues)) @issue_tags = kaminari_paginate(@issue_tags.includes(:project, :user, :issue_issues, :pull_request_issues))
end end
end end
def create def create
@issue_tag = @project.issue_tags.new(issue_tag_params) @issue_tag = @project.issue_tags.new(issue_tag_params)
if @issue_tag.save! if @issue_tag.save!
render_ok render_ok

View File

@ -46,7 +46,7 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController
end end
def load_issue def load_issue
@issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || @project.issues.issue_issue.find_by_id(params[:index]) @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? if @issue.blank?
render_not_found("疑修不存在!") render_not_found("疑修不存在!")
end end

View File

@ -1,6 +1,6 @@
class Api::V1::IssuesController < Api::V1::BaseController class Api::V1::IssuesController < Api::V1::BaseController
before_action :require_login, except: [:index, :show, :show_by_id] before_action :require_login, except: [:index, :show]
before_action :require_public_and_member_above, only: [:index, :show, :show_by_id, :create, :update, :destroy] before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy]
before_action :require_operate_above, only: [:batch_update, :batch_destroy] before_action :require_operate_above, only: [:batch_update, :batch_destroy]
def index def index
@ -22,15 +22,8 @@ class Api::V1::IssuesController < Api::V1::BaseController
before_action :load_issue, only: [:show, :update, :destroy] before_action :load_issue, only: [:show, :update, :destroy]
before_action :check_issue_operate_permission, only: [:update, :destroy] before_action :check_issue_operate_permission, only: [:update, :destroy]
before_action :load_issue_by_id, only: [:show_by_id]
def show_by_id def show
@issue.associate_attachment_container
@user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user)
end
def show
@issue.associate_attachment_container
@user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user) @user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user)
end end
@ -70,14 +63,7 @@ class Api::V1::IssuesController < Api::V1::BaseController
private private
def load_issue def load_issue
@issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || @project.issues.issue_issue.find_by_id(params[:index]) @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_issue_by_id
@issue = Issue.find_by_id(params[:index])
if @issue.blank? if @issue.blank?
render_not_found("疑修不存在!") render_not_found("疑修不存在!")
end end

View File

@ -1,36 +0,0 @@
class Api::V1::PmIssuesController < ApplicationController
before_action :require_login, except: [:index, :show]
def index
project = Project.find_by_id(params[:project_id]) || Project.new( id: 0, user_id: 0, name:"pm_mm", identifier:"pm_mm" )
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
project = Project.find_by_id(params[:project_id]) || Project.new( id: 0, user_id: 0, name:"pm_mm", identifier:"pm_mm" )
@object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user)
end
private
def issue_params
params.permit(
:status_id, :priority_id, :milestone_id,
:branch_name, :start_date, :due_date,
:subject, :description, :blockchain_token_num,
:pm_project_id, :pm_sprint_id,
:issue_tag_ids => [],
:assigner_ids => [],
:attachment_ids => [],
:receivers_login => []
)
end
end

View File

@ -1,10 +0,0 @@
class Api::V1::ProjectDatasetsController < Api::V1::BaseController
def index
return render_error("请输入正确的项目id字符串") unless params[:ids].present?
ids = params[:ids].split(",")
@project_datasets = ProjectDataset.where(project_id: ids).includes(:license, :project)
@project_datasets = kaminari_unlimit_paginate(@project_datasets)
end
end

View File

@ -1,93 +0,0 @@
class Api::V1::Projects::Actions::ActionsController < Api::V1::Projects::Actions::BaseController
def new_index
@files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") rescue []
@workflows = params[:workflows].split(",") if params[:workflows].present?
@action_runs = Gitea::ActionRun.where(repo_id: @project.gpid)
disabled_config = Gitea::RepoUnit.where(repo_id: @project.gpid, type: 10)&.first&.config
disabled_workflows = disabled_config.present? ? JSON.parse(disabled_config)["DisabledWorkflows"] : []
@action_runs = @action_runs.where(id: params[:ids].split(",")) if params[:ids].present?
@action_runs = @action_runs.where(workflow_id: @workflows) if params[:workflows].present?
group_data = @action_runs.where(status: [1,2]).group(:workflow_id, :status).count
@result = []
@files.map{|i|i['name']}.each do |file|
if @workflows.present?
next if !@workflows.include?(file)
end
last_action_run = @action_runs.where(workflow_id: file).order(updated: :desc).first
last_action_run_json = last_action_run.present? ? {
pipeline_id: Action::Pipeline.find_by(pipeline_name: file, project_id: @project.id),
id: last_action_run.id,
schedule: last_action_run.schedule_id > 0,
title: last_action_run.title,
index: last_action_run.index,
status: last_action_run.status,
started: last_action_run.started,
stopped: last_action_run.stopped,
length: last_action_run.stopped-last_action_run.started,
created: last_action_run.created,
updated: last_action_run.updated,
} : {}
total = 0
success = 0
failure = 0
group_data.each do |k,v|
total += v if k[0] == file
success += v if k[0] == file && k[1] == 1
failure += v if k[0] == file && k[1] == 2
end
pipeline_type = 1
begin
content = Gitea::Repository::Entries::GetService.call(@project&.owner, @project&.identifier, URI.escape(file), ref: last_action_run.present? ? last_action_run.ref.gsub("refs/heads/","") : @project.default_branch)['content']
yaml_string = Base64.decode64(content).force_encoding("GBK").encode("UTF-8") unless Base64.decode64(content).force_encoding('UTF-8').valid_encoding?
yaml_string = Base64.decode64(content).force_encoding('UTF-8')
yml = YAML.safe_load(yaml_string)
pipeline_type = yml.name == file.to_s.gsub(".yml","").gsub(".yaml","") ? 2 : 1
rescue
Rails.logger.info("#{file}不能识别流水线类型")
end
@result << {
filename: file,
disabled: disabled_workflows.include?(file.to_s),
name: file.to_s.gsub(".yml","").gsub(".yaml","") ,
branch: last_action_run.present? ? last_action_run.ref.gsub("refs/heads/","") : @project.default_branch,
pipeline_type: pipeline_type,
total: total,
success: success,
failure: failure
}.merge(last_action_run_json)
end
render :json => {data: @result}
end
def index
begin
gitea_result = $gitea_hat_client.get_repos_actions_by_owner_repo(@project&.owner&.login, @project&.identifier)
@data = gitea_result[:data]["Workflows"]
rescue
@data = []
end
end
def disable
return render_error("请输入正确的流水线文件!") if params[:workflow].blank?
gitea_result = $gitea_hat_client.post_repos_actions_disable(@project&.owner&.login, @project&.identifier, {query: {workflow: params[:workflow]}}) rescue nil
if gitea_result
render_ok
else
render_error("禁用流水线失败")
end
end
def enable
return render_error("请输入正确的流水线文件!") if params[:workflow].blank?
gitea_result = $gitea_hat_client.post_repos_actions_enable(@project&.owner&.login, @project&.identifier, {query: {workflow: params[:workflow]}}) rescue nil
if gitea_result
render_ok
else
render_error("取消禁用流水线失败")
end
end
end

View File

@ -1,4 +0,0 @@
class Api::V1::Projects::Actions::BaseController < Api::V1::BaseController
before_action :require_public_and_member_above
end

View File

@ -1,61 +0,0 @@
class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::BaseController
def index
@files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") rescue []
@has_file = @files.select { |i| i['name'] == params[:workflow] }.present?
if @has_file
@result_object = Api::V1::Projects::Actions::Runs::ListService.call(@project, {workflow: params[:workflow], page: page, limit: limit}, current_user&.gitea_token)
@begin_num = (page.to_i - 1) * limit.to_i
end
end
def create
return render_error("请输入正确的流水线文件!") if params[:workflow].blank?
return render_error("请输入正确的分支!") if params[:ref].blank?
gitea_result = $gitea_hat_client.post_repos_actions_runs_by_owner_repo(@project&.owner&.login, @project&.identifier, {query: {workflow: params[:workflow], ref: params[:ref]}})
if gitea_result
render_ok
else
ender_error("启动流水线任务失败")
end
end
def rerun
return render_error("请输入正确的流水线记录ID") if params[:run_id].blank?
gitea_result = $gitea_hat_client.post_repos_actions_runs_rerun_by_owner_repo_run(@project&.owner&.login, @project&.identifier, params[:run_id]) rescue nil
if gitea_result
render_ok
else
render_error("重启所有流水线任务失败")
end
end
def job_rerun
return render_error("请输入正确的流水线记录ID") if params[:run_id].blank?
return render_error("请输入正确的流水线任务ID") if params[:job].blank?
gitea_result = $gitea_hat_client.post_repos_actions_runs_jobs_rerun_by_owner_repo_run_job(@project&.owner&.login, @project&.identifier, params[:run_id], params[:job]) rescue nil
if gitea_result
render_ok
else
render_error("重启流水线任务失败")
end
end
def job_show
@result_object = Api::V1::Projects::Actions::Runs::JobShowService.call(@project, params[:run_id], params[:job], params[:log_cursors], current_user&.gitea_token)
end
def job_logs
return render_error("请输入正确的流水线记录ID") if params[:run_id].blank?
return render_error("请输入正确的流水线任务ID") if params[:job].blank?
domain = GiteaService.gitea_config[:domain]
api_url = GiteaService.gitea_config[:hat_base_url]
url = "/repos/#{@owner.login}/#{@repository.identifier}/actions/runs/#{CGI.escape(params[:run_id])}/jobs/#{CGI.escape(params[:job])}/logs"
file_path = [domain, api_url, url].join
file_path = [file_path, "access_token=#{@owner&.gitea_token}"].join("?")
redirect_to file_path
end
end

View File

@ -1,79 +1,34 @@
class Api::V1::Projects::BranchesController < Api::V1::BaseController class Api::V1::Projects::BranchesController < Api::V1::BaseController
before_action :require_public_and_member_above, only: [:index, :all] before_action :require_public_and_member_above, only: [:index, :all]
def gitee
url = URI("https://gitee.com/api/v5/repos/#{params[:owner]}/#{params[:repo]}/branches?access_token=#{params[:token]}&page=#{page}&per_page=#{limit}")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
response = https.request(request)
render :json => response.read_body
end
def github
url = URI("https://api.github.com/repos/#{params[:owner]}/#{params[:repo]}/branches?page=#{page}&per_page=#{limit}")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer #{params[:token]}"
request["Accept"] = "application/vnd.github+json"
request["X-GitHub-Api-Version"] = "2022-11-28"
response = https.request(request)
render :json => response.read_body
end
def index def index
@result_object = Api::V1::Projects::Branches::ListService.call(@project, {name: params[:keyword], state: params[:state], page: page, limit: limit}, current_user&.gitea_token) @result_object = Api::V1::Projects::Branches::ListService.call(@project, {name: params[:keyword], page: page, limit: limit}, current_user&.gitea_token)
end end
def all def all
@result_object = Api::V1::Projects::Branches::AllListService.call(@project, current_user&.gitea_token) @result_object = Api::V1::Projects::Branches::AllListService.call(@project, current_user&.gitea_token)
end end
before_action :require_operate_above, only: [:create, :destroy, :restore] before_action :require_operate_above, only: [:create, :destroy]
def create def create
@result_object = Api::V1::Projects::Branches::CreateService.call(@project, branch_params, current_user&.gitea_token) @result_object = Api::V1::Projects::Branches::CreateService.call(@project, branch_params, current_user&.gitea_token)
@project.update_column(:updated_on, Time.now)
end end
def destroy def destroy
@result_object = Api::V1::Projects::Branches::DeleteService.call(@project, params[:name], current_user&.gitea_token) @result_object = Api::V1::Projects::Branches::DeleteService.call(@project, params[:name], current_user&.gitea_token)
if @result_object if @result_object
@project.update_column(:updated_on, Time.now)
# 有开启的pr需要一同关闭
# 1、删除本仓库中存在未关闭的pr,即本仓库分支1->分支2
# 2、如果是fork仓库考虑删除主仓库中存在未关闭的pr,即本仓库分支1->主分支2同时分两种删除1删除本仓库分支12删除主仓库分支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 return render_ok
else else
return render_error('删除分支失败!') return render_error('删除分支失败!')
end end
end end
def restore
@result_object = Api::V1::Projects::Branches::RestoreService.call(@project, params[:branch_id], params[:branch_name], current_user&.gitea_token)
if @result_object
@project.update_column(:updated_on, Time.now)
return render_ok
else
return render_error('恢复分支失败!')
end
end
before_action :require_manager_above, only: [:update_default_branch] before_action :require_manager_above, only: [:update_default_branch]
def update_default_branch def update_default_branch
@result_object = Api::V1::Projects::Branches::UpdateDefaultBranchService.call(@project, params[:name], current_user&.gitea_token) @result_object = Api::V1::Projects::Branches::UpdateDefaultBranchService.call(@project, params[:name], current_user&.gitea_token)
if @result_object if @result_object
@project.update_column(:updated_on, Time.now)
return render_ok return render_ok
else else
return render_error('更新默认分支失败!') return render_error('更新默认分支失败!')
@ -84,19 +39,4 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController
def branch_params def branch_params
params.require(:branch).permit(:new_branch_name, :old_branch_name) params.require(:branch).permit(:new_branch_name, :old_branch_name)
end 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 end

Some files were not shown because too many files have changed in this diff Show More