Browse Source

Merge remote-tracking branch 'origin/standalone_develop' into standalone_develop

pull/343/head
xxq250 3 years ago
parent
commit
fafae74dec
8 changed files with 28 additions and 8 deletions
  1. +8
    -4
      app/controllers/organizations/clas_controller.rb
  2. +1
    -0
      app/controllers/users/clas_controller.rb
  3. +2
    -2
      app/forms/organizations/create_cla_form.rb
  4. +7
    -2
      app/models/cla.rb
  5. +5
    -0
      app/models/organization.rb
  6. +3
    -0
      app/models/user_cla.rb
  7. +1
    -0
      app/views/organizations/clas/_detail.json.jbuilder
  8. +1
    -0
      app/views/organizations/clas/show.json.jbuilder

+ 8
- 4
app/controllers/organizations/clas_controller.rb View File

@@ -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
@@ -15,7 +19,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
@@ -47,7 +51,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
@@ -57,7 +61,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

+ 1
- 0
app/controllers/users/clas_controller.rb View File

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


+ 2
- 2
app/forms/organizations/create_cla_form.rb View File

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

+ 7
- 2
app/models/cla.rb View File

@@ -27,12 +27,17 @@ 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],
pr_need: params[:pr_need]
)
end


def fresh_count
update(count:self.users.count)
end
end

+ 5
- 0
app/models/organization.rb View File

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


+ 3
- 0
app/models/user_cla.rb View File

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


+ 1
- 0
app/views/organizations/clas/_detail.json.jbuilder View File

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

+ 1
- 0
app/views/organizations/clas/show.json.jbuilder View File

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

Loading…
Cancel
Save