[ADD]增加特殊许可的验证

This commit is contained in:
viletyy 2020-12-25 16:17:46 +08:00
parent c283c7ed58
commit 36bae71947
19 changed files with 118 additions and 38 deletions

View File

@ -0,0 +1,16 @@
class ApplySignaturesController < ApplicationController
def create
ActiveRecord::Base.transaction do
begin
@signature = current_user.apply_signatures.create!(project_id: params[:project_id])
@attachment = Attachment.find_by_id(params[:attachment_id])
@attachment.container = @signature
@attachment.save!
rescue Exception => e
tip_exception("#{e}")
raise ActiveRecord::Rollback
end
render_json
end
end
end

View File

@ -12,7 +12,7 @@ class ProjectCategoriesController < ApplicationController
# projects = Project.visible
# end
@project_children_categories = ProjectCategory.descendants
projects = Project.no_anomory_projects.visible
projects = Project.no_anomory_projects.secret_and_visible
categories = projects.joins(:project_category).where(project_categories: {ancestry: nil}).group("project_categories.name", "project_categories.id").size.keys.to_h
extra_category_id = categories.delete("其他")
categories = categories.merge({"其他": extra_category_id}) if extra_category_id.present? #其他的放在最后面

View File

@ -43,7 +43,7 @@ class ProjectsController < ApplicationController
# else
# projects = Project.visible
# end
projects = Project.no_anomory_projects.visible
projects = Project.no_anomory_projects.secret_and_visible
language_lists = projects.joins(:project_language).group("project_languages.name", "project_languages.id").size.keys.sort.to_h
@project_group_list = language_lists.delete_if { |k, v| k.blank? }
end

View File

@ -0,0 +1,6 @@
class ApplySignature < ApplicationRecord
belongs_to :user
belongs_to :project
scope :with_user_id, -> (user_id) {where(user_id: user_id)}
end

View File

@ -1,3 +1,5 @@
class License < ApplicationRecord
include Projectable
has_many :attachments, as: :container, dependent: :destroy
end

View File

@ -31,10 +31,14 @@ class Project < ApplicationRecord
has_many :versions, -> { order("versions.created_on DESC, versions.name DESC") }, dependent: :destroy
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
has_many :apply_signatures, dependent: :destroy
after_save :check_project_members
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
scope :secret_and_visible, -> {joins(:license).where("licenses.is_secret = TRUE OR projects.is_public = TRUE")}
delegate :is_secret, to: :license
def self.search_project(search)

View File

@ -92,6 +92,7 @@ class User < ApplicationRecord
# 教学案例
# has_many :libraries, dependent: :destroy
has_many :project_trends, dependent: :destroy
has_many :apply_signatures, dependent: :destroy
# Groups and active users
scope :active, lambda { where(status: STATUS_ACTIVE) }

View File

@ -10,7 +10,7 @@ class Projects::ListQuery < ApplicationQuery
end
def call
q = Project.visible.search_project(params[:search])
q = Project.secret_and_visible.search_project(params[:search])
scope = q.result(distinct: true)
.includes(:project_category, :project_language, :repository, owner: :user_extension)

View File

@ -52,6 +52,11 @@ class Projects::CreateService < ApplicationService
# end
def repo_is_public
params[:private].blank? ? true : !params[:private]
license = License.find_by_id(params[:license_id])
if license.is_secret
false
else
params[:private].blank? ? true : !params[:private]
end
end
end

View File

@ -0,0 +1,4 @@
json.id @signature.id
json.attachment do
json.name @attachment.filename
end

View File

@ -1 +1 @@
json.licenses @licenses, :id, :name
json.licenses @licenses, :id, :name, :is_secret

View File

@ -3,38 +3,44 @@ if user.blank?
nil
else
json.id project.id
json.repo_id project&.repository&.id
json.identifier project.identifier
json.name project.name
json.description Nokogiri::HTML(project.description).text
json.visits project.visits
json.praises_count project.praises_count.to_i
json.forked_count project.forked_count.to_i
json.is_public project.is_public
json.mirror_url project.repository&.mirror_url
json.type project&.numerical_for_project_type
json.last_update_time render_unix_time(project.updated_on)
json.time_ago time_from_now(project.updated_on)
json.forked_from_project_id project.forked_from_project_id
json.author do
json.name user.try(:show_real_name)
json.login user.login
json.image_url url_to_avatar(project.owner)
end
json.category do
if project.project_category.blank?
json.nil!
else
json.id project.project_category.id
json.name project.project_category.name
json.repo_id project&.repository&.id
json.identifier project.identifier
json.name project.name
json.description Nokogiri::HTML(project.description).text
json.visits project.visits
json.praises_count project.praises_count.to_i
json.forked_count project.forked_count.to_i
json.is_public project.is_public
json.is_secret project.is_secret
json.mirror_url project.repository&.mirror_url
json.type project&.numerical_for_project_type
json.last_update_time render_unix_time(project.updated_on)
json.time_ago time_from_now(project.updated_on)
json.forked_from_project_id project.forked_from_project_id
json.author do
json.name user.try(:show_real_name)
json.login user.login
json.image_url url_to_avatar(project.owner)
end
json.category do
if project.project_category.blank?
json.nil!
else
json.id project.project_category.id
json.name project.project_category.name
end
end
json.language do
if project.project_language.blank?
json.nil!
else
json.id project.project_language.id
json.name project.project_language.name
end
end
user_apply_signatures = project.apply_signatures.with_user_id(current_user.id)
json.user_apply_signatures user_apply_signatures do |signature|
json.id signature.id
json.status signature.status
end
end
json.language do
if project.project_language.blank?
json.nil!
else
json.id project.project_language.id
json.name project.project_language.name
end
end
end

View File

@ -1,6 +1,12 @@
json.name @project.name
json.identifier @project.identifier
json.is_public @project.is_public
json.is_secret @project.is_secret
json.description @project.description
json.repo_id @project.repository.id
json.repo_identifier @project.repository.identifier
user_apply_signatures = @project.apply_signatures.with_user_id(current_user.id)
json.user_apply_signatures user_apply_signatures do |signature|
json.id signature.id
json.status signature.status
end

View File

@ -5,3 +5,4 @@ json.project_description @project.description
json.project_category_id @project.project_category_id
json.project_language_id @project.project_language_id
json.private !@project.is_public
json.is_secret @project.is_secret

View File

@ -16,6 +16,12 @@ json.permission User.current&.admin? ? "Manager" : @project.get_premission(@use
json.mirror_url @project&.repository.mirror_url
json.mirror @project&.repository.mirror_url.present?
json.type @project.numerical_for_project_type
json.is_secret @project.is_secret
user_apply_signatures = @project.apply_signatures.with_user_id(current_user.id)
json.user_apply_signatures user_apply_signatures do |signature|
json.id signature.id
json.status signature.status
end
unless @project.common?
json.mirror_status @repo.mirror_status

View File

@ -35,6 +35,7 @@ Rails.application.routes.draw do
delete :destroy_files
end
end
resources :apply_signatures, only: [:create]
get 'home/index'
get 'home/search'
get 'main/first_stamp'

View File

@ -0,0 +1,11 @@
class CreateApplySignatures < ActiveRecord::Migration[5.2]
def change
create_table :apply_signatures do |t|
t.references :user
t.references :project
t.integer :status, default: 0
t.timestamps
end
end
end

View File

@ -0,0 +1,6 @@
class AddSomeColumnsAboutApplySignatures < ActiveRecord::Migration[5.2]
def change
add_column :licenses, :is_secret, :boolean, default: false
add_column :members, :is_apply_signature, :boolean, default: false
end
end

View File

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