Merge branch 'pre_trustie_server' into trustie_server

This commit is contained in:
xxq250 2023-06-21 16:19:54 +08:00
commit f094c3a84c
88 changed files with 932 additions and 172 deletions

View File

@ -0,0 +1,65 @@
$(document).on('turbolinks:load', function(){
if ($('body.admins-organizations-index-page').length > 0) {
var showSuccessNotify = function() {
$.notify({
message: '操作成功'
},{
type: 'success'
});
}
// organizations open cla
$('.organizations-list-container').on('click', '.open-cla-action', function(){
var $openClaAction = $(this);
var $closeClaAction = $openClaAction.siblings('.close-cla-action');
var userId = $openClaAction.data('id');
customConfirm({
content: '确认开通吗?',
ok: function () {
$.ajax({
url: '/admins/organizations/' + userId + '/open_cla',
method: 'POST',
dataType: 'json',
success: function() {
showSuccessNotify();
$closeClaAction.show();
$openClaAction.hide();
},
error: function(res){
$.notify({ message: res.responseJSON.message }, { type: 'danger' });
}
});
}
})
});
// organizations close cla
$('.organizations-list-container').on('click', '.close-cla-action', function(){
var $closeClaAction = $(this);
var $openClaAction= $closeClaAction.siblings('.open-cla-action');
var userId = $openClaAction.data('id');
customConfirm({
content: '确认关闭吗?',
ok: function () {
$.ajax({
url: '/admins/organizations/' + userId + '/close_cla',
method: 'POST',
dataType: 'json',
success: function() {
showSuccessNotify();
$openClaAction.show();
$closeClaAction.hide();
},
error: function(res){
$.notify({ message: res.responseJSON.message }, { type: 'danger' });
}
});
}
})
});
}
});

View File

@ -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.

View File

@ -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.

View File

@ -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/

View File

@ -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/

View File

@ -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

View File

@ -9,6 +9,22 @@ class Admins::OrganizationsController < Admins::BaseController
@orgs = paginate orgs
end
def open_cla
@org.open_cla!
render_ok
end
def close_cla
if @org.cla.nil?
@org.close_cla!
render_ok
else
render_error(' 该组织已创建CLA 不允许关闭')
end
end
def show
end

View File

@ -0,0 +1,70 @@
class Organizations::ClasController < Organizations::BaseController
before_action :load_organization
before_action :load_cla, only: [:show, :update, :destroy]
before_action :check_user_can_edit_org, only: [:create, :update, :destroy]
def index
@cla = @organization.cla
end
def show
@is_admin = can_edit_org?
@is_member = @organization.is_member?(current_user.id)
@is_sign = @organization.is_sign?(current_user.id)
@cla_sign_email = if @is_sign
@organization.cla_sign_email(current_user.id)
end
end
def create
tip_exception("您的组织还未拥有创建CLA权限请联系管理员") if @organization.enabling_cla == false
ActiveRecord::Base.transaction do
if @organization.cla.present?
return tip_exception("组织已存在CLA")
else
Organizations::CreateClaForm.new(cla_params).validate!
@cla = Cla.build(cla_params,@organization.id)
end
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
def update
ActiveRecord::Base.transaction do
Organizations::CreateClaForm.new(cla_params).validate!
@cla.update(cla_params)
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
def destroy
tip_exception("组织CLA已被签署无法删除") if @cla.user_clas.size > 0
ActiveRecord::Base.transaction do
@cla.destroy!
end
render_ok
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
private
def cla_params
params.permit(:name, :key, :content, :pr_need)
end
def load_organization
@organization = Organization.find_by(login: params[:organization_id]) || Organization.find_by(id: params[:organization_id])
return render_not_found("组织不存在") if @organization.nil?
end
def load_cla
@cla = Cla.find_by!(organization:@organization, key: params[:id])
end
end

View File

@ -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,11 @@ class ProjectsController < ApplicationController
tip_exception(e.message)
end
def verify_auth_token
data = Projects::VerifyAuthTokenService.call(params[:clone_addr], params[:auth_token])
render_ok({data: data})
end
def migrate
Projects::MigrateForm.new(mirror_params).validate!

View File

@ -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

View File

