From b4a5f685be84c8c4f1cde2123785a4e75d0ef2c7 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 12 Jun 2023 17:49:32 +0800 Subject: [PATCH 01/30] =?UTF-8?q?fixed=20=E5=8F=91=E9=80=81=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/send_template_message_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/send_template_message_job.rb b/app/jobs/send_template_message_job.rb index 05572d451..1df1d8c7d 100644 --- a/app/jobs/send_template_message_job.rb +++ b/app/jobs/send_template_message_job.rb @@ -8,7 +8,7 @@ class SendTemplateMessageJob < ApplicationJob receivers_id, template_id, props = args[0], args[1], args[2] template = MessageTemplate.find_by_id(template_id) return unless template.present? - receivers = User.where(id: receivers_id).or(User.where(mail: receivers_id)) + receivers = User.where("id in(?)", receivers_id).or(User.where(mail: receivers_id)) not_exists_receivers = receivers_id - receivers.pluck(:id) - receivers.pluck(:mail) receivers_string, content, notification_url = MessageTemplate::CustomTip.get_message_content(receivers, template, props) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {receivers_id: receivers_id, template_id: template_id, props: props}) From cfaa5301ea40635813bd2164741c3de806bff7c5 Mon Sep 17 00:00:00 2001 From: chenjing Date: Tue, 13 Jun 2023 15:30:16 +0800 Subject: [PATCH 02/30] cla init --- .../javascripts/admins/organizations/index.js | 43 +++++++++++ app/assets/javascripts/organizations/clas.js | 2 + app/assets/javascripts/users/clas.js | 2 + .../stylesheets/organizations/clas.scss | 3 + app/assets/stylesheets/users/clas.scss | 3 + .../admins/message_templates_controller.rb | 2 +- .../admins/organizations_controller.rb | 13 ++++ .../organizations/clas_controller.rb | 63 +++++++++++++++ app/controllers/users/clas_controller.rb | 22 ++++++ app/forms/organizations/create_cla_form.rb | 6 ++ app/forms/users/user_cla_form.rb | 6 ++ app/helpers/organizations/clas_helper.rb | 2 + app/helpers/users/clas_helper.rb | 2 + app/models/attachment.rb | 77 ++++++++++--------- app/models/ci/user.rb | 13 ++-- app/models/cla.rb | 38 +++++++++ app/models/commit_log.rb | 23 ++++++ app/models/edu_setting.rb | 31 ++++---- app/models/gitea/public_key.rb | 22 ++++++ app/models/gitea/pull.rb | 2 + app/models/gitea/webhook.rb | 31 +++++++- app/models/gitea/webhook_task.rb | 18 ++++- app/models/issue.rb | 3 +- app/models/issue_participant.rb | 17 ++++ app/models/issue_tag.rb | 23 +++--- app/models/laboratory.rb | 1 - app/models/mark_file.rb | 20 +++++ .../message_template/issue_creator_expire.rb | 16 +++- app/models/organization.rb | 24 ++++-- app/models/organization_extension.rb | 2 + app/models/praise_tread.rb | 33 ++++---- app/models/project.rb | 5 +- app/models/repository.rb | 1 + app/models/system_notification_history.rb | 14 ++-- app/models/template_message_setting.rb | 6 +- .../create_or_assign.rb | 6 +- .../manage_project.rb | 6 +- app/models/template_message_setting/normal.rb | 6 +- .../template_message_setting/watch_project.rb | 6 +- app/models/timeable_visit_record.rb | 2 +- app/models/token.rb | 31 ++++---- app/models/topic.rb | 1 - app/models/topic/activity_forum.rb | 1 - app/models/topic/banner.rb | 1 - app/models/topic/card.rb | 1 - app/models/topic/cooperator.rb | 1 - app/models/topic/excellent_project.rb | 1 - app/models/topic/experience_forum.rb | 1 - app/models/topic/glcc_news.rb | 3 +- app/models/topic/pinned_forum.rb | 1 - app/models/user.rb | 5 ++ app/models/user_action.rb | 7 +- app/models/user_agent.rb | 5 +- app/models/user_cla.rb | 35 +++++++++ app/models/user_extension.rb | 2 +- app/models/version.rb | 2 +- app/models/version_release.rb | 4 +- .../organizations/shared/_org_list.html.erb | 3 +- app/views/admins/organizations/show.html.erb | 3 + .../organizations/clas/_detail.json.jbuilder | 5 ++ .../organizations/clas/create.json.jbuilder | 1 + .../organizations/clas/index.json.jbuilder | 4 + .../organizations/clas/show.json.jbuilder | 6 ++ .../organizations/clas/update.json.jbuilder | 1 + .../organizations/_detail.json.jbuilder | 3 +- app/views/users/clas/_detail.json.jbuilder | 8 ++ app/views/users/clas/index.json.jbuilder | 3 + app/views/users/clas/show.json.jbuilder | 1 + config/routes.rb | 10 ++- db/migrate/20230612020506_add_cla_to_users.rb | 5 ++ db/migrate/20230612031416_create_clas.rb | 13 ++++ db/migrate/20230612031448_create_user_clas.rb | 12 +++ .../organizations/clas_controller_spec.rb | 5 ++ .../controllers/users/clas_controller_spec.rb | 5 ++ .../helpers/organizations/clas_helper_spec.rb | 15 ++++ spec/helpers/users/clas_helper_spec.rb | 15 ++++ spec/models/cla_spec.rb | 5 ++ spec/models/user_cla_spec.rb | 5 ++ 78 files changed, 682 insertions(+), 163 deletions(-) create mode 100644 app/assets/javascripts/admins/organizations/index.js create mode 100644 app/assets/javascripts/organizations/clas.js create mode 100644 app/assets/javascripts/users/clas.js create mode 100644 app/assets/stylesheets/organizations/clas.scss create mode 100644 app/assets/stylesheets/users/clas.scss create mode 100644 app/controllers/organizations/clas_controller.rb create mode 100644 app/controllers/users/clas_controller.rb create mode 100644 app/forms/organizations/create_cla_form.rb create mode 100644 app/forms/users/user_cla_form.rb create mode 100644 app/helpers/organizations/clas_helper.rb create mode 100644 app/helpers/users/clas_helper.rb create mode 100644 app/models/cla.rb create mode 100644 app/models/user_cla.rb create mode 100644 app/views/organizations/clas/_detail.json.jbuilder create mode 100644 app/views/organizations/clas/create.json.jbuilder create mode 100644 app/views/organizations/clas/index.json.jbuilder create mode 100644 app/views/organizations/clas/show.json.jbuilder create mode 100644 app/views/organizations/clas/update.json.jbuilder create mode 100644 app/views/users/clas/_detail.json.jbuilder create mode 100644 app/views/users/clas/index.json.jbuilder create mode 100644 app/views/users/clas/show.json.jbuilder create mode 100644 db/migrate/20230612020506_add_cla_to_users.rb create mode 100644 db/migrate/20230612031416_create_clas.rb create mode 100644 db/migrate/20230612031448_create_user_clas.rb create mode 100644 spec/controllers/organizations/clas_controller_spec.rb create mode 100644 spec/controllers/users/clas_controller_spec.rb create mode 100644 spec/helpers/organizations/clas_helper_spec.rb create mode 100644 spec/helpers/users/clas_helper_spec.rb create mode 100644 spec/models/cla_spec.rb create mode 100644 spec/models/user_cla_spec.rb diff --git a/app/assets/javascripts/admins/organizations/index.js b/app/assets/javascripts/admins/organizations/index.js new file mode 100644 index 000000000..b301e537d --- /dev/null +++ b/app/assets/javascripts/admins/organizations/index.js @@ -0,0 +1,43 @@ +$(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 $action = $(this); + + var userId = $action.data('id'); + $.ajax({ + url: '/admins/organizations/' + userId + '/open_cla', + method: 'POST', + dataType: 'json', + success: function() { + showSuccessNotify(); + } + }); + }); + + // organizations close cla + $('.organizations-list-container').on('click', '.close-cla-action', function(){ + var $action = $(this); + + var userId = $action.data('id'); + $.ajax({ + url: '/admins/organizations/' + userId + '/close_cla', + method: 'POST', + dataType: 'json', + success: function() { + showSuccessNotify(); + } + }); + }); + + + } +}); \ No newline at end of file diff --git a/app/assets/javascripts/organizations/clas.js b/app/assets/javascripts/organizations/clas.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/organizations/clas.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/users/clas.js b/app/assets/javascripts/users/clas.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/users/clas.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/organizations/clas.scss b/app/assets/stylesheets/organizations/clas.scss new file mode 100644 index 000000000..1716eff69 --- /dev/null +++ b/app/assets/stylesheets/organizations/clas.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the organizations/clas controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/users/clas.scss b/app/assets/stylesheets/users/clas.scss new file mode 100644 index 000000000..c5dd66bb9 --- /dev/null +++ b/app/assets/stylesheets/users/clas.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the users/clas controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/admins/message_templates_controller.rb b/app/controllers/admins/message_templates_controller.rb index 87a3ccfe7..6a5000c24 100644 --- a/app/controllers/admins/message_templates_controller.rb +++ b/app/controllers/admins/message_templates_controller.rb @@ -49,7 +49,7 @@ class Admins::MessageTemplatesController < Admins::BaseController def message_template_params # type = @message_template.present? ? @message_template.type : "MessageTemplate::CustomTip" # params.require(type.split("::").join("_").underscore.to_sym).permit! - params.require(:message_template).permit! + params.require(:message_template_custom_tip).permit! end def get_template diff --git a/app/controllers/admins/organizations_controller.rb b/app/controllers/admins/organizations_controller.rb index 35fb4dee8..9ca23ba38 100644 --- a/app/controllers/admins/organizations_controller.rb +++ b/app/controllers/admins/organizations_controller.rb @@ -9,6 +9,19 @@ class Admins::OrganizationsController < Admins::BaseController @orgs = paginate orgs end + + def open_cla + @org = Organization.find(params[:id]) + @org.open_cla! + render_ok + end + + def close_cla + @org = Organization.find(params[:id]) + @org.close_cla! + render_ok + end + def show end diff --git a/app/controllers/organizations/clas_controller.rb b/app/controllers/organizations/clas_controller.rb new file mode 100644 index 000000000..369fb435c --- /dev/null +++ b/app/controllers/organizations/clas_controller.rb @@ -0,0 +1,63 @@ +class Organizations::ClasController < Organizations::BaseController + before_action :load_organization + before_action :load_cla, only: [:show, :update, :destroy] + def index + @cla = @organization.cla + end + + def show + end + + def create + tip_exception("您的组织还未拥有创建CLA权限,请联系管理员") if @organization.cla == false + ActiveRecord::Base.transaction do + if @organization.cla.present? + return tip_exception("组织已存在CLA!") + else + Organizations::CreateClaForm.new(cla_params).validate! + @cla = Cla.build(cla_params) + end + end + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + end + + def update + ActiveRecord::Base.transaction do + Organizations::CreateClaForm.new(cla_params).validate! + @cla.update(cla_params) + end + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + end + + def destroy + tip_exception("组织CLA已被签署,无法删除") if @cla.user_clas.size > 0 + ActiveRecord::Base.transaction do + @cla.destroy! + end + render_ok + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + end + + + private + def cla_params + params.permit(:name, :key, :content, :organization_id, :pr_need) + end + + def load_organization + @organization = Organization.find_by(login: params[:organization_id]) || Organization.find_by(id: params[:organization_id]) + return render_not_found("组织不存在") if @organization.nil? + return render_forbidden("没有查看组织的权限") if org_limited_condition || org_privacy_condition + end + + def load_cla + @cla = Cla.find_by!(organization:params[:organization_id], key: params[:id]) + end + +end diff --git a/app/controllers/users/clas_controller.rb b/app/controllers/users/clas_controller.rb new file mode 100644 index 000000000..e3a4de0c2 --- /dev/null +++ b/app/controllers/users/clas_controller.rb @@ -0,0 +1,22 @@ +class Users::ClasController < Users::BaseController + def index + @user_clas = UserCla.where(user: @_observed_user) + end + + def create + tip_exception("已签署过该组织CLA!") if @_observed_user.user_clas.where(cla_id: params[:cla_id]).size > 0 + ActiveRecord::Base.transaction do + Users::UserClaForm.new(user_cla_params).validate! + @user_cla = UserCla.build(user_cla_params, @_observed_user.id) + end + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + end + private + + def user_cla_params + params.permit(:email, :real_name, :cla_id) + end + +end diff --git a/app/forms/organizations/create_cla_form.rb b/app/forms/organizations/create_cla_form.rb new file mode 100644 index 000000000..e77053e9f --- /dev/null +++ b/app/forms/organizations/create_cla_form.rb @@ -0,0 +1,6 @@ +class Organizations::CreateClaForm < BaseForm + KEY_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾 + attr_accessor :name, :key, :content, :organization_id, :pr_need + validates :name, :organization_id , :key, presence: true + validates :name, format: { with: KEY_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } +end \ No newline at end of file diff --git a/app/forms/users/user_cla_form.rb b/app/forms/users/user_cla_form.rb new file mode 100644 index 000000000..24f615591 --- /dev/null +++ b/app/forms/users/user_cla_form.rb @@ -0,0 +1,6 @@ +class Users::UserClaForm + include ActiveModel::Model + attr_accessor :email, :real_name, :cla_id + validates :email, presence: true, format: { with: CustomRegexp::EMAIL } + end + \ No newline at end of file diff --git a/app/helpers/organizations/clas_helper.rb b/app/helpers/organizations/clas_helper.rb new file mode 100644 index 000000000..38c1531c3 --- /dev/null +++ b/app/helpers/organizations/clas_helper.rb @@ -0,0 +1,2 @@ +module Organizations::ClasHelper +end diff --git a/app/helpers/users/clas_helper.rb b/app/helpers/users/clas_helper.rb new file mode 100644 index 000000000..55e326d0d --- /dev/null +++ b/app/helpers/users/clas_helper.rb @@ -0,0 +1,2 @@ +module Users::ClasHelper +end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 0cbf6fb0f..0c056f60c 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1,41 +1,42 @@ -# == Schema Information -# -# Table name: attachments -# -# id :integer not null, primary key -# container_id :integer -# container_type :string(30) -# filename :string(255) default(""), not null -# disk_filename :string(255) default(""), not null -# filesize :integer default("0"), not null -# content_type :string(255) default("") -# digest :string(60) default(""), not null -# downloads :integer default("0"), not null -# author_id :integer default("0"), not null -# created_on :datetime -# description :text(65535) -# disk_directory :string(255) -# attachtype :integer default("1") -# is_public :integer default("1") -# copy_from :string(255) -# quotes :integer default("0") -# is_publish :integer default("1") -# publish_time :datetime -# resource_bank_id :integer -# unified_setting :boolean default("1") -# cloud_url :string(255) default("") -# course_second_category_id :integer default("0") -# delay_publish :boolean default("0") -# link :string(255) -# clone_id :integer -# -# Indexes -# -# index_attachments_on_author_id (author_id) -# index_attachments_on_clone_id (clone_id) -# index_attachments_on_container_id_and_container_type (container_id,container_type) -# index_attachments_on_created_on (created_on) -# +# == Schema Information +# +# Table name: attachments +# +# id :integer not null, primary key +# container_id :integer +# container_type :string(30) +# filename :string(255) default(""), not null +# disk_filename :string(255) default(""), not null +# filesize :integer default("0"), not null +# content_type :string(255) default("") +# digest :string(60) default(""), not null +# downloads :integer default("0"), not null +# author_id :integer default("0"), not null +# created_on :datetime +# description :text(65535) +# disk_directory :string(255) +# attachtype :integer default("1") +# is_public :integer default("1") +# copy_from :integer +# quotes :integer default("0") +# is_publish :integer default("1") +# publish_time :datetime +# resource_bank_id :integer +# unified_setting :boolean default("1") +# cloud_url :string(255) default("") +# course_second_category_id :integer default("0") +# delay_publish :boolean default("0") +# +# Indexes +# +# index_attachments_on_author_id (author_id) +# index_attachments_on_container_id_and_container_type (container_id,container_type) +# index_attachments_on_course_second_category_id (course_second_category_id) +# index_attachments_on_created_on (created_on) +# index_attachments_on_is_public (is_public) +# index_attachments_on_quotes (quotes) +# + diff --git a/app/models/ci/user.rb b/app/models/ci/user.rb index e4a4d0623..be151dee2 100644 --- a/app/models/ci/user.rb +++ b/app/models/ci/user.rb @@ -39,15 +39,15 @@ # business :boolean default("0") # profile_completed :boolean default("0") # laboratory_id :integer -# is_shixun_marker :boolean default("0") -# admin_visitable :boolean default("0") -# collaborator :boolean default("0") +# platform :string(255) default("0") +# gitea_token :string(255) # gitea_uid :integer +# is_shixun_marker :boolean default("0") # is_sync_pwd :boolean default("1") # watchers_count :integer default("0") # devops_step :integer default("0") -# gitea_token :string(255) -# platform :string(255) +# sign_cla :boolean default("0") +# cla :boolean default("0") # # Indexes # @@ -56,8 +56,7 @@ # index_users_on_homepage_teacher (homepage_teacher) # index_users_on_laboratory_id (laboratory_id) # index_users_on_login (login) UNIQUE -# index_users_on_mail (mail) UNIQUE -# index_users_on_phone (phone) UNIQUE +# index_users_on_mail (mail) # index_users_on_type (type) # diff --git a/app/models/cla.rb b/app/models/cla.rb new file mode 100644 index 000000000..d42726658 --- /dev/null +++ b/app/models/cla.rb @@ -0,0 +1,38 @@ +# == Schema Information +# +# Table name: clas +# +# id :integer not null, primary key +# name :string(255) not null +# key :string(255) not null +# content :text(65535) +# organization_id :integer not null +# pr_need :boolean default("0") +# count :integer default("0") +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_clas_on_key (key) +# index_clas_on_organization_id (organization_id) +# + +class Cla < ApplicationRecord + has_many :user_clas, :dependent => :destroy + has_many :users, through: :user_clas + belongs_to :organization + + def to_param + self.key.parameterize + end + + def self.build(params) + self.create!(organization_id: params[:organization_id], + name: params[:name], + key: params[:key], + content: params[:content], + pr_need: params[:pr_need] + ) + end +end diff --git a/app/models/commit_log.rb b/app/models/commit_log.rb index def2846fa..d351e6f48 100644 --- a/app/models/commit_log.rb +++ b/app/models/commit_log.rb @@ -1,3 +1,26 @@ +# == Schema Information +# +# Table name: commit_logs +# +# id :integer not null, primary key +# user_id :integer +# project_id :integer +# repository_id :integer +# name :string(255) +# full_name :string(255) +# commit_id :string(255) +# ref :string(255) +# message :text(65535) +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_commit_logs_on_commit_id (commit_id) +# index_commit_logs_on_project_id (project_id) +# index_commit_logs_on_user_id (user_id) +# + class CommitLog < ApplicationRecord belongs_to :user belongs_to :project diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index 22575ff15..f4a89c09b 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -1,18 +1,19 @@ -# == Schema Information -# -# Table name: edu_settings -# -# id :integer not null, primary key -# name :string(255) -# value :string(255) -# created_at :datetime not null -# updated_at :datetime not null -# description :string(255) -# -# Indexes -# -# index_edu_settings_on_name (name) UNIQUE -# +# == Schema Information +# +# Table name: edu_settings +# +# id :integer not null, primary key +# name :string(255) +# value :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# description :string(255) +# +# Indexes +# +# index_edu_settings_on_name (name) UNIQUE +# + class EduSetting < ApplicationRecord after_commit :expire_value_cache diff --git a/app/models/gitea/public_key.rb b/app/models/gitea/public_key.rb index bb2192358..a9962dc67 100644 --- a/app/models/gitea/public_key.rb +++ b/app/models/gitea/public_key.rb @@ -1,3 +1,25 @@ +# == Schema Information +# +# Table name: public_key +# +# id :integer not null, primary key +# owner_id :integer not null +# name :string(255) not null +# fingerprint :string(255) not null +# content :text(16777215) not null +# mode :integer default("2"), not null +# type :integer default("1"), not null +# login_source_id :integer default("0"), not null +# created_unix :integer +# updated_unix :integer +# verified :boolean default("0"), not null +# +# Indexes +# +# IDX_public_key_fingerprint (fingerprint) +# IDX_public_key_owner_id (owner_id) +# + class Gitea::PublicKey < Gitea::Base self.inheritance_column = nil # FIX The single-table inheritance mechanism failed # establish_connection :gitea_db diff --git a/app/models/gitea/pull.rb b/app/models/gitea/pull.rb index 7adb8c366..70e61f5fa 100644 --- a/app/models/gitea/pull.rb +++ b/app/models/gitea/pull.rb @@ -16,10 +16,12 @@ # head_branch :string(255) # base_branch :string(255) # merge_base :string(40) +# allow_maintainer_edit :boolean default("0"), not null # has_merged :boolean # merged_commit_id :string(40) # merger_id :integer # merged_unix :integer +# flow :integer default("0"), not null # # Indexes # diff --git a/app/models/gitea/webhook.rb b/app/models/gitea/webhook.rb index f60f56788..ec1c836c4 100644 --- a/app/models/gitea/webhook.rb +++ b/app/models/gitea/webhook.rb @@ -1,3 +1,32 @@ +# == Schema Information +# +# Table name: webhook +# +# id :integer not null, primary key +# repo_id :integer +# org_id :integer +# is_system_webhook :boolean +# url :text(65535) +# http_method :string(255) +# content_type :integer +# secret :text(65535) +# events :text(65535) +# is_active :boolean +# type :string(16) +# meta :text(65535) +# last_status :integer +# created_unix :integer +# updated_unix :integer +# +# Indexes +# +# IDX_webhook_created_unix (created_unix) +# IDX_webhook_is_active (is_active) +# IDX_webhook_org_id (org_id) +# IDX_webhook_repo_id (repo_id) +# IDX_webhook_updated_unix (updated_unix) +# + class Gitea::Webhook < Gitea::Base serialize :events, JSON self.inheritance_column = nil @@ -10,4 +39,4 @@ class Gitea::Webhook < Gitea::Base enum hook_task_type: {gogs: 1, slack: 2, gitea: 3, discord: 4, dingtalk: 5, telegram: 6, msteams: 7, feishu: 8, matrix: 9} enum last_status: {waiting: 0, succeed: 1, fail: 2} enum content_type: {json: 1, form: 2} -end \ No newline at end of file +end diff --git a/app/models/gitea/webhook_task.rb b/app/models/gitea/webhook_task.rb index 7e9bc68a7..b612816ba 100644 --- a/app/models/gitea/webhook_task.rb +++ b/app/models/gitea/webhook_task.rb @@ -1,3 +1,19 @@ +# == Schema Information +# +# Table name: hook_task +# +# id :integer not null, primary key +# hook_id :integer +# uuid :string(255) +# payload_content :text(4294967295) +# event_type :string(255) +# is_delivered :boolean +# delivered :integer +# is_succeed :boolean +# request_content :text(4294967295) +# response_content :text(4294967295) +# + class Gitea::WebhookTask < Gitea::Base serialize :payload_content, JSON serialize :request_content, JSON @@ -11,4 +27,4 @@ class Gitea::WebhookTask < Gitea::Base enum type: {gogs: 1, slack: 2, gitea: 3, discord: 4, dingtalk: 5, telegram: 6, msteams: 7, feishu: 8, matrix: 9} -end \ No newline at end of file +end diff --git a/app/models/issue.rb b/app/models/issue.rb index e12f667db..eae5acf6f 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -5,7 +5,7 @@ # id :integer not null, primary key # tracker_id :integer not null # project_id :integer not null -# subject :string(255) default(""), not null +# subject :string(255) # description :text(4294967295) # due_date :date # category_id :integer @@ -33,6 +33,7 @@ # issue_classify :string(255) # ref_name :string(255) # branch_name :string(255) +# blockchain_token_num :integer # # Indexes # diff --git a/app/models/issue_participant.rb b/app/models/issue_participant.rb index fa7be6980..d756b28a2 100644 --- a/app/models/issue_participant.rb +++ b/app/models/issue_participant.rb @@ -1,3 +1,20 @@ +# == Schema Information +# +# Table name: issue_participants +# +# id :integer not null, primary key +# issue_id :integer +# participant_id :integer +# participant_type :integer default("0") +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_issue_participants_on_issue_id (issue_id) +# index_issue_participants_on_participant_id (participant_id) +# + class IssueParticipant < ApplicationRecord belongs_to :issue diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index b4ee673f7..7251e98f2 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -2,17 +2,18 @@ # # Table name: issue_tags # -# id :integer not null, primary key -# name :string(255) -# description :string(255) -# color :string(255) -# user_id :integer -# project_id :integer -# issues_count :integer default("0") -# created_at :datetime not null -# updated_at :datetime not null -# gid :integer -# gitea_url :string(255) +# id :integer not null, primary key +# name :string(190) +# description :string(255) +# color :string(255) +# user_id :integer +# project_id :integer +# issues_count :integer default("0") +# created_at :datetime not null +# updated_at :datetime not null +# gid :integer +# gitea_url :string(255) +# pull_requests_count :integer default("0") # # Indexes # diff --git a/app/models/laboratory.rb b/app/models/laboratory.rb index 9b409c170..0517c0df6 100644 --- a/app/models/laboratory.rb +++ b/app/models/laboratory.rb @@ -10,7 +10,6 @@ # sync_course :boolean default("0") # sync_subject :boolean default("0") # sync_shixun :boolean default("0") -# is_local :boolean default("0") # # Indexes # diff --git a/app/models/mark_file.rb b/app/models/mark_file.rb index c6c834623..663f6aca4 100644 --- a/app/models/mark_file.rb +++ b/app/models/mark_file.rb @@ -1,3 +1,23 @@ +# == Schema Information +# +# Table name: mark_files +# +# id :integer not null, primary key +# pull_request_id :integer +# user_id :integer +# file_path_sha :string(255) +# file_path :string(255) +# mark_as_read :boolean default("0") +# updated_after_read :boolean default("0") +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_mark_files_on_file_path_sha (file_path_sha) +# index_mark_files_on_pull_request_id (pull_request_id) +# + class MarkFile < ApplicationRecord belongs_to :pull_request diff --git a/app/models/message_template/issue_creator_expire.rb b/app/models/message_template/issue_creator_expire.rb index e6f42fcc4..c9478aa53 100644 --- a/app/models/message_template/issue_creator_expire.rb +++ b/app/models/message_template/issue_creator_expire.rb @@ -1,3 +1,17 @@ +# == Schema Information +# +# Table name: message_templates +# +# id :integer not null, primary key +# type :string(255) +# sys_notice :text(65535) +# email :text(65535) +# created_at :datetime not null +# updated_at :datetime not null +# notification_url :string(255) +# email_title :string(255) +# + class MessageTemplate::IssueCreatorExpire < MessageTemplate -end \ No newline at end of file +end diff --git a/app/models/organization.rb b/app/models/organization.rb index 75a2db971..281a52980 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -46,11 +46,8 @@ # is_sync_pwd :boolean default("1") # watchers_count :integer default("0") # devops_step :integer default("0") -# sponsor_certification :integer default("0") -# sponsor_num :integer default("0") -# sponsored_num :integer default("0") -# sponsor_description :text(65535) -# award_time :datetime +# sign_cla :boolean default("0") +# cla :boolean default("0") # # Indexes # @@ -58,7 +55,7 @@ # index_users_on_homepage_engineer (homepage_engineer) # index_users_on_homepage_teacher (homepage_teacher) # index_users_on_laboratory_id (laboratory_id) -# index_users_on_login (login) +# index_users_on_login (login) UNIQUE # index_users_on_mail (mail) # index_users_on_type (type) # @@ -70,6 +67,8 @@ class Organization < Owner default_scope { where(type: "Organization") } has_one :organization_extension, dependent: :destroy + has_one :cla, dependent: :destroy + has_many :teams, dependent: :destroy has_many :organization_users, dependent: :destroy has_many :team_users, dependent: :destroy @@ -183,4 +182,17 @@ class Organization < Owner name end end + + def open_cla! + update_attribute(:cla, true) + end + + def close_cla! + update_attribute(:cla, false) + end + + def open_cla? + cla == true + end + end diff --git a/app/models/organization_extension.rb b/app/models/organization_extension.rb index cb216aca1..11f0c7694 100644 --- a/app/models/organization_extension.rb +++ b/app/models/organization_extension.rb @@ -19,6 +19,8 @@ # news_banner_id :integer # news_content :text(65535) # memo :text(65535) +# news_title :string(255) +# news_url :string(255) # # Indexes # diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index 0250f012e..0618aa575 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -1,19 +1,20 @@ -# == Schema Information -# -# Table name: praise_treads -# -# id :integer not null, primary key -# user_id :integer not null -# praise_tread_object_id :integer -# praise_tread_object_type :string(255) -# praise_or_tread :integer default("1") -# created_at :datetime not null -# updated_at :datetime not null -# -# Indexes -# -# praise_tread (praise_tread_object_id,praise_tread_object_type) -# +# == Schema Information +# +# Table name: praise_treads +# +# id :integer not null, primary key +# user_id :integer not null +# praise_tread_object_id :integer +# praise_tread_object_type :string(255) +# praise_or_tread :integer default("1") +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# praise_tread (praise_tread_object_id,praise_tread_object_type) +# + class PraiseTread < ApplicationRecord diff --git a/app/models/project.rb b/app/models/project.rb index a63a8dd42..3a868357c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -3,7 +3,7 @@ # Table name: projects # # id :integer not null, primary key -# name :string(255) +# name :string(190) # description :text(4294967295) # homepage :string(255) default("") # is_public :boolean default("1"), not null @@ -55,14 +55,17 @@ # default_branch :string(255) default("master") # website :string(255) # lesson_url :string(255) +# use_blockchain :boolean default("0") # is_pinned :boolean default("0") # recommend_index :integer default("0") +# pr_view_admin :boolean default("0") # # Indexes # # index_projects_on_forked_from_project_id (forked_from_project_id) # index_projects_on_identifier (identifier) # index_projects_on_invite_code (invite_code) +# index_projects_on_is_pinned (is_pinned) # index_projects_on_is_public (is_public) # index_projects_on_lft (lft) # index_projects_on_license_id (license_id) diff --git a/app/models/repository.rb b/app/models/repository.rb index ed1f81db3..f2815dde7 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -27,6 +27,7 @@ # # Indexes # +# index_repositories_on_identifier (identifier) # index_repositories_on_project_id (project_id) # index_repositories_on_user_id (user_id) # diff --git a/app/models/system_notification_history.rb b/app/models/system_notification_history.rb index b629babdf..9ecfc5bb8 100644 --- a/app/models/system_notification_history.rb +++ b/app/models/system_notification_history.rb @@ -2,16 +2,16 @@ # # Table name: system_notification_histories # -# id :integer not null, primary key -# system_message_id :integer -# user_id :integer -# created_at :datetime not null -# updated_at :datetime not null +# id :integer not null, primary key +# system_notification_id :integer +# user_id :integer +# created_at :datetime not null +# updated_at :datetime not null # # Indexes # -# index_system_notification_histories_on_system_message_id (system_message_id) -# index_system_notification_histories_on_user_id (user_id) +# index_system_notification_histories_on_system_notification_id (system_notification_id) +# index_system_notification_histories_on_user_id (user_id) # class SystemNotificationHistory < ApplicationRecord diff --git a/app/models/template_message_setting.rb b/app/models/template_message_setting.rb index 67f9586d0..5e4907b2e 100644 --- a/app/models/template_message_setting.rb +++ b/app/models/template_message_setting.rb @@ -6,9 +6,9 @@ # type :string(255) # name :string(255) # key :string(255) -# openning :boolean -# notification_disabled :boolean -# email_disabled :boolean +# openning :boolean default("1") +# notification_disabled :boolean default("1") +# email_disabled :boolean default("0") # created_at :datetime not null # updated_at :datetime not null # diff --git a/app/models/template_message_setting/create_or_assign.rb b/app/models/template_message_setting/create_or_assign.rb index 4c392b4b7..629051305 100644 --- a/app/models/template_message_setting/create_or_assign.rb +++ b/app/models/template_message_setting/create_or_assign.rb @@ -6,9 +6,9 @@ # type :string(255) # name :string(255) # key :string(255) -# openning :boolean -# notification_disabled :boolean -# email_disabled :boolean +# openning :boolean default("1") +# notification_disabled :boolean default("1") +# email_disabled :boolean default("0") # created_at :datetime not null # updated_at :datetime not null # diff --git a/app/models/template_message_setting/manage_project.rb b/app/models/template_message_setting/manage_project.rb index 978761f94..c9b2406d7 100644 --- a/app/models/template_message_setting/manage_project.rb +++ b/app/models/template_message_setting/manage_project.rb @@ -6,9 +6,9 @@ # type :string(255) # name :string(255) # key :string(255) -# openning :boolean -# notification_disabled :boolean -# email_disabled :boolean +# openning :boolean default("1") +# notification_disabled :boolean default("1") +# email_disabled :boolean default("0") # created_at :datetime not null # updated_at :datetime not null # diff --git a/app/models/template_message_setting/normal.rb b/app/models/template_message_setting/normal.rb index 771fba2f2..acf44009f 100644 --- a/app/models/template_message_setting/normal.rb +++ b/app/models/template_message_setting/normal.rb @@ -6,9 +6,9 @@ # type :string(255) # name :string(255) # key :string(255) -# openning :boolean -# notification_disabled :boolean -# email_disabled :boolean +# openning :boolean default("1") +# notification_disabled :boolean default("1") +# email_disabled :boolean default("0") # created_at :datetime not null # updated_at :datetime not null # diff --git a/app/models/template_message_setting/watch_project.rb b/app/models/template_message_setting/watch_project.rb index 35dfef6db..a07e4bb94 100644 --- a/app/models/template_message_setting/watch_project.rb +++ b/app/models/template_message_setting/watch_project.rb @@ -6,9 +6,9 @@ # type :string(255) # name :string(255) # key :string(255) -# openning :boolean -# notification_disabled :boolean -# email_disabled :boolean +# openning :boolean default("1") +# notification_disabled :boolean default("1") +# email_disabled :boolean default("0") # created_at :datetime not null # updated_at :datetime not null # diff --git a/app/models/timeable_visit_record.rb b/app/models/timeable_visit_record.rb index 8411ddf66..aee1d718f 100644 --- a/app/models/timeable_visit_record.rb +++ b/app/models/timeable_visit_record.rb @@ -5,7 +5,7 @@ # id :integer not null, primary key # time :string(255) # project_id :integer -# visits :integer +# visits :integer default("0") # created_at :datetime not null # updated_at :datetime not null # diff --git a/app/models/token.rb b/app/models/token.rb index 746af6535..fac516eb8 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -1,18 +1,19 @@ -# == Schema Information -# -# Table name: tokens -# -# id :integer not null, primary key -# user_id :integer default("0"), not null -# action :string(30) default(""), not null -# value :string(40) default(""), not null -# created_on :datetime not null -# -# Indexes -# -# index_tokens_on_user_id (user_id) -# tokens_value (value) UNIQUE -# +# == Schema Information +# +# Table name: tokens +# +# id :integer not null, primary key +# user_id :integer default("0"), not null +# action :string(30) default(""), not null +# value :string(40) default(""), not null +# created_on :datetime not null +# +# Indexes +# +# index_tokens_on_user_id (user_id) +# tokens_value (value) UNIQUE +# + # # This program is free software; you can redistribute it and/or diff --git a/app/models/topic.rb b/app/models/topic.rb index e464859ec..f7b4a11fb 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -6,7 +6,6 @@ # type :string(255) # title :string(255) # uuid :integer -# image_url :string(255) # url :string(255) # order_index :integer # diff --git a/app/models/topic/activity_forum.rb b/app/models/topic/activity_forum.rb index 8cf9adf83..ee2dc9941 100644 --- a/app/models/topic/activity_forum.rb +++ b/app/models/topic/activity_forum.rb @@ -6,7 +6,6 @@ # type :string(255) # title :string(255) # uuid :integer -# image_url :string(255) # url :string(255) # order_index :integer # diff --git a/app/models/topic/banner.rb b/app/models/topic/banner.rb index e5b77bec0..7abd2ac56 100644 --- a/app/models/topic/banner.rb +++ b/app/models/topic/banner.rb @@ -6,7 +6,6 @@ # type :string(255) # title :string(255) # uuid :integer -# image_url :string(255) # url :string(255) # order_index :integer # diff --git a/app/models/topic/card.rb b/app/models/topic/card.rb index 6a54e17ea..3baee486c 100644 --- a/app/models/topic/card.rb +++ b/app/models/topic/card.rb @@ -6,7 +6,6 @@ # type :string(255) # title :string(255) # uuid :integer -# image_url :string(255) # url :string(255) # order_index :integer # diff --git a/app/models/topic/cooperator.rb b/app/models/topic/cooperator.rb index a023d3656..0fab2c3b7 100644 --- a/app/models/topic/cooperator.rb +++ b/app/models/topic/cooperator.rb @@ -6,7 +6,6 @@ # type :string(255) # title :string(255) # uuid :integer -# image_url :string(255) # url :string(255) # order_index :integer # diff --git a/app/models/topic/excellent_project.rb b/app/models/topic/excellent_project.rb index ac08863c7..aec097f62 100644 --- a/app/models/topic/excellent_project.rb +++ b/app/models/topic/excellent_project.rb @@ -6,7 +6,6 @@ # type :string(255) # title :string(255) # uuid :integer -# image_url :string(255) # url :string(255) # order_index :integer # diff --git a/app/models/topic/experience_forum.rb b/app/models/topic/experience_forum.rb index 855a56809..9b48f9ed4 100644 --- a/app/models/topic/experience_forum.rb +++ b/app/models/topic/experience_forum.rb @@ -6,7 +6,6 @@ # type :string(255) # title :string(255) # uuid :integer -# image_url :string(255) # url :string(255) # order_index :integer # diff --git a/app/models/topic/glcc_news.rb b/app/models/topic/glcc_news.rb index 6b707bf07..4b2e758d2 100644 --- a/app/models/topic/glcc_news.rb +++ b/app/models/topic/glcc_news.rb @@ -6,7 +6,6 @@ # type :string(255) # title :string(255) # uuid :integer -# image_url :string(255) # url :string(255) # order_index :integer # @@ -14,4 +13,4 @@ # GLCC 新闻稿 class Topic::GlccNews < Topic -end \ No newline at end of file +end diff --git a/app/models/topic/pinned_forum.rb b/app/models/topic/pinned_forum.rb index c5a2c8572..78425ce6a 100644 --- a/app/models/topic/pinned_forum.rb +++ b/app/models/topic/pinned_forum.rb @@ -6,7 +6,6 @@ # type :string(255) # title :string(255) # uuid :integer -# image_url :string(255) # url :string(255) # order_index :integer # diff --git a/app/models/user.rb b/app/models/user.rb index 9d76696ea..7250eb09d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -47,6 +47,7 @@ # watchers_count :integer default("0") # devops_step :integer default("0") # sign_cla :boolean default("0") +# cla :boolean default("0") # # Indexes # @@ -181,6 +182,10 @@ class User < Owner has_many :issue_participants, foreign_key: :participant_id has_many :participant_issues, through: :issue_participants, source: :issue has_many :project_topics + #cla + has_many :user_clas, :dependent => :destroy + has_many :clas, through: :user_clas + # Groups and active users scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) } scope :like, lambda { |keywords| diff --git a/app/models/user_action.rb b/app/models/user_action.rb index 179359695..384475c4f 100644 --- a/app/models/user_action.rb +++ b/app/models/user_action.rb @@ -12,9 +12,10 @@ # # Indexes # -# index_user_actions_on_ip (ip) -# index_user_actions_on_user_id (user_id) -# index_user_actions_on_user_id_and_action_type (user_id,action_type) +# index_user_actions_on_action_id (action_id) +# index_user_actions_on_action_type (action_type) +# index_user_actions_on_ip (ip) +# index_user_actions_on_user_id (user_id) # class UserAction < ApplicationRecord diff --git a/app/models/user_agent.rb b/app/models/user_agent.rb index ba519d6fb..49d7b35a1 100644 --- a/app/models/user_agent.rb +++ b/app/models/user_agent.rb @@ -10,13 +10,10 @@ # updated_at :datetime not null # register_status :integer default("0") # action_status :integer default("0") -# is_delete :boolean default("0") -# user_id :integer # # Indexes # -# index_user_agents_on_ip (ip) -# index_user_agents_on_user_id (user_id) +# index_user_agents_on_ip (ip) UNIQUE # class UserAgent < ApplicationRecord diff --git a/app/models/user_cla.rb b/app/models/user_cla.rb new file mode 100644 index 000000000..a1accb41e --- /dev/null +++ b/app/models/user_cla.rb @@ -0,0 +1,35 @@ +# == Schema Information +# +# Table name: user_clas +# +# id :integer not null, primary key +# user_id :integer not null +# cla_id :integer not null +# real_name :string(255) not null +# email :string(255) not null +# state :integer default("0") +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_user_clas_on_cla_id (cla_id) +# index_user_clas_on_user_id (user_id) +# + +class UserCla < ApplicationRecord + belongs_to :user + belongs_to :cla +# identity 0: 教师教授 1: 学生, 2: 专业人士, 3: 开发者 + enum state: { deafult: 0, signed: 1, failed: 2} + + def self.build(params,user_id) + self.create!(user_id: user_id, + cla_id: params[:cla_id], + real_name: params[:real_name], + email: params[:email], + state: 1 + ) + end + +end diff --git a/app/models/user_extension.rb b/app/models/user_extension.rb index c1046ac2f..ef4af5fd3 100644 --- a/app/models/user_extension.rb +++ b/app/models/user_extension.rb @@ -20,7 +20,7 @@ # student_realname :string(255) # location_city :string(255) # school_id :integer -# description :string(255) default("") +# description :string(255) # department_id :integer # province :string(255) # city :string(255) diff --git a/app/models/version.rb b/app/models/version.rb index 82474f55e..ec2ad68cd 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -4,7 +4,7 @@ # # id :integer not null, primary key # project_id :integer default("0"), not null -# name :string(255) default(""), not null +# name :string(255) # description :text(65535) # effective_date :date # created_on :datetime diff --git a/app/models/version_release.rb b/app/models/version_release.rb index 00119f806..98c81b61d 100644 --- a/app/models/version_release.rb +++ b/app/models/version_release.rb @@ -4,9 +4,9 @@ # # id :integer not null, primary key # user_id :integer -# name :string(255) +# name :text(4294967295) # body :text(65535) -# tag_name :string(255) +# tag_name :text(65535) # target_commitish :string(255) # draft :boolean default("0") # prerelease :boolean default("0") diff --git a/app/views/admins/organizations/shared/_org_list.html.erb b/app/views/admins/organizations/shared/_org_list.html.erb index 25878b296..148681fb2 100644 --- a/app/views/admins/organizations/shared/_org_list.html.erb +++ b/app/views/admins/organizations/shared/_org_list.html.erb @@ -27,11 +27,12 @@ <%= link_to org.organization_users_count, "/#{org.login}", target: "_blank" %> <%= link_to org.projects_count, "/#{org.login}", target: "_blank" %> + <%= javascript_void_link '开通CLA', class: 'action open-cla-action', data: { id: org.id }, style: org.open_cla? ? 'display: none;' : '' %> + <%= javascript_void_link '关闭CLA', class: 'action close-cla-action', data: { id: org.id }, style: org.open_cla? ? '' : 'display: none;' %> <%= link_to '查看', admins_organization_path(org), class: 'action' %>
<%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %>
diff --git a/app/views/admins/organizations/show.html.erb b/app/views/admins/organizations/show.html.erb index b40f1c258..102392567 100644 --- a/app/views/admins/organizations/show.html.erb +++ b/app/views/admins/organizations/show.html.erb @@ -29,6 +29,9 @@ <%= f.input :lastname, label: '姓名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @org.real_name } %> +
+ <%= f.input :cla, label: '是否开通CLA', wrapper_html: { class: 'col-md-3' }, input_html: { class: 'col-md-11', value: @org.cla } %> +
<% end %> diff --git a/app/views/organizations/clas/_detail.json.jbuilder b/app/views/organizations/clas/_detail.json.jbuilder new file mode 100644 index 000000000..39c4e6a33 --- /dev/null +++ b/app/views/organizations/clas/_detail.json.jbuilder @@ -0,0 +1,5 @@ +json.id cla.id +json.content cla.content +json.key cla.key +json.name cla.name +json.pr_need cla.pr_need diff --git a/app/views/organizations/clas/create.json.jbuilder b/app/views/organizations/clas/create.json.jbuilder new file mode 100644 index 000000000..e95312d8c --- /dev/null +++ b/app/views/organizations/clas/create.json.jbuilder @@ -0,0 +1 @@ +json.partial! "detail", cla: @cla, organization: @organization \ No newline at end of file diff --git a/app/views/organizations/clas/index.json.jbuilder b/app/views/organizations/clas/index.json.jbuilder new file mode 100644 index 000000000..260943dce --- /dev/null +++ b/app/views/organizations/clas/index.json.jbuilder @@ -0,0 +1,4 @@ +json.id @cla.id +json.key @cla.key +json.name @cla.name +json.pr_need @cla.pr_need diff --git a/app/views/organizations/clas/show.json.jbuilder b/app/views/organizations/clas/show.json.jbuilder new file mode 100644 index 000000000..4fa0db18c --- /dev/null +++ b/app/views/organizations/clas/show.json.jbuilder @@ -0,0 +1,6 @@ +json.partial! "detail", cla: @cla, organization: @organization +json.is_admin @is_admin +json.is_member @is_member +json.organization do + json.partial! "organizations/organizations/simple", organization: @organization +end \ No newline at end of file diff --git a/app/views/organizations/clas/update.json.jbuilder b/app/views/organizations/clas/update.json.jbuilder new file mode 100644 index 000000000..e95312d8c --- /dev/null +++ b/app/views/organizations/clas/update.json.jbuilder @@ -0,0 +1 @@ +json.partial! "detail", cla: @cla, organization: @organization \ No newline at end of file diff --git a/app/views/organizations/organizations/_detail.json.jbuilder b/app/views/organizations/organizations/_detail.json.jbuilder index c7614f039..fffc019dc 100644 --- a/app/views/organizations/organizations/_detail.json.jbuilder +++ b/app/views/organizations/organizations/_detail.json.jbuilder @@ -16,4 +16,5 @@ json.news_banner_id organization.news_banner_id json.news_content organization.news_content json.memo organization.memo json.news_title organization.news_title -json.news_url organization.news_url \ No newline at end of file +json.news_url organization.news_url +json.cla organization.cla \ No newline at end of file diff --git a/app/views/users/clas/_detail.json.jbuilder b/app/views/users/clas/_detail.json.jbuilder new file mode 100644 index 000000000..07bc5070b --- /dev/null +++ b/app/views/users/clas/_detail.json.jbuilder @@ -0,0 +1,8 @@ +json.id user_cla.id +json.real_name user_cla.real_name +json.email user_cla.email +json.state user_cla.state +json.created_at format_time(user_cla.created_at) +json.cla do + json.partial! "/organizations/clas/detail", locals: {cla: user_cla.cla} +end \ No newline at end of file diff --git a/app/views/users/clas/index.json.jbuilder b/app/views/users/clas/index.json.jbuilder new file mode 100644 index 000000000..d4e645c6e --- /dev/null +++ b/app/views/users/clas/index.json.jbuilder @@ -0,0 +1,3 @@ +json.user_clas @user_clas do |user_cla| + json.partial! "detail", user_cla: user_cla +end diff --git a/app/views/users/clas/show.json.jbuilder b/app/views/users/clas/show.json.jbuilder new file mode 100644 index 000000000..a34e77b7f --- /dev/null +++ b/app/views/users/clas/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "detail", user_cla: @user_cla diff --git a/config/routes.rb b/config/routes.rb index f34c9d44e..6ab9f228c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -147,6 +147,7 @@ Rails.application.routes.draw do delete :quit end end + resources :clas resources :teams, except: [:edit, :new] do collection do get :search @@ -389,7 +390,7 @@ Rails.application.routes.draw do scope module: :users do resource :interest, only: [:create] - + resources :clas, only: [:index,:create] resources :accounts, only: [:show, :update] do resource :phone_bind, only: [:create] resource :email_bind, only: [:create] @@ -847,7 +848,12 @@ Rails.application.routes.draw do resources :school_statistics, only: [:index] do get :contrast, on: :collection end - resources :organizations, only: [:index, :edit, :show, :destroy] + resources :organizations, only: [:index, :edit, :show, :destroy] do + member do + post :open_cla + post :close_cla + end + end resources :users, only: [:index, :edit, :update, :destroy] do member do post :reward_grade diff --git a/db/migrate/20230612020506_add_cla_to_users.rb b/db/migrate/20230612020506_add_cla_to_users.rb new file mode 100644 index 000000000..d16650c49 --- /dev/null +++ b/db/migrate/20230612020506_add_cla_to_users.rb @@ -0,0 +1,5 @@ +class AddClaToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :cla, :boolean, default: false + end +end diff --git a/db/migrate/20230612031416_create_clas.rb b/db/migrate/20230612031416_create_clas.rb new file mode 100644 index 000000000..f85012429 --- /dev/null +++ b/db/migrate/20230612031416_create_clas.rb @@ -0,0 +1,13 @@ +class CreateClas < ActiveRecord::Migration[5.2] + def change + create_table :clas do |t| + t.string :name, null:false + t.string :key, index:true, null:false + t.text :content + t.integer :organization_id, index:true, null:false + t.boolean :pr_need, default: false + t.integer :count, default: 0 + t.timestamps + end + end +end diff --git a/db/migrate/20230612031448_create_user_clas.rb b/db/migrate/20230612031448_create_user_clas.rb new file mode 100644 index 000000000..715a363fb --- /dev/null +++ b/db/migrate/20230612031448_create_user_clas.rb @@ -0,0 +1,12 @@ +class CreateUserClas < ActiveRecord::Migration[5.2] + def change + create_table :user_clas do |t| + t.integer :user_id, null:false, index: true + t.integer :cla_id, null:false, index: true + t.string :real_name, null:false + t.string :email, null:false + t.integer :state, default:0 + t.timestamps + end + end +end diff --git a/spec/controllers/organizations/clas_controller_spec.rb b/spec/controllers/organizations/clas_controller_spec.rb new file mode 100644 index 000000000..e6df41003 --- /dev/null +++ b/spec/controllers/organizations/clas_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Organizations::ClasController, type: :controller do + +end diff --git a/spec/controllers/users/clas_controller_spec.rb b/spec/controllers/users/clas_controller_spec.rb new file mode 100644 index 000000000..02bc9979e --- /dev/null +++ b/spec/controllers/users/clas_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Users::ClasController, type: :controller do + +end diff --git a/spec/helpers/organizations/clas_helper_spec.rb b/spec/helpers/organizations/clas_helper_spec.rb new file mode 100644 index 000000000..18c3a1165 --- /dev/null +++ b/spec/helpers/organizations/clas_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Organizations::ClasHelper. For example: +# +# describe Organizations::ClasHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Organizations::ClasHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/users/clas_helper_spec.rb b/spec/helpers/users/clas_helper_spec.rb new file mode 100644 index 000000000..5bc4dd757 --- /dev/null +++ b/spec/helpers/users/clas_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Users::ClasHelper. For example: +# +# describe Users::ClasHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Users::ClasHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/cla_spec.rb b/spec/models/cla_spec.rb new file mode 100644 index 000000000..cc8796f17 --- /dev/null +++ b/spec/models/cla_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Cla, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/user_cla_spec.rb b/spec/models/user_cla_spec.rb new file mode 100644 index 000000000..3cf7c59db --- /dev/null +++ b/spec/models/user_cla_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe UserCla, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 0a483cf7622d45ee5fb1cd2a1bff0629d81d78f8 Mon Sep 17 00:00:00 2001 From: chenjing Date: Tue, 13 Jun 2023 16:09:35 +0800 Subject: [PATCH 03/30] change migration index length --- db/migrate/20230612031416_create_clas.rb | 6 ++++-- db/migrate/20230612031448_create_user_clas.rb | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/db/migrate/20230612031416_create_clas.rb b/db/migrate/20230612031416_create_clas.rb index f85012429..67ffb2986 100644 --- a/db/migrate/20230612031416_create_clas.rb +++ b/db/migrate/20230612031416_create_clas.rb @@ -2,12 +2,14 @@ class CreateClas < ActiveRecord::Migration[5.2] def change create_table :clas do |t| t.string :name, null:false - t.string :key, index:true, null:false + t.string :key, null:false t.text :content - t.integer :organization_id, index:true, null:false + t.integer :organization_id, null:false t.boolean :pr_need, default: false t.integer :count, default: 0 t.timestamps end + add_index :clas, :key, :length =>190 + add_index :clas, :organization_id end end diff --git a/db/migrate/20230612031448_create_user_clas.rb b/db/migrate/20230612031448_create_user_clas.rb index 715a363fb..b79aafec3 100644 --- a/db/migrate/20230612031448_create_user_clas.rb +++ b/db/migrate/20230612031448_create_user_clas.rb @@ -1,12 +1,15 @@ class CreateUserClas < ActiveRecord::Migration[5.2] def change create_table :user_clas do |t| - t.integer :user_id, null:false, index: true - t.integer :cla_id, null:false, index: true + t.integer :user_id, null:false + t.integer :cla_id, null:false t.string :real_name, null:false t.string :email, null:false t.integer :state, default:0 t.timestamps end + add_index :user_clas, :user_id + add_index :user_clas, :cla_id + end end From bde92206415dc75688601d968fd613cbbb79ed2f Mon Sep 17 00:00:00 2001 From: chenjing Date: Tue, 13 Jun 2023 17:16:30 +0800 Subject: [PATCH 04/30] change cla --- .../javascripts/admins/organizations/index.js | 58 +++++++++++++------ .../admins/organizations_controller.rb | 11 ++-- .../organizations/clas_controller.rb | 2 +- app/models/ci/user.rb | 2 +- app/models/organization.rb | 8 +-- app/models/user.rb | 2 +- .../organizations/_detail.json.jbuilder | 2 +- ...50_change_cal_to_enabling_cla_for_users.rb | 5 ++ 8 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 db/migrate/20230613082850_change_cal_to_enabling_cla_for_users.rb diff --git a/app/assets/javascripts/admins/organizations/index.js b/app/assets/javascripts/admins/organizations/index.js index b301e537d..97a5c76d1 100644 --- a/app/assets/javascripts/admins/organizations/index.js +++ b/app/assets/javascripts/admins/organizations/index.js @@ -10,32 +10,54 @@ $(document).on('turbolinks:load', function(){ // organizations open cla $('.organizations-list-container').on('click', '.open-cla-action', function(){ - var $action = $(this); + var $openClaAction = $(this); + var $closeClaAction = $openClaAction.siblings('.close-cla-action'); - var userId = $action.data('id'); - $.ajax({ - url: '/admins/organizations/' + userId + '/open_cla', - method: 'POST', - dataType: 'json', - success: function() { - showSuccessNotify(); + 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 $action = $(this); + var $closeClaAction = $(this); + var $openClaAction= $closeClaAction.siblings('.open-cla-action'); - var userId = $action.data('id'); - $.ajax({ - url: '/admins/organizations/' + userId + '/close_cla', - method: 'POST', - dataType: 'json', - success: function() { - showSuccessNotify(); + 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' }); + } + }); } - }); + }) }); diff --git a/app/controllers/admins/organizations_controller.rb b/app/controllers/admins/organizations_controller.rb index 9ca23ba38..c2e0ea96c 100644 --- a/app/controllers/admins/organizations_controller.rb +++ b/app/controllers/admins/organizations_controller.rb @@ -11,15 +11,18 @@ class Admins::OrganizationsController < Admins::BaseController def open_cla - @org = Organization.find(params[:id]) @org.open_cla! render_ok end def close_cla - @org = Organization.find(params[:id]) - @org.close_cla! - render_ok + if @org.cla.nil? + @org.close_cla! + render_ok + else + render_error(' 该组织已创建CLA 不允许关闭') + end + end def show diff --git a/app/controllers/organizations/clas_controller.rb b/app/controllers/organizations/clas_controller.rb index 369fb435c..531dc3c5d 100644 --- a/app/controllers/organizations/clas_controller.rb +++ b/app/controllers/organizations/clas_controller.rb @@ -9,7 +9,7 @@ class Organizations::ClasController < Organizations::BaseController end def create - tip_exception("您的组织还未拥有创建CLA权限,请联系管理员") if @organization.cla == false + tip_exception("您的组织还未拥有创建CLA权限,请联系管理员") if @organization.enabling_cla == false ActiveRecord::Base.transaction do if @organization.cla.present? return tip_exception("组织已存在CLA!") diff --git a/app/models/ci/user.rb b/app/models/ci/user.rb index be151dee2..62ed4c447 100644 --- a/app/models/ci/user.rb +++ b/app/models/ci/user.rb @@ -47,7 +47,7 @@ # watchers_count :integer default("0") # devops_step :integer default("0") # sign_cla :boolean default("0") -# cla :boolean default("0") +# enabling_cla :boolean default("0") # # Indexes # diff --git a/app/models/organization.rb b/app/models/organization.rb index 281a52980..e58cc91be 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -47,7 +47,7 @@ # watchers_count :integer default("0") # devops_step :integer default("0") # sign_cla :boolean default("0") -# cla :boolean default("0") +# enabling_cla :boolean default("0") # # Indexes # @@ -184,15 +184,15 @@ class Organization < Owner end def open_cla! - update_attribute(:cla, true) + update_attribute(:enabling_cla, true) end def close_cla! - update_attribute(:cla, false) + update_attribute(:enabling_cla, false) end def open_cla? - cla == true + enabling_cla == true end end diff --git a/app/models/user.rb b/app/models/user.rb index 7250eb09d..fd79bc408 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -47,7 +47,7 @@ # watchers_count :integer default("0") # devops_step :integer default("0") # sign_cla :boolean default("0") -# cla :boolean default("0") +# enabling_cla :boolean default("0") # # Indexes # diff --git a/app/views/organizations/organizations/_detail.json.jbuilder b/app/views/organizations/organizations/_detail.json.jbuilder index fffc019dc..1968e78c8 100644 --- a/app/views/organizations/organizations/_detail.json.jbuilder +++ b/app/views/organizations/organizations/_detail.json.jbuilder @@ -17,4 +17,4 @@ json.news_content organization.news_content json.memo organization.memo json.news_title organization.news_title json.news_url organization.news_url -json.cla organization.cla \ No newline at end of file +json.enabling_cla organization.enabling_cla \ No newline at end of file diff --git a/db/migrate/20230613082850_change_cal_to_enabling_cla_for_users.rb b/db/migrate/20230613082850_change_cal_to_enabling_cla_for_users.rb new file mode 100644 index 000000000..1c4a9e93b --- /dev/null +++ b/db/migrate/20230613082850_change_cal_to_enabling_cla_for_users.rb @@ -0,0 +1,5 @@ +class ChangeCalToEnablingClaForUsers < ActiveRecord::Migration[5.2] + def change + rename_column :users, :cla ,:enabling_cla + end +end From 04b335196225a5f25b5e532ed6143d6e2f9c5fa6 Mon Sep 17 00:00:00 2001 From: chenjing Date: Wed, 14 Jun 2023 10:46:48 +0800 Subject: [PATCH 05/30] change validate for create cla --- app/forms/organizations/create_cla_form.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/forms/organizations/create_cla_form.rb b/app/forms/organizations/create_cla_form.rb index e77053e9f..47499088f 100644 --- a/app/forms/organizations/create_cla_form.rb +++ b/app/forms/organizations/create_cla_form.rb @@ -2,5 +2,5 @@ class Organizations::CreateClaForm < BaseForm KEY_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾 attr_accessor :name, :key, :content, :organization_id, :pr_need validates :name, :organization_id , :key, presence: true - validates :name, format: { with: KEY_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } + validates :key, format: { with: KEY_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } end \ No newline at end of file From 0d00fd17442a0110739893a62e8349a7c02ad226 Mon Sep 17 00:00:00 2001 From: chenjing Date: Wed, 14 Jun 2023 11:22:13 +0800 Subject: [PATCH 06/30] fix when cla nil index error --- app/views/organizations/clas/index.json.jbuilder | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/views/organizations/clas/index.json.jbuilder b/app/views/organizations/clas/index.json.jbuilder index 260943dce..632fde017 100644 --- a/app/views/organizations/clas/index.json.jbuilder +++ b/app/views/organizations/clas/index.json.jbuilder @@ -1,4 +1,3 @@ -json.id @cla.id -json.key @cla.key -json.name @cla.name -json.pr_need @cla.pr_need +if @cla.present? + json.partial! "detail", cla: @cla +end \ No newline at end of file From 78a1d48a3ed3c1a930af8e23961c02e691bb5ea0 Mon Sep 17 00:00:00 2001 From: chenjing Date: Wed, 14 Jun 2023 11:58:51 +0800 Subject: [PATCH 07/30] fix bug --- app/controllers/organizations/clas_controller.rb | 4 ++-- app/models/cla.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/organizations/clas_controller.rb b/app/controllers/organizations/clas_controller.rb index 531dc3c5d..a8c92e99d 100644 --- a/app/controllers/organizations/clas_controller.rb +++ b/app/controllers/organizations/clas_controller.rb @@ -15,7 +15,7 @@ class Organizations::ClasController < Organizations::BaseController return tip_exception("组织已存在CLA!") else Organizations::CreateClaForm.new(cla_params).validate! - @cla = Cla.build(cla_params) + @cla = Cla.build(cla_params,@organization.id) end end rescue Exception => e @@ -57,7 +57,7 @@ class Organizations::ClasController < Organizations::BaseController end def load_cla - @cla = Cla.find_by!(organization:params[:organization_id], key: params[:id]) + @cla = Cla.find_by!(organization:@organization, key: params[:id]) end end diff --git a/app/models/cla.rb b/app/models/cla.rb index d42726658..ff5b8780f 100644 --- a/app/models/cla.rb +++ b/app/models/cla.rb @@ -27,8 +27,8 @@ class Cla < ApplicationRecord self.key.parameterize end - def self.build(params) - self.create!(organization_id: params[:organization_id], + def self.build(params,org_id) + self.create!(organization_id: org_id, name: params[:name], key: params[:key], content: params[:content], From b938025e5be02d1c8ff0d011f832dc80c3a3ab83 Mon Sep 17 00:00:00 2001 From: chenjing Date: Wed, 14 Jun 2023 14:20:58 +0800 Subject: [PATCH 08/30] cla add count --- app/controllers/users/clas_controller.rb | 1 + app/models/cla.rb | 5 +++++ app/models/user_cla.rb | 3 +++ app/views/organizations/clas/_detail.json.jbuilder | 1 + 4 files changed, 10 insertions(+) diff --git a/app/controllers/users/clas_controller.rb b/app/controllers/users/clas_controller.rb index e3a4de0c2..d5e93436e 100644 --- a/app/controllers/users/clas_controller.rb +++ b/app/controllers/users/clas_controller.rb @@ -8,6 +8,7 @@ class Users::ClasController < Users::BaseController ActiveRecord::Base.transaction do Users::UserClaForm.new(user_cla_params).validate! @user_cla = UserCla.build(user_cla_params, @_observed_user.id) + render_ok end rescue Exception => e uid_logger_error(e.message) diff --git a/app/models/cla.rb b/app/models/cla.rb index ff5b8780f..11f86dcd6 100644 --- a/app/models/cla.rb +++ b/app/models/cla.rb @@ -35,4 +35,9 @@ class Cla < ApplicationRecord pr_need: params[:pr_need] ) end + + + def fresh_count + update(count:self.users.count) + end end diff --git a/app/models/user_cla.rb b/app/models/user_cla.rb index a1accb41e..005533ce7 100644 --- a/app/models/user_cla.rb +++ b/app/models/user_cla.rb @@ -22,6 +22,9 @@ class UserCla < ApplicationRecord belongs_to :cla # identity 0: 教师教授 1: 学生, 2: 专业人士, 3: 开发者 enum state: { deafult: 0, signed: 1, failed: 2} + after_create do + cla.fresh_count + end def self.build(params,user_id) self.create!(user_id: user_id, diff --git a/app/views/organizations/clas/_detail.json.jbuilder b/app/views/organizations/clas/_detail.json.jbuilder index 39c4e6a33..b9d50183b 100644 --- a/app/views/organizations/clas/_detail.json.jbuilder +++ b/app/views/organizations/clas/_detail.json.jbuilder @@ -3,3 +3,4 @@ json.content cla.content json.key cla.key json.name cla.name json.pr_need cla.pr_need +json.count cla.count \ No newline at end of file From 6b772ea8890bab59516e52d7eb95d23d927258f4 Mon Sep 17 00:00:00 2001 From: chenjing Date: Wed, 14 Jun 2023 16:53:24 +0800 Subject: [PATCH 09/30] fix cla --- app/controllers/organizations/clas_controller.rb | 2 +- app/forms/organizations/create_cla_form.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/organizations/clas_controller.rb b/app/controllers/organizations/clas_controller.rb index a8c92e99d..e50cb8db4 100644 --- a/app/controllers/organizations/clas_controller.rb +++ b/app/controllers/organizations/clas_controller.rb @@ -47,7 +47,7 @@ class Organizations::ClasController < Organizations::BaseController private def cla_params - params.permit(:name, :key, :content, :organization_id, :pr_need) + params.permit(:name, :key, :content, :pr_need) end def load_organization diff --git a/app/forms/organizations/create_cla_form.rb b/app/forms/organizations/create_cla_form.rb index 47499088f..ce20a23ce 100644 --- a/app/forms/organizations/create_cla_form.rb +++ b/app/forms/organizations/create_cla_form.rb @@ -1,6 +1,6 @@ class Organizations::CreateClaForm < BaseForm KEY_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾 - attr_accessor :name, :key, :content, :organization_id, :pr_need - validates :name, :organization_id , :key, presence: true + attr_accessor :name, :key, :content, :pr_need + validates :name , :key, presence: true validates :key, format: { with: KEY_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } end \ No newline at end of file From fccf36e1eb71b4e0333e44cc603570e6a95a6941 Mon Sep 17 00:00:00 2001 From: chenjing Date: Thu, 15 Jun 2023 14:01:36 +0800 Subject: [PATCH 10/30] update response for cla --- app/controllers/organizations/clas_controller.rb | 6 +++++- app/models/organization.rb | 5 +++++ app/views/organizations/clas/show.json.jbuilder | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/organizations/clas_controller.rb b/app/controllers/organizations/clas_controller.rb index e50cb8db4..953cc9d5c 100644 --- a/app/controllers/organizations/clas_controller.rb +++ b/app/controllers/organizations/clas_controller.rb @@ -1,11 +1,15 @@ class Organizations::ClasController < Organizations::BaseController before_action :load_organization before_action :load_cla, only: [:show, :update, :destroy] + def index @cla = @organization.cla end - def show + def show + @is_admin = can_edit_org? + @is_member = @organization.is_member?(current_user.id) + @is_sign = @organization.is_sign?(current_user.id) end def create diff --git a/app/models/organization.rb b/app/models/organization.rb index e58cc91be..72788d025 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -107,6 +107,11 @@ class Organization < Owner organization_users.where(user_id: user_id).present? end + def is_sign?(user_id) + return false if cla.nil? + cla.user_clas.where(user_id: user_id).present? + end + def is_owner?(user_id) team_users.joins(:team).where(user_id: user_id, teams: {authorize: %w(owner)}).present? end diff --git a/app/views/organizations/clas/show.json.jbuilder b/app/views/organizations/clas/show.json.jbuilder index 4fa0db18c..1660b4d07 100644 --- a/app/views/organizations/clas/show.json.jbuilder +++ b/app/views/organizations/clas/show.json.jbuilder @@ -1,5 +1,6 @@ json.partial! "detail", cla: @cla, organization: @organization json.is_admin @is_admin +json.is_sign @is_sign json.is_member @is_member json.organization do json.partial! "organizations/organizations/simple", organization: @organization From cc4452e4adcec1bd6d55f202ce2f76bfdf9af6f6 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 15 Jun 2023 14:30:27 +0800 Subject: [PATCH 11/30] =?UTF-8?q?fixed=20readme=E4=B8=AD=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E9=97=AE=E5=8F=B7=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 0f3f27ac0..796774564 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -136,6 +136,7 @@ module RepositoriesHelper # 链接直接跳过不做替换 next if s_content.starts_with?('http://') || s_content.starts_with?('https://') || s_content.starts_with?('mailto:') || s_content.blank? ext = File.extname(s_content)[1..-1] + ext = ext.split("?")[0] if ext.include?("?") if (image_type?(ext) || download_type(ext)) && !ext.blank? s_content = File.expand_path(s_content, file_path) s_content = s_content.split("#{Rails.root}/")[1] From fca25ff482b9a469a67a71d304acf1c5399d1834 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 15 Jun 2023 14:37:58 +0800 Subject: [PATCH 12/30] =?UTF-8?q?fixed=20readme=E4=B8=AD=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E9=97=AE=E5=8F=B7=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 796774564..29662ea9f 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -142,7 +142,8 @@ module RepositoriesHelper s_content = s_content.split("#{Rails.root}/")[1] # content = content.gsub(s[0], "/#{s_content}") s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{s_content}?ref=#{ref}"].join - case k.to_s + s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{s_content}&ref=#{ref}"].join if s_content.include?("?") + case k.to_s when 'ss_src' content = content.gsub("src=\"#{s[0]}\"", "src=\"#{s_content}\"") when 'ss_src_1' From 328c5c35618708aec3da872ac2867d04198f48f4 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 15 Jun 2023 14:43:01 +0800 Subject: [PATCH 13/30] =?UTF-8?q?fixed=20readme=E4=B8=AD=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E9=97=AE=E5=8F=B7=E5=A4=84=E7=90=862?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 29662ea9f..4ccaa7d36 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -141,8 +141,8 @@ module RepositoriesHelper s_content = File.expand_path(s_content, file_path) s_content = s_content.split("#{Rails.root}/")[1] # content = content.gsub(s[0], "/#{s_content}") - s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{s_content}?ref=#{ref}"].join - s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{s_content}&ref=#{ref}"].join if s_content.include?("?") + join_xxx = s_content.include?("?") ? "&" : "?" + s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{s_content}#{join_xxx}ref=#{ref}"].join case k.to_s when 'ss_src' content = content.gsub("src=\"#{s[0]}\"", "src=\"#{s_content}\"") From d5807c0df007e611c19f9ab5cd7e25e4a7b96f9e Mon Sep 17 00:00:00 2001 From: chenjing Date: Thu, 15 Jun 2023 17:45:07 +0800 Subject: [PATCH 14/30] cla send issue journal --- .../organizations/clas_controller.rb | 1 + app/controllers/pull_requests_controller.rb | 1 + .../pull_requests/send_journal_service.rb | 32 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 app/services/pull_requests/send_journal_service.rb diff --git a/app/controllers/organizations/clas_controller.rb b/app/controllers/organizations/clas_controller.rb index 953cc9d5c..ae88ee2f1 100644 --- a/app/controllers/organizations/clas_controller.rb +++ b/app/controllers/organizations/clas_controller.rb @@ -1,6 +1,7 @@ class Organizations::ClasController < Organizations::BaseController before_action :load_organization before_action :load_cla, only: [:show, :update, :destroy] + before_action :check_user_can_edit_org, only: [:create, :update, :destroy] def index @cla = @organization.cla diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 0cf022f7c..037e201bf 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -67,6 +67,7 @@ class PullRequestsController < ApplicationController Issues::CreateForm.new({subject: params[:title], description: params[:body].blank? ? params[:body] : params[:body].b}).validate! @pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params) if @gitea_pull_request[:status] == :success + PullRequests::SendJournalService.call(@project, @pull_request, current_user) @pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"], @gitea_pull_request[:body]["id"]) reviewers = User.where(id: params[:reviewer_ids]) @pull_request.reviewers = reviewers diff --git a/app/services/pull_requests/send_journal_service.rb b/app/services/pull_requests/send_journal_service.rb new file mode 100644 index 000000000..16e14ca2b --- /dev/null +++ b/app/services/pull_requests/send_journal_service.rb @@ -0,0 +1,32 @@ +class PullRequests::SendJournalService < ApplicationService + + def initialize(project, pull_request,current_user) + @project = project + @issue = pull_request + @current_user = current_user + @org = project.owner + end + + def call + if @org.enabling_cla && @org.cla.present? && @org.cla.pr_need && !@org.is_member?(@current_user&.id) + ActiveRecord::Base.transaction do + sender_id = if Rails.env.development? + User.last.id + else + 87461 + end + journal_params = { + journalized_id: @issue.id , + journalized_type: "Issue", + user_id: sender_id , + notes: "@xxx 您好!欢迎参与 #{@project.name} 的贡献。首次进行贡献请完成《#{@project.owner.cla.name}》的签署,签署完成后,项目成员才可查看到您的合并请求", + } + journal = Journal.new journal_params + if journal.save + TouchWebhookJob.set(wait: 5.seconds).perform_later('PullRequestComment', @issue&.id, sender_id, journal.id, 'created', {}) + push_activity_2_blockchain("issue_comment_create", journal) if Site.has_blockchain? && @project.use_blockchain + end + end + end + end +end From 74dcdebe5ebf2bf33c242d7cdffe9497372406ca Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Fri, 16 Jun 2023 08:44:26 +0800 Subject: [PATCH 15/30] add user_cla response --- app/controllers/users/clas_controller.rb | 2 ++ app/views/users/clas/_detail.json.jbuilder | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/users/clas_controller.rb b/app/controllers/users/clas_controller.rb index d5e93436e..864e1a7b4 100644 --- a/app/controllers/users/clas_controller.rb +++ b/app/controllers/users/clas_controller.rb @@ -1,4 +1,6 @@ class Users::ClasController < Users::BaseController + before_action :require_login + before_action :private_user_resources! def index @user_clas = UserCla.where(user: @_observed_user) end diff --git a/app/views/users/clas/_detail.json.jbuilder b/app/views/users/clas/_detail.json.jbuilder index 07bc5070b..5b6d246e5 100644 --- a/app/views/users/clas/_detail.json.jbuilder +++ b/app/views/users/clas/_detail.json.jbuilder @@ -5,4 +5,7 @@ json.state user_cla.state json.created_at format_time(user_cla.created_at) json.cla do json.partial! "/organizations/clas/detail", locals: {cla: user_cla.cla} -end \ No newline at end of file +end +json.organization do + json.partial! "organizations/organizations/simple", organization: user_cla.cla.organization + end \ No newline at end of file From fb4a44a6fa4b1ac77e45235e1cfb8af9935fbca8 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Fri, 16 Jun 2023 10:07:06 +0800 Subject: [PATCH 16/30] cla pr and destroy user_cla --- app/controllers/users/clas_controller.rb | 24 ++++++++++++++----- app/models/cla.rb | 4 +++- .../pull_requests/send_journal_service.rb | 2 +- app/views/projects/_detail.json.jbuilder | 1 + app/views/pull_requests/index.json.jbuilder | 4 ++++ config/routes.rb | 2 +- 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/controllers/users/clas_controller.rb b/app/controllers/users/clas_controller.rb index 864e1a7b4..bede9ac81 100644 --- a/app/controllers/users/clas_controller.rb +++ b/app/controllers/users/clas_controller.rb @@ -2,20 +2,32 @@ class Users::ClasController < Users::BaseController before_action :require_login before_action :private_user_resources! def index - @user_clas = UserCla.where(user: @_observed_user) + @user_clas = UserCla.where(user: current_user) end def create - tip_exception("已签署过该组织CLA!") if @_observed_user.user_clas.where(cla_id: params[:cla_id]).size > 0 - ActiveRecord::Base.transaction do - Users::UserClaForm.new(user_cla_params).validate! - @user_cla = UserCla.build(user_cla_params, @_observed_user.id) - render_ok + @user_cla = current_user.user_clas.find_by(cla_id: params[:cla_id]) + if @user_cla + @user_cla.update_attributes(state: 1) + else + ActiveRecord::Base.transaction do + Users::UserClaForm.new(user_cla_params).validate! + @user_cla = UserCla.build(user_cla_params, current_user.id) + + end end + render_ok rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) end + + def destroy + @user_cla = current_user.user_clas.find_by(cla_id: params[:cla_id]) + @user_cla.update_attributes(state: 2) + render_ok + end + private def user_cla_params diff --git a/app/models/cla.rb b/app/models/cla.rb index 11f86dcd6..fca050430 100644 --- a/app/models/cla.rb +++ b/app/models/cla.rb @@ -36,7 +36,9 @@ class Cla < ApplicationRecord ) end - + def valid_sign(user_id) + user_clas.where(user_id: user_id, state:1).present? + end def fresh_count update(count:self.users.count) end diff --git a/app/services/pull_requests/send_journal_service.rb b/app/services/pull_requests/send_journal_service.rb index 16e14ca2b..67cc6ca89 100644 --- a/app/services/pull_requests/send_journal_service.rb +++ b/app/services/pull_requests/send_journal_service.rb @@ -8,7 +8,7 @@ class PullRequests::SendJournalService < ApplicationService end def call - if @org.enabling_cla && @org.cla.present? && @org.cla.pr_need && !@org.is_member?(@current_user&.id) + if @org.enabling_cla && @org.cla.present? && @org.cla.pr_need && !@org.is_member?(@current_user&.id) && !@org.cla.valid_sign(@current_user&.id) ActiveRecord::Base.transaction do sender_id = if Rails.env.development? User.last.id diff --git a/app/views/projects/_detail.json.jbuilder b/app/views/projects/_detail.json.jbuilder index ed23fdef2..e60aaed8a 100644 --- a/app/views/projects/_detail.json.jbuilder +++ b/app/views/projects/_detail.json.jbuilder @@ -3,6 +3,7 @@ json.identifier project.identifier json.name project.name json.description project.description json.is_public project.is_public +json.pr_need @project.owner&.cla.try(:pr_need) json.owner do json.partial! "/users/user_simple", locals: {user: project.owner} end \ No newline at end of file diff --git a/app/views/pull_requests/index.json.jbuilder b/app/views/pull_requests/index.json.jbuilder index b7f642118..55dac139a 100644 --- a/app/views/pull_requests/index.json.jbuilder +++ b/app/views/pull_requests/index.json.jbuilder @@ -10,7 +10,11 @@ json.project_name @project.name json.project_author @project.owner.try(:login) json.project_author_name @project.owner.try(:show_real_name) json.has_created_pull_requests @project.pull_requests.size > 0 +<<<<<<< 74dcdebe5ebf2bf33c242d7cdffe9497372406ca json.disable_pr_vew @project.pr_view_admin? && !@project.manager?(current_user) +======= +json.pr_need @project.owner&.cla.try(:pr_need) +>>>>>>> cla pr and destroy user_cla json.issues do json.array! @issues.to_a do |issue| diff --git a/config/routes.rb b/config/routes.rb index 6ab9f228c..90526f9e6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -390,7 +390,7 @@ Rails.application.routes.draw do scope module: :users do resource :interest, only: [:create] - resources :clas, only: [:index,:create] + resources :clas resources :accounts, only: [:show, :update] do resource :phone_bind, only: [:create] resource :email_bind, only: [:create] From d407b3c67444b6d13384aacd85b1343c447514fa Mon Sep 17 00:00:00 2001 From: xxqfamous Date: Wed, 7 Jun 2023 11:03:49 +0800 Subject: [PATCH 17/30] =?UTF-8?q?=E7=A6=81=E6=AD=A2pr=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/pull_requests/index.json.jbuilder | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/views/pull_requests/index.json.jbuilder b/app/views/pull_requests/index.json.jbuilder index 55dac139a..b888c99fd 100644 --- a/app/views/pull_requests/index.json.jbuilder +++ b/app/views/pull_requests/index.json.jbuilder @@ -10,11 +10,8 @@ json.project_name @project.name json.project_author @project.owner.try(:login) json.project_author_name @project.owner.try(:show_real_name) json.has_created_pull_requests @project.pull_requests.size > 0 -<<<<<<< 74dcdebe5ebf2bf33c242d7cdffe9497372406ca json.disable_pr_vew @project.pr_view_admin? && !@project.manager?(current_user) -======= json.pr_need @project.owner&.cla.try(:pr_need) ->>>>>>> cla pr and destroy user_cla json.issues do json.array! @issues.to_a do |issue| From fed604989f81f221119aaab6792cc8f2a161f163 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Fri, 16 Jun 2023 10:35:10 +0800 Subject: [PATCH 18/30] cla show add response --- app/controllers/organizations/clas_controller.rb | 3 +++ app/models/organization.rb | 5 +++++ app/views/organizations/clas/show.json.jbuilder | 1 + 3 files changed, 9 insertions(+) diff --git a/app/controllers/organizations/clas_controller.rb b/app/controllers/organizations/clas_controller.rb index ae88ee2f1..2549d7411 100644 --- a/app/controllers/organizations/clas_controller.rb +++ b/app/controllers/organizations/clas_controller.rb @@ -11,6 +11,9 @@ class Organizations::ClasController < Organizations::BaseController @is_admin = can_edit_org? @is_member = @organization.is_member?(current_user.id) @is_sign = @organization.is_sign?(current_user.id) + @cla_sign_email = if @is_sign + @organization.cla_sign_email(current_user.id) + end end def create diff --git a/app/models/organization.rb b/app/models/organization.rb index f3df5da18..5c3ce6d2b 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -112,6 +112,11 @@ class Organization < Owner cla.user_clas.where(user_id: user_id).present? end + def cla_sign_email(user_id) + cla.user_clas.find_by(user_id: user_id)&.email + end + + def is_owner?(user_id) team_users.joins(:team).where(user_id: user_id, teams: {authorize: %w(owner)}).present? end diff --git a/app/views/organizations/clas/show.json.jbuilder b/app/views/organizations/clas/show.json.jbuilder index 1660b4d07..8c55f38e2 100644 --- a/app/views/organizations/clas/show.json.jbuilder +++ b/app/views/organizations/clas/show.json.jbuilder @@ -1,6 +1,7 @@ json.partial! "detail", cla: @cla, organization: @organization json.is_admin @is_admin json.is_sign @is_sign +json.cla_sign_email @cla_sign_email json.is_member @is_member json.organization do json.partial! "organizations/organizations/simple", organization: @organization From a04e0508d6d1f0fcdcb3dc88aee6a6041a05c26e Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Fri, 16 Jun 2023 11:01:27 +0800 Subject: [PATCH 19/30] update --- app/controllers/users/clas_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/clas_controller.rb b/app/controllers/users/clas_controller.rb index bede9ac81..9d659761a 100644 --- a/app/controllers/users/clas_controller.rb +++ b/app/controllers/users/clas_controller.rb @@ -23,7 +23,7 @@ class Users::ClasController < Users::BaseController end def destroy - @user_cla = current_user.user_clas.find_by(cla_id: params[:cla_id]) + @user_cla = current_user.user_clas.find params[:id] @user_cla.update_attributes(state: 2) render_ok end From 1727435aa69c1a8dd064291e620490d55c4fb1a6 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Fri, 16 Jun 2023 11:58:31 +0800 Subject: [PATCH 20/30] add pull request state --- app/models/organization.rb | 2 +- app/models/pull_request.rb | 3 ++- app/models/user_cla.rb | 13 +++++++++++++ app/services/pull_requests/send_journal_service.rb | 4 +++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/models/organization.rb b/app/models/organization.rb index 5c3ce6d2b..cd533d32d 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -109,7 +109,7 @@ class Organization < Owner def is_sign?(user_id) return false if cla.nil? - cla.user_clas.where(user_id: user_id).present? + cla.user_clas.where(user_id: user_id, status: 1).present? end def cla_sign_email(user_id) diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index e46777951..0142f27f6 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -24,10 +24,11 @@ # class PullRequest < ApplicationRecord - #status 0 默认未合并, 1表示合并, 2表示请求拒绝(或已关闭) + #status 0 默认未合并, 1表示合并, 2表示请求拒绝(或已关闭) ,3 表示未签署CLA OPEN = 0 MERGED = 1 CLOSED = 2 + NEEDCLA = 3 belongs_to :issue belongs_to :user diff --git a/app/models/user_cla.rb b/app/models/user_cla.rb index 005533ce7..cd3cea8a8 100644 --- a/app/models/user_cla.rb +++ b/app/models/user_cla.rb @@ -26,6 +26,10 @@ class UserCla < ApplicationRecord cla.fresh_count end + before_save do + fresh_pull_request + end + def self.build(params,user_id) self.create!(user_id: user_id, cla_id: params[:cla_id], @@ -35,4 +39,13 @@ class UserCla < ApplicationRecord ) end + def fresh_pull_request + gitea_ids = Project.where(user_id: cla.user_id).pluck(:gpid) + if state == "signed" + PullRequest.where(user_id: user_id, gitea_id: gitea_ids, status:3).update_all(status:0) + else + PullRequest.where(user_id: user_id, gitea_id: gitea_ids, status:0).update_all(status:3) + end + end + end diff --git a/app/services/pull_requests/send_journal_service.rb b/app/services/pull_requests/send_journal_service.rb index 67cc6ca89..816b13f11 100644 --- a/app/services/pull_requests/send_journal_service.rb +++ b/app/services/pull_requests/send_journal_service.rb @@ -2,7 +2,8 @@ class PullRequests::SendJournalService < ApplicationService def initialize(project, pull_request,current_user) @project = project - @issue = pull_request + @pull_request = pull_request + @issue = pull_request.issue @current_user = current_user @org = project.owner end @@ -23,6 +24,7 @@ class PullRequests::SendJournalService < ApplicationService } journal = Journal.new journal_params if journal.save + @pull_request.update_attributes(status: 3) TouchWebhookJob.set(wait: 5.seconds).perform_later('PullRequestComment', @issue&.id, sender_id, journal.id, 'created', {}) push_activity_2_blockchain("issue_comment_create", journal) if Site.has_blockchain? && @project.use_blockchain end From 4077de736032e1e2291cc505dbfcb1a5fb7f4ed6 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Fri, 16 Jun 2023 16:27:07 +0800 Subject: [PATCH 21/30] fix cla error for pr --- app/views/pull_requests/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/pull_requests/index.json.jbuilder b/app/views/pull_requests/index.json.jbuilder index b888c99fd..2c17dcca6 100644 --- a/app/views/pull_requests/index.json.jbuilder +++ b/app/views/pull_requests/index.json.jbuilder @@ -11,7 +11,7 @@ json.project_author @project.owner.try(:login) json.project_author_name @project.owner.try(:show_real_name) json.has_created_pull_requests @project.pull_requests.size > 0 json.disable_pr_vew @project.pr_view_admin? && !@project.manager?(current_user) -json.pr_need @project.owner&.cla.try(:pr_need) +json.pr_need @project.owner.class == User ? false : @project.owner&.cla.try(:pr_need) json.issues do json.array! @issues.to_a do |issue| From 633a6ba585962b70b150e373f5e4bee0245b5cef Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Fri, 16 Jun 2023 17:09:55 +0800 Subject: [PATCH 22/30] update JournalService notes --- app/services/pull_requests/send_journal_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/pull_requests/send_journal_service.rb b/app/services/pull_requests/send_journal_service.rb index 816b13f11..17f6fdabd 100644 --- a/app/services/pull_requests/send_journal_service.rb +++ b/app/services/pull_requests/send_journal_service.rb @@ -20,7 +20,7 @@ class PullRequests::SendJournalService < ApplicationService journalized_id: @issue.id , journalized_type: "Issue", user_id: sender_id , - notes: "@xxx 您好!欢迎参与 #{@project.name} 的贡献。首次进行贡献请完成《#{@project.owner.cla.name}》的签署,签署完成后,项目成员才可查看到您的合并请求", + notes: "@#{@current_user.nickname} 您好!欢迎参与 #{@project.name} 的贡献。首次进行贡献请完成《#{@project.owner.cla.name}》的签署,签署完成后,项目成员才可查看到您的合并请求", } journal = Journal.new journal_params if journal.save From 7a9be101945dec9f2f155d7a61050e4c2838e900 Mon Sep 17 00:00:00 2001 From: chenjing Date: Mon, 19 Jun 2023 10:44:58 +0800 Subject: [PATCH 23/30] fix bug --- app/models/organization.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/organization.rb b/app/models/organization.rb index cd533d32d..fb1659d1a 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -109,7 +109,7 @@ class Organization < Owner def is_sign?(user_id) return false if cla.nil? - cla.user_clas.where(user_id: user_id, status: 1).present? + cla.user_clas.where(user_id: user_id, state: 1).present? end def cla_sign_email(user_id) From 86a616fc2ffd4971d8fa2169d203ec2672527ad6 Mon Sep 17 00:00:00 2001 From: chenjing Date: Mon, 19 Jun 2023 11:14:45 +0800 Subject: [PATCH 24/30] fix org delete error --- app/services/admins/delete_organization_service.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/services/admins/delete_organization_service.rb b/app/services/admins/delete_organization_service.rb index d5c9bd2c5..2a7b4aab1 100644 --- a/app/services/admins/delete_organization_service.rb +++ b/app/services/admins/delete_organization_service.rb @@ -6,9 +6,6 @@ class Admins::DeleteOrganizationService < Gitea::ClientService end def call - response = delete(url, params) - render_status(response) - Gitea::Organization::DeleteService.call(token,name) end From 325f3453813b224d0ed78622f797d7cb4aace385 Mon Sep 17 00:00:00 2001 From: chenjing Date: Mon, 19 Jun 2023 15:10:16 +0800 Subject: [PATCH 25/30] fix --- app/models/user_cla.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/user_cla.rb b/app/models/user_cla.rb index cd3cea8a8..848a825db 100644 --- a/app/models/user_cla.rb +++ b/app/models/user_cla.rb @@ -30,8 +30,8 @@ class UserCla < ApplicationRecord fresh_pull_request end - def self.build(params,user_id) - self.create!(user_id: user_id, + def self.build(params,current_user_id) + self.create!(user_id: current_user_id, cla_id: params[:cla_id], real_name: params[:real_name], email: params[:email], @@ -40,11 +40,11 @@ class UserCla < ApplicationRecord end def fresh_pull_request - gitea_ids = Project.where(user_id: cla.user_id).pluck(:gpid) + project_ids = cla.organization.projects.pluck(:id) if state == "signed" - PullRequest.where(user_id: user_id, gitea_id: gitea_ids, status:3).update_all(status:0) + PullRequest.where(user_id: user_id, project_id: project_ids, status:3).update_all(status:0) else - PullRequest.where(user_id: user_id, gitea_id: gitea_ids, status:0).update_all(status:3) + PullRequest.where(user_id: user_id, project_id: project_ids, status:0).update_all(status:3) end end From 65eaafe003178126aada56f9a2343cf62e257409 Mon Sep 17 00:00:00 2001 From: chenjing Date: Mon, 19 Jun 2023 15:25:38 +0800 Subject: [PATCH 26/30] fix admins org and show private org's cla --- app/controllers/organizations/clas_controller.rb | 1 - app/views/admins/organizations/show.html.erb | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/organizations/clas_controller.rb b/app/controllers/organizations/clas_controller.rb index 2549d7411..cc3f4e11f 100644 --- a/app/controllers/organizations/clas_controller.rb +++ b/app/controllers/organizations/clas_controller.rb @@ -61,7 +61,6 @@ class Organizations::ClasController < Organizations::BaseController def load_organization @organization = Organization.find_by(login: params[:organization_id]) || Organization.find_by(id: params[:organization_id]) return render_not_found("组织不存在") if @organization.nil? - return render_forbidden("没有查看组织的权限") if org_limited_condition || org_privacy_condition end def load_cla diff --git a/app/views/admins/organizations/show.html.erb b/app/views/admins/organizations/show.html.erb index 102392567..501b1b5ad 100644 --- a/app/views/admins/organizations/show.html.erb +++ b/app/views/admins/organizations/show.html.erb @@ -28,11 +28,9 @@
<%= f.input :lastname, label: '姓名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @org.real_name } %>
-
- <%= f.input :cla, label: '是否开通CLA', wrapper_html: { class: 'col-md-3' }, input_html: { class: 'col-md-11', value: @org.cla } %> + <%= f.input :enabling_cla, as: :boolean, label: '开通CLA', checked_value: 1, unchecked_value: 0 %>
- <% end %>

