[FIX]merge

This commit is contained in:
viletyy 2020-12-25 16:33:16 +08:00
commit d42053ce0c
18 changed files with 169 additions and 81 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

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

@ -11,4 +11,6 @@
class License < ApplicationRecord
include Projectable
has_many :attachments, as: :container, dependent: :destroy
end

View File

@ -106,12 +106,16 @@ class Project < ApplicationRecord
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
has_one :project_detail, dependent: :destroy
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 :recommend, -> { visible.project_statics_select.where(recommend: true) }
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

@ -161,6 +161,7 @@ class User < ApplicationRecord
# has_many :libraries, dependent: :destroy
has_many :project_trends, dependent: :destroy
has_many :oauths , 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.by_name_or_identifier(params[:search])
q = Project.secret_and_visible.by_name_or_identifier(params[:search])
scope = q
.with_project_type(params[:project_type])

View File

@ -53,6 +53,11 @@ class Projects::CreateService < ApplicationService
# end
def repo_is_public
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

@ -7,6 +7,7 @@ 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)
@ -35,12 +36,25 @@ json.category do
json.id project.project_category.id
json.name project.project_category.name
end
end
json.language do
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

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

@ -17,6 +17,12 @@ json.mirror_url @project&.repository.mirror_url
json.mirror @project&.repository.mirror_url.present?
json.type @project.numerical_for_project_type
json.open_devops @project.open_devops?
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

@ -59,6 +59,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