@ -0,0 +1,43 @@
class Users::ClasController < Users::BaseController
before_action :require_login
before_action :private_user_resources!
def index
@user_clas = UserCla.where(user: current_user)
end
def show
@user_cla = current_user.user_clas.find params[:id]
end
def create
@user_cla = current_user.user_clas.find_by(cla_id: params[:cla_id])
if @user_cla.nil?
ActiveRecord::Base.transaction do
Users::UserClaForm.new(user_cla_params).validate!
@user_cla = UserCla.build(user_cla_params, current_user.id)
end
elsif @user_cla.state == "failed"
@user_cla.update_by_params(user_cla_params)
elsif @user_cla.state == "signed"
return render_error('协议生效中,请勿重复签署')
end
render_ok
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
def destroy
@user_cla = current_user.user_clas.find params[:id]
@user_cla.update_attributes(state: 2)
render_ok
end
private
def user_cla_params
params.permit(:email, :real_name, :cla_id)
end
end

View File

@ -0,0 +1,6 @@
class Organizations::CreateClaForm < BaseForm
KEY_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
attr_accessor :name, :key, :content, :pr_need
validates :name , :key, presence: true
validates :key, format: { with: KEY_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
end

View File

@ -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

View File

@ -0,0 +1,2 @@
module Organizations::ClasHelper
end

View File

@ -0,0 +1,2 @@
module Users::ClasHelper
end

View File

@ -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)
#

View File

@ -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")
# enabling_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)
#

46
app/models/cla.rb Normal file
View File

@ -0,0 +1,46 @@
# == 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,org_id)
self.create!(organization_id: org_id,
name: params[:name],
key: params[:key],
content: params[:content],
pr_need: params[:pr_need]
)
end
def valid_sign(user_id)
user_clas.where(user_id: user_id, state:1).present?
end
def fresh_count
number = self.user_clas.where(state: 1).count
update(count: number)
end
end

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
#

View File

@ -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
end

View File

@ -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
end

View File

@ -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
#

View File

@ -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

View File

@ -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
#

View File

@ -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
#

View File

@ -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

View File

@ -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
end

View File

@ -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")
# enabling_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
@ -108,6 +107,16 @@ 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, state: 1).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
@ -193,4 +202,17 @@ class Organization < Owner
name
end
end
def open_cla!
update_attribute(:enabling_cla, true)
end
def close_cla!
update_attribute(:enabling_cla, false)
end
def open_cla?
enabling_cla == true
end
end

View File

@ -19,6 +19,8 @@
# news_banner_id :integer
# news_content :text(65535)
# memo :text(65535)
# news_title :string(255)
# news_url :string(255)
#
# Indexes
#

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -27,6 +27,7 @@
#
# Indexes
#
# index_repositories_on_identifier (identifier)
# index_repositories_on_project_id (project_id)
# index_repositories_on_user_id (user_id)
#

View File

@ -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

View File

@ -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
#

View File

@ -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
#

View File

@ -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
#

View File

@ -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
#

View File

@ -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
#

View File

@ -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
#

View File

@ -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

View File

@ -6,7 +6,6 @@
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#

View File

@ -6,7 +6,6 @@
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#

View File

@ -6,7 +6,6 @@
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#

View File

@ -6,7 +6,6 @@
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#

View File

@ -6,7 +6,6 @@
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#

View File

@ -6,7 +6,6 @@
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#

View File

@ -6,7 +6,6 @@
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#

View File

@ -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
end

View File

@ -6,7 +6,6 @@
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#

View File

@ -47,6 +47,7 @@
# watchers_count :integer default("0")
# devops_step :integer default("0")
# sign_cla :boolean default("0")
# enabling_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|

View File

@ -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

View File

@ -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

63
app/models/user_cla.rb Normal file
View File

@ -0,0 +1,63 @@
# == 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
# sign_time :datetime
#
# 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}
after_save do
cla.fresh_count
end
before_save do
fresh_pull_request
end
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],
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"
PullRequest.where(user_id: user_id, project_id: project_ids, status:3).update_all(status:0)
else
PullRequest.where(user_id: user_id, project_id: project_ids, status:0).update_all(status:3)
end
end
end

View File

@ -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)

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -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 = false
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

View File