组织项目

From c0f0b90347cccc0bc0088b627785f2a5bdae032e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 19 Jun 2023 15:46:19 +0800 Subject: [PATCH 27/30] =?UTF-8?q?fixed=20job=E4=B8=ADissue=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/touch_webhook_job.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/jobs/touch_webhook_job.rb b/app/jobs/touch_webhook_job.rb index 0a8c03e9f..514fa6950 100644 --- a/app/jobs/touch_webhook_job.rb +++ b/app/jobs/touch_webhook_job.rb @@ -49,9 +49,9 @@ class TouchWebhookJob < ApplicationJob when 'IssueComment' issue_id, sender_id, comment_id, action_type, comment_json = args[0], args[1], args[2], args[3], args[4] issue = Issue.find_by_id issue_id - comment = issue.comment_journals.find_by_id comment_id sender = User.find_by_id sender_id - return if issue.nil? || sender.nil? + return if issue.nil? || sender.nil? + comment = issue.comment_journals.find_by_id comment_id return if action_type == 'edited' && comment_json.blank? issue.project.webhooks.each do |webhook| @@ -63,10 +63,10 @@ class TouchWebhookJob < ApplicationJob when 'PullRequestComment' issue_id, sender_id, comment_id, action_type, comment_json = args[0], args[1], args[2], args[3], args[4] issue = Issue.find_by_id(issue_id) - comment = issue.comment_journals.find_by_id comment_id sender = User.find_by_id sender_id pull = issue.try(:pull_request) - return if pull.nil? || sender.nil? + return if issue.nil? || pull.nil? || sender.nil? + comment = issue.comment_journals.find_by_id comment_id return if action_type == 'edited' && comment_json.blank? pull.project.webhooks.each do |webhook| From 99f2c5b99613fb9399dc5a96fe5d352bb0b6d590 Mon Sep 17 00:00:00 2001 From: chenjing Date: Mon, 19 Jun 2023 16:43:06 +0800 Subject: [PATCH 28/30] add user cla show --- app/controllers/users/clas_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/users/clas_controller.rb b/app/controllers/users/clas_controller.rb index 9d659761a..51a93819b 100644 --- a/app/controllers/users/clas_controller.rb +++ b/app/controllers/users/clas_controller.rb @@ -4,6 +4,10 @@ class Users::ClasController < Users::BaseController def index @user_clas = UserCla.where(user: current_user) end + + def show + @user_cla = current_user.user_clas.find params[:id] + end def create @user_cla = current_user.user_clas.find_by(cla_id: params[:cla_id]) From 65816a980b4187eb7e6a3467d792a56bab0d8889 Mon Sep 17 00:00:00 2001 From: chenjing Date: Tue, 20 Jun 2023 15:27:03 +0800 Subject: [PATCH 29/30] cla fix and add token verify --- app/controllers/projects_controller.rb | 15 +++- app/controllers/users/clas_controller.rb | 8 +- app/models/cla.rb | 3 +- app/models/user_cla.rb | 14 +++- .../projects/verify_auth_token_service.rb | 83 +++++++++++++++++++ .../pull_requests/send_journal_service.rb | 2 +- app/views/users/clas/_detail.json.jbuilder | 2 +- config/routes.rb | 1 + ...230620030511_add_sign_time_to_user_clas.rb | 5 ++ 9 files changed, 123 insertions(+), 10 deletions(-) create mode 100644 app/services/projects/verify_auth_token_service.rb create mode 100644 db/migrate/20230620030511_add_sign_time_to_user_clas.rb diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 0d7caba05..e5dc7103a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -4,9 +4,9 @@ class ProjectsController < ApplicationController include ProjectsHelper include Acceleratorable - before_action :require_login, except: %i[index branches branches_slice group_type_list simple show fork_users praise_users watch_users recommend banner_recommend about menu_list] - before_action :require_profile_completed, only: [:create, :migrate] - before_action :load_repository, except: %i[index group_type_list migrate create recommend banner_recommend] + before_action :require_login, except: %i[index branches branches_slice group_type_list simple show fork_users praise_users watch_users recommend banner_recommend about menu_list verify_auth_token] + before_action :require_profile_completed, only: [:create, :migrate,:verify_auth_token] + before_action :load_repository, except: %i[index group_type_list migrate create recommend banner_recommend verify_auth_token] before_action :authorizate_user_can_edit_project!, only: %i[update] before_action :project_public?, only: %i[fork_users praise_users watch_users] before_action :request_limit, only: %i[index] @@ -63,6 +63,15 @@ class ProjectsController < ApplicationController tip_exception(e.message) end + def verify_auth_token + data = Projects::VerifyAuthTokenService.call(params[:clone_addr], params[:auth_token]) + if data + render_ok + else + render_error('token验证不通过') + end + end + def migrate Projects::MigrateForm.new(mirror_params).validate! diff --git a/app/controllers/users/clas_controller.rb b/app/controllers/users/clas_controller.rb index 51a93819b..b1e09cacc 100644 --- a/app/controllers/users/clas_controller.rb +++ b/app/controllers/users/clas_controller.rb @@ -11,14 +11,16 @@ class Users::ClasController < Users::BaseController def create @user_cla = current_user.user_clas.find_by(cla_id: params[:cla_id]) - if @user_cla - @user_cla.update_attributes(state: 1) - else + if @user_cla.nil? ActiveRecord::Base.transaction do Users::UserClaForm.new(user_cla_params).validate! @user_cla = UserCla.build(user_cla_params, current_user.id) end + elsif @user_cla.state == "failed" + @user_cla.update_by_params(user_cla_params) + elsif @user_cla.state == "signed" + return render_error('协议生效中,请勿重复签署') end render_ok rescue Exception => e diff --git a/app/models/cla.rb b/app/models/cla.rb index fca050430..6bbfb6143 100644 --- a/app/models/cla.rb +++ b/app/models/cla.rb @@ -40,6 +40,7 @@ class Cla < ApplicationRecord user_clas.where(user_id: user_id, state:1).present? end def fresh_count - update(count:self.users.count) + number = self.user_clas.where(state: 1).count + update(count: number) end end diff --git a/app/models/user_cla.rb b/app/models/user_cla.rb index 848a825db..b109a74fa 100644 --- a/app/models/user_cla.rb +++ b/app/models/user_cla.rb @@ -10,6 +10,7 @@ # state :integer default("0") # created_at :datetime not null # updated_at :datetime not null +# sign_time :datetime # # Indexes # @@ -22,7 +23,8 @@ class UserCla < ApplicationRecord belongs_to :cla # identity 0: 教师教授 1: 学生, 2: 专业人士, 3: 开发者 enum state: { deafult: 0, signed: 1, failed: 2} - after_create do + + after_save do cla.fresh_count end @@ -35,10 +37,20 @@ class UserCla < ApplicationRecord cla_id: params[:cla_id], real_name: params[:real_name], email: params[:email], + sign_time: Time.now, state: 1 ) end + def update_by_params(params) + update(\ + state: 1, + sign_time: Time.now, + real_name: params[:real_name], + email: params[:email], + ) + end + def fresh_pull_request project_ids = cla.organization.projects.pluck(:id) if state == "signed" diff --git a/app/services/projects/verify_auth_token_service.rb b/app/services/projects/verify_auth_token_service.rb new file mode 100644 index 000000000..1318bb9db --- /dev/null +++ b/app/services/projects/verify_auth_token_service.rb @@ -0,0 +1,83 @@ +class Projects::VerifyAuthTokenService < ApplicationService + attr_accessor :url, :token + + def initialize(url, token) + @url = url + @token = token + @repo = nil + @owner = nil + @website = nil + @success = nil + end + + def call + Rails.logger.info("###### VerifyAuthTokenService begin ######") + regular_url + to_verify + Rails.logger.info("##### VerifyAuthTokenService end ######") + return @success + end + + private + def regular_url + regx = /\/\/[\s\S]*.git$/ #获取字串 + data = (regx.match @url).to_s[2..-5].split("/") + @website = data[0] + @owner = data[1] + @repo = data[2] + end + + + def to_verify + data = case @website + when "github.com" + github_verify + when "gitlab.com" + gitlab_verify + when "gitee.com" + gitee_verify + end + end + + def gitee_verify + url = "/api/v5/repos/#{@owner}/#{@repo}" + api_url= "https://gitee.com" + client = Faraday.new(url: api_url) + client.options["open_timeout"] = 1 + client.options["timeout"] = 1 + client.options["write_timeout"] = 1 + req_params={ + access_token: @token, + owner: @owner, + repo: @repo + } + response = client.public_send("get", url, req_params) + @success = true if response.status == 200 + end + + def github_verify + url = "/octocat" + api_url= "https://api.github.com" + client = Faraday.new(url: api_url) + client.options["open_timeout"] = 1 + client.options["timeout"] = 1 + client.options["write_timeout"] = 1 + client.headers["Authorization"] = "Bearer #{@token}" + response = client.public_send("get", url) + @success = true if response.status == 200 + end + + def gitlab_verify + url = "/api/v4/projects" + api_url= "https://gitlab.com" + client = Faraday.new(url: api_url) + client.options["open_timeout"] = 1 + client.options["timeout"] = 1 + client.options["write_timeout"] = 1 + req_params={ + private_token: @token + } + response = client.public_send("get", url, req_params) + @success = true if response.status == 200 + end +end \ No newline at end of file diff --git a/app/services/pull_requests/send_journal_service.rb b/app/services/pull_requests/send_journal_service.rb index 17f6fdabd..578faa4b9 100644 --- a/app/services/pull_requests/send_journal_service.rb +++ b/app/services/pull_requests/send_journal_service.rb @@ -20,7 +20,7 @@ class PullRequests::SendJournalService < ApplicationService journalized_id: @issue.id , journalized_type: "Issue", user_id: sender_id , - notes: "@#{@current_user.nickname} 您好!欢迎参与 #{@project.name} 的贡献。首次进行贡献请完成《#{@project.owner.cla.name}》的签署,签署完成后,项目成员才可查看到您的合并请求", + notes: "#{@current_user.nickname}您好!欢迎参与 #{@project.name} 的贡献。首次进行贡献请完成《#{@project.owner.cla.name}》的签署,签署完成后,项目成员才可查看到您的合并请求", } journal = Journal.new journal_params if journal.save diff --git a/app/views/users/clas/_detail.json.jbuilder b/app/views/users/clas/_detail.json.jbuilder index 5b6d246e5..106145f6e 100644 --- a/app/views/users/clas/_detail.json.jbuilder +++ b/app/views/users/clas/_detail.json.jbuilder @@ -2,7 +2,7 @@ json.id user_cla.id json.real_name user_cla.real_name json.email user_cla.email json.state user_cla.state -json.created_at format_time(user_cla.created_at) +json.created_at format_time(user_cla.sign_time) json.cla do json.partial! "/organizations/clas/detail", locals: {cla: user_cla.cla} end diff --git a/config/routes.rb b/config/routes.rb index 90526f9e6..0d04c498a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -241,6 +241,7 @@ Rails.application.routes.draw do get :group_type_list get :recommend get :banner_recommend + post :verify_auth_token end end diff --git a/db/migrate/20230620030511_add_sign_time_to_user_clas.rb b/db/migrate/20230620030511_add_sign_time_to_user_clas.rb new file mode 100644 index 000000000..f913f244f --- /dev/null +++ b/db/migrate/20230620030511_add_sign_time_to_user_clas.rb @@ -0,0 +1,5 @@ +class AddSignTimeToUserClas < ActiveRecord::Migration[5.2] + def change + add_column :user_clas, :sign_time, :datetime + end +end From 1b09c93b5e0198c2e89805c5696959d48d1eb14c Mon Sep 17 00:00:00 2001 From: chenjing Date: Tue, 20 Jun 2023 15:50:11 +0800 Subject: [PATCH 30/30] change verify token response --- app/controllers/projects_controller.rb | 6 +----- app/services/projects/verify_auth_token_service.rb | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e5dc7103a..04982d8ce 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -65,11 +65,7 @@ class ProjectsController < ApplicationController def verify_auth_token data = Projects::VerifyAuthTokenService.call(params[:clone_addr], params[:auth_token]) - if data - render_ok - else - render_error('token验证不通过') - end + render_ok({data: data}) end def migrate diff --git a/app/services/projects/verify_auth_token_service.rb b/app/services/projects/verify_auth_token_service.rb index 1318bb9db..36dcb106f 100644 --- a/app/services/projects/verify_auth_token_service.rb +++ b/app/services/projects/verify_auth_token_service.rb @@ -7,7 +7,7 @@ class Projects::VerifyAuthTokenService < ApplicationService @repo = nil @owner = nil @website = nil - @success = nil + @success = false end def call