Merge remote-tracking branch 'origin/standalone_develop' into standalone_develop
This commit is contained in:
commit
fafae74dec
|
@ -1,11 +1,15 @@
|
||||||
class Organizations::ClasController < Organizations::BaseController
|
class Organizations::ClasController < Organizations::BaseController
|
||||||
before_action :load_organization
|
before_action :load_organization
|
||||||
before_action :load_cla, only: [:show, :update, :destroy]
|
before_action :load_cla, only: [:show, :update, :destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@cla = @organization.cla
|
@cla = @organization.cla
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -15,7 +19,7 @@ class Organizations::ClasController < Organizations::BaseController
|
||||||
return tip_exception("组织已存在CLA!")
|
return tip_exception("组织已存在CLA!")
|
||||||
else
|
else
|
||||||
Organizations::CreateClaForm.new(cla_params).validate!
|
Organizations::CreateClaForm.new(cla_params).validate!
|
||||||
@cla = Cla.build(cla_params)
|
@cla = Cla.build(cla_params,@organization.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
@ -47,7 +51,7 @@ class Organizations::ClasController < Organizations::BaseController
|
||||||
|
|
||||||
private
|
private
|
||||||
def cla_params
|
def cla_params
|
||||||
params.permit(:name, :key, :content, :organization_id, :pr_need)
|
params.permit(:name, :key, :content, :pr_need)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_organization
|
def load_organization
|
||||||
|
@ -57,7 +61,7 @@ class Organizations::ClasController < Organizations::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_cla
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,7 @@ class Users::ClasController < Users::BaseController
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
Users::UserClaForm.new(user_cla_params).validate!
|
Users::UserClaForm.new(user_cla_params).validate!
|
||||||
@user_cla = UserCla.build(user_cla_params, @_observed_user.id)
|
@user_cla = UserCla.build(user_cla_params, @_observed_user.id)
|
||||||
|
render_ok
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Organizations::CreateClaForm < BaseForm
|
class Organizations::CreateClaForm < BaseForm
|
||||||
KEY_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
KEY_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||||
attr_accessor :name, :key, :content, :organization_id, :pr_need
|
attr_accessor :name, :key, :content, :pr_need
|
||||||
validates :name, :organization_id , :key, presence: true
|
validates :name , :key, presence: true
|
||||||
validates :key, format: { with: KEY_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
validates :key, format: { with: KEY_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||||
end
|
end
|
|
@ -27,12 +27,17 @@ class Cla < ApplicationRecord
|
||||||
self.key.parameterize
|
self.key.parameterize
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.build(params)
|
def self.build(params,org_id)
|
||||||
self.create!(organization_id: params[:organization_id],
|
self.create!(organization_id: org_id,
|
||||||
name: params[:name],
|
name: params[:name],
|
||||||
key: params[:key],
|
key: params[:key],
|
||||||
content: params[:content],
|
content: params[:content],
|
||||||
pr_need: params[:pr_need]
|
pr_need: params[:pr_need]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def fresh_count
|
||||||
|
update(count:self.users.count)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -107,6 +107,11 @@ class Organization < Owner
|
||||||
organization_users.where(user_id: user_id).present?
|
organization_users.where(user_id: user_id).present?
|
||||||
end
|
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)
|
def is_owner?(user_id)
|
||||||
team_users.joins(:team).where(user_id: user_id, teams: {authorize: %w(owner)}).present?
|
team_users.joins(:team).where(user_id: user_id, teams: {authorize: %w(owner)}).present?
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,9 @@ class UserCla < ApplicationRecord
|
||||||
belongs_to :cla
|
belongs_to :cla
|
||||||
# identity 0: 教师教授 1: 学生, 2: 专业人士, 3: 开发者
|
# identity 0: 教师教授 1: 学生, 2: 专业人士, 3: 开发者
|
||||||
enum state: { deafult: 0, signed: 1, failed: 2}
|
enum state: { deafult: 0, signed: 1, failed: 2}
|
||||||
|
after_create do
|
||||||
|
cla.fresh_count
|
||||||
|
end
|
||||||
|
|
||||||
def self.build(params,user_id)
|
def self.build(params,user_id)
|
||||||
self.create!(user_id: user_id,
|
self.create!(user_id: user_id,
|
||||||
|
|
|
@ -3,3 +3,4 @@ json.content cla.content
|
||||||
json.key cla.key
|
json.key cla.key
|
||||||
json.name cla.name
|
json.name cla.name
|
||||||
json.pr_need cla.pr_need
|
json.pr_need cla.pr_need
|
||||||
|
json.count cla.count
|
|
@ -1,5 +1,6 @@
|
||||||
json.partial! "detail", cla: @cla, organization: @organization
|
json.partial! "detail", cla: @cla, organization: @organization
|
||||||
json.is_admin @is_admin
|
json.is_admin @is_admin
|
||||||
|
json.is_sign @is_sign
|
||||||
json.is_member @is_member
|
json.is_member @is_member
|
||||||
json.organization do
|
json.organization do
|
||||||
json.partial! "organizations/organizations/simple", organization: @organization
|
json.partial! "organizations/organizations/simple", organization: @organization
|
||||||
|
|
Loading…
Reference in New Issue