@ -0,0 +1,34 @@
class PullRequests::SendJournalService < ApplicationService
def initialize(project, pull_request,current_user)
@project = project
@pull_request = pull_request
@issue = pull_request.issue
@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) && !@org.cla.valid_sign(@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: "<b>#{@current_user.nickname}</b>您好!欢迎参与 #{@project.name} 的贡献。首次进行贡献请完成《<a href='/#{@project.owner.login}/cla/#{@project.owner.cla.key}' target='_blank'>#{@project.owner.cla.name}</a>》的签署,签署完成后,项目成员才可查看到您的合并请求",
}
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
end
end
end
end

View File

@ -27,11 +27,12 @@
<td><%= link_to org.organization_users_count, "/#{org.login}", target: "_blank" %></td>
<td><%= link_to org.projects_count, "/#{org.login}", target: "_blank" %></td>
<td class="action-container">
<%= 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' %>
<div class="d-inline">
<%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %>
<div class="dropdown-menu more-action-dropdown">
<%= delete_link '删除', admins_organization_path(org, element: ".user-item-#{org.id}"), class: 'dropdown-item delete-user-action' %>
</div>
</div>

View File

@ -28,8 +28,9 @@
<div class="form-row">
<%= f.input :lastname, label: '姓名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @org.real_name } %>
</div>
<div class="form-row">
<%= f.input :enabling_cla, as: :boolean, label: '开通CLA', checked_value: 1, unchecked_value: 0 %>
</div>
</div>
<% end %>
<h3> 组织项目 </h3>

View File

@ -0,0 +1,6 @@
json.id cla.id
json.content cla.content
json.key cla.key
json.name cla.name
json.pr_need cla.pr_need
json.count cla.count

View File

@ -0,0 +1 @@
json.partial! "detail", cla: @cla, organization: @organization

View File

@ -0,0 +1,3 @@
if @cla.present?
json.partial! "detail", cla: @cla
end

View File

@ -0,0 +1,8 @@
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
end

View File

@ -0,0 +1 @@
json.partial! "detail", cla: @cla, organization: @organization

View File

@ -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
json.news_url organization.news_url
json.enabling_cla organization.enabling_cla

View File

@ -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

View File

@ -11,6 +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.class == User ? false : @project.owner&.cla.try(:pr_need)
json.issues do
json.array! @issues.to_a do |issue|

View File

@ -0,0 +1,11 @@
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.sign_time)
json.cla do
json.partial! "/organizations/clas/detail", locals: {cla: user_cla.cla}
end
json.organization do
json.partial! "organizations/organizations/simple", organization: user_cla.cla.organization
end

View File

@ -0,0 +1,3 @@
json.user_clas @user_clas do |user_cla|
json.partial! "detail", user_cla: user_cla
end

View File

@ -0,0 +1 @@
json.partial! "detail", user_cla: @user_cla

View File

@ -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
@ -240,6 +241,7 @@ Rails.application.routes.draw do
get :group_type_list
get :recommend
get :banner_recommend
post :verify_auth_token
end
end
@ -389,7 +391,7 @@ Rails.application.routes.draw do
scope module: :users do
resource :interest, only: [:create]
resources :clas
resources :accounts, only: [:show, :update] do
resource :phone_bind, only: [:create]
resource :email_bind, only: [:create]
@ -847,7 +849,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

View File

@ -0,0 +1,5 @@
class AddClaToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :cla, :boolean, default: false
end
end

View File

@ -0,0 +1,15 @@
class CreateClas < ActiveRecord::Migration[5.2]
def change
create_table :clas do |t|
t.string :name, null:false
t.string :key, null:false
t.text :content
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

View File

@ -0,0 +1,15 @@
class CreateUserClas < ActiveRecord::Migration[5.2]
def change
create_table :user_clas do |t|
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

View File

@ -0,0 +1,5 @@
class ChangeCalToEnablingClaForUsers < ActiveRecord::Migration[5.2]
def change
rename_column :users, :cla ,:enabling_cla
end
end

View File

@ -0,0 +1,5 @@
class AddSignTimeToUserClas < ActiveRecord::Migration[5.2]
def change
add_column :user_clas, :sign_time, :datetime
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Organizations::ClasController, type: :controller do
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Users::ClasController, type: :controller do
end

View File

@ -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

View File

@ -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

5
spec/models/cla_spec.rb Normal file
View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Cla, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe UserCla, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end