diff --git a/app/controllers/api/pm/weekly_issues_controller.rb b/app/controllers/api/pm/weekly_issues_controller.rb index 4510e5ff7..88bd06d75 100644 --- a/app/controllers/api/pm/weekly_issues_controller.rb +++ b/app/controllers/api/pm/weekly_issues_controller.rb @@ -5,9 +5,11 @@ class Api::Pm::WeeklyIssuesController < Api::Pm::BaseController 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 + @weekly_begin_date = params[:weekly_begin_date].to_time || Date.today.beginning_of_week rescue Date.today.beginning_of_week + @weekly_end_date = params[:weekly_end_date].to_time || Date.today.end_of_week rescue Date.today.end_of_week + @this_week_all_issues = @all_issues.where("due_date >= ? and start_date <= ?", @weekly_begin_date.to_s, @weekly_end_date.to_s).distinct @this_week_all_issues = @this_week_all_issues.order('created_on desc').pm_includes - @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 = @all_issues.where("due_date >= ? and start_date <=?", (@weekly_begin_date+1.week).to_s, (@weekly_end_date+1.week).to_s).distinct @next_week_all_issues = @next_week_all_issues.order('created_on desc').pm_includes @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) @@ -27,7 +29,9 @@ class Api::Pm::WeeklyIssuesController < Api::Pm::BaseController @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) + @weekly_begin_date = params[:weekly_begin_date] || Date.today.beginning_of_week.to_s + @weekly_end_date = params[:weekly_end_date] || Date.today.end_of_week.to_s + @this_week_all_issues = @all_issues.where("due_date >= ? and start_date <= ?", @weekly_begin_date, @weekly_end_date) @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| diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index d9db4b99c..38e10d5f5 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -37,6 +37,11 @@ class Api::V1::BaseController < ApplicationController params.fetch(:page, 1) end + def load_organization + @organization = Organization.find_by(login: params[:owner]) || Organization.find_by(id: params[:owner]) + return render_not_found("组织不存在") if @organization.nil? + end + # 具有对仓库的管理权限 def require_manager_above @project = load_project diff --git a/app/controllers/api/v1/organizations/sync_repositories_controller.rb b/app/controllers/api/v1/organizations/sync_repositories_controller.rb new file mode 100644 index 000000000..d02dcd40c --- /dev/null +++ b/app/controllers/api/v1/organizations/sync_repositories_controller.rb @@ -0,0 +1,42 @@ +class Api::V1::Organizations::SyncRepositoriesController < Api::V1::BaseController + before_action :load_organization, only: [:create] + + def create + return render_error("请输入正确的外部组织login") unless params[:external_login].present? + # 拉取外部组织仓库列表 + url = URI("https://api.github.com/orgs/#{params[:external_login]}/repos?page=#{params[:page]}&per_page=#{params[:limit]}") + https = Net::HTTP.new(url.host, url.port) + https.use_ssl = true + request = Net::HTTP::Get.new(url) + request["Authorization"] = "Bearer #{params[:external_token]}" + response = https.request(request) + if response.code == "200" + repos = JSON.parse(response.body) + repos.each do |repo| + # 检查是否已经存在该仓库 + @project = @organization.projects.find_by(identifier: repo["name"]) + if @project.present? + if @project.repository.mirror.failed? + @project.destroy! + mirror_params = {name: repo["name"], user_id: @organization.id, description: repo["description"], repository_name: repo["name"], auth_token: params[:external_token], clone_addr: repo["clone_url"]} + @project = ::Projects::MigrateService.call(current_user, mirror_params) + end + @project.update_column(:created_on, repo['created_at'].to_time) + @project.update_column(:updated_on, repo['updated_at'].to_time) + next + else + mirror_params = {name: repo["name"], user_id: @organization.id, description: repo["description"], repository_name: repo["name"], auth_token: params[:external_token], clone_addr: repo["clone_url"]} + @project = ::Projects::MigrateService.call(current_user, mirror_params) + @project.update_column(:created_on, repo['created_at'].to_time) + @project.update_column(:updated_on, repo['updated_at'].to_time) + end + end + end + end + + private + def sync_repository_params + params.permit(:external_token) + end + +end \ No newline at end of file diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 46145abf3..cf1198f1f 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -37,6 +37,7 @@ class AttachmentsController < ApplicationController Rails.logger.info("request.host===#{request.host},request.referer===#{request.referer}") tip_exception(403, "你没有权限访问") if request.host.present? && !request.referer.to_s.include?(request.host.to_s.gsub("www.","")) normal_status(-1, "参数缺失") if params[:download_url].blank? + tip_exception('不可访问') if params[:download_url].to_s.include?("chinese_dictionary.txt") url = base_url.starts_with?("https:") ? params[:download_url].to_s.gsub("http:", "https:") : params[:download_url].to_s if url.starts_with?(base_url) && !url.starts_with?("#{base_url}/repo") domain = GiteaService.gitea_config[:domain] diff --git a/app/controllers/competition_infos_controller.rb b/app/controllers/competition_infos_controller.rb index 93e8e74e7..4cbacdc99 100644 --- a/app/controllers/competition_infos_controller.rb +++ b/app/controllers/competition_infos_controller.rb @@ -163,7 +163,7 @@ class CompetitionInfosController < ApplicationController member_array << member end send_data["members"] = member_array - login_index = column_names.index("用户标识") + login_index = column_names.index("用户标识*") user = User.find_by(login:row[login_index]) || User.find_by(phone: send_data['phone']) if user.present? begin @@ -191,7 +191,7 @@ class CompetitionInfosController < ApplicationController format.xlsx { set_export_cookies enroll_fields = @competition_info.enroll_fields.except("ID") - @table_columns = ["用户标识"] | enroll_fields.keys + @table_columns = ["用户标识*"] | enroll_fields.keys if EduSetting.get("is_local") == "true" @table_columns = @table_columns + ["成员姓名", "成员单位", "成员手机号"] else diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 7d76dbc95..7aa69531d 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -7,7 +7,7 @@ class MainController < ApplicationController #before_action :sso_login, only: [:index] def first_stamp - render :json => { status: 0, message: Time.now.to_i } + render :json => { status: 0, message: Time.now.to_i, online: UserOnline.count } end def test_404 diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 27580593d..7b360f289 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -85,7 +85,7 @@ class RepositoriesController < ApplicationController def sub_entries file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) - + tip_exception('不可访问') if params[:filepath].to_s.include?("chinese_dictionary.txt") if @project.educoder? if params[:type] === 'file' @sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri) @@ -308,6 +308,7 @@ class RepositoriesController < ApplicationController def raw domain = GiteaService.gitea_config[:domain] api_url = GiteaService.gitea_config[:base_url] + tip_exception('不可访问') if params[:filepath].to_s.include?("chinese_dictionary.txt") url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{CGI.escape(params[:filepath])}?ref=#{CGI.escape(params[:ref])}" file_path = [domain, api_url, url].join diff --git a/app/controllers/users/organizations_controller.rb b/app/controllers/users/organizations_controller.rb index 2d80adb9b..000d33f93 100644 --- a/app/controllers/users/organizations_controller.rb +++ b/app/controllers/users/organizations_controller.rb @@ -9,7 +9,7 @@ class Users::OrganizationsController < Users::BaseController @organizations = observed_user.organizations.with_visibility("common") end - @organizations = @organizations.ransack(login_cont: params[:search]).result if params[:search].present? + @organizations = @organizations.ransack(login_or_nickname_cont: params[:search]).result if params[:search].present? @home_top_ids = @organizations.joins(:home_top_settings).where(home_top_settings: {user_id: observed_user.id}).order("home_top_settings.created_at asc").pluck(:id) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index b3d1bda5d..125b5402e 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -244,7 +244,9 @@ module RepositoriesHelper Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}") content = entry['content'].present? ? entry['content'] : Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] # readme_render_decode64_content(content, owner, repo, ref) - new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name']) + text = new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name']) + text = "该内容不合规,请修改。" if text.present? && !HarmoniousDictionary.clean?(text) + text end def decode64_content(entry, owner, repo, ref, path=nil) @@ -253,9 +255,13 @@ module RepositoriesHelper content = entry['content'].present? ? entry['content'] : Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] # Rails.logger.info("content===#{content}") return Base64.decode64(content).force_encoding("GBK").encode("UTF-8") unless Base64.decode64(content).force_encoding('UTF-8').valid_encoding? - return Base64.decode64(content).force_encoding('UTF-8') + text = Base64.decode64(content).force_encoding('UTF-8') + text = "该内容不合规,请修改。" if text.present? && !HarmoniousDictionary.clean?(text) + text elsif entry['is_text_file'] == true - return render_decode64_content(entry['content']) + text = render_decode64_content(entry['content']) + text = "该内容不合规,请修改。" if text.present? && !HarmoniousDictionary.clean?(text) + text else file_type = File.extname(entry['name'].to_s)[1..-1] if image_type?(file_type) @@ -264,7 +270,9 @@ module RepositoriesHelper if download_type(file_type) return entry['content'] end - render_decode64_content(entry['content']) + text = render_decode64_content(entry['content']) + text = "该内容不合规,请修改。" if text.present? && !HarmoniousDictionary.clean?(text) + text end end diff --git a/app/services/api/v1/projects/commits/recent_service.rb b/app/services/api/v1/projects/commits/recent_service.rb index 9a226d9f2..09a1ee94e 100644 --- a/app/services/api/v1/projects/commits/recent_service.rb +++ b/app/services/api/v1/projects/commits/recent_service.rb @@ -25,7 +25,9 @@ class Api::V1::Projects::Commits::RecentService < ApplicationService param = { access_token: token, page: page, - limit: limit + limit: limit, + stats: false, + files: false } param.merge!(keyword: keyword) if keyword.present? diff --git a/app/views/projects/_project_detail.json.jbuilder b/app/views/projects/_project_detail.json.jbuilder index 292de99d3..5c702ad7b 100644 --- a/app/views/projects/_project_detail.json.jbuilder +++ b/app/views/projects/_project_detail.json.jbuilder @@ -31,8 +31,8 @@ json.author do user = project.owner json.name user.try(:show_real_name) json.type user&.type - json.login user&.login - json.image_url url_to_avatar(user) + json.login user.login + json.image_url url_to_avatar(user).present? ? url_to_avatar(user) : User::Avatar.get_letter_avatar_url(user.login) end end diff --git a/config/harmonious_dictionary/chinese_dictionary.txt b/config/harmonious_dictionary/chinese_dictionary.txt index 386534f3f..fe884de46 100644 --- a/config/harmonious_dictionary/chinese_dictionary.txt +++ b/config/harmonious_dictionary/chinese_dictionary.txt @@ -638,7 +638,6 @@ a级情片 法仑 法伦 法轮 -法论 反封锁技术 反腐败论坛 反共 @@ -1252,7 +1251,6 @@ fa轮 指点江山论坛 中俄边界 中功 -中共 中国威胁论 中国问题论坛 中国之春 diff --git a/config/harmonious_dictionary/harmonious.hash b/config/harmonious_dictionary/harmonious.hash index afab436f7..019e01051 100644 Binary files a/config/harmonious_dictionary/harmonious.hash and b/config/harmonious_dictionary/harmonious.hash differ diff --git a/config/routes/api.rb b/config/routes/api.rb index 089ecbaf6..2862abb03 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -98,6 +98,9 @@ defaults format: :json do patch :update_phone end end + scope module: :organizations do + resources :sync_repositories, only: [:create] + end scope module: :users do resources :projects, only: [:index] resources :feedbacks, only: [:create] diff --git a/db/migrate/202506274325719_add_project_index_gpid.rb b/db/migrate/202506274325719_add_project_index_gpid.rb new file mode 100644 index 000000000..1d680ce3c --- /dev/null +++ b/db/migrate/202506274325719_add_project_index_gpid.rb @@ -0,0 +1,5 @@ +class AddProjectIndexGpid < ActiveRecord::Migration[5.2] + def change + add_index :projects, :gpid + end +end