forked from Gitlink/forgeplus
修改is_mirror
This commit is contained in:
parent
5c4daaeed2
commit
569c5309ce
|
@ -382,7 +382,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def current_user
|
||||
if Rails.env.development?
|
||||
User.current = User.find 36480
|
||||
User.current = User.find 1
|
||||
else
|
||||
User.current
|
||||
end
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
class ComposeProjectsController < ApplicationController
|
||||
#未做完
|
||||
before_action :require_login
|
||||
before_action :set_compose
|
||||
|
||||
def create
|
||||
project_ids = params[:project_ids]
|
||||
ComposeProject.transaction do
|
||||
project_ids.each do |p|
|
||||
project = Project.select(:id, :user_id).find(p)
|
||||
unless project.blank? || ComposeProject.exists?(user_id: project.user_id, project_id: p, compose_id: @compose.id)
|
||||
ComposeProject.create!(user_id: project.user_id, project_id: p, compose_id: @compose.id, position: p)
|
||||
end
|
||||
end
|
||||
end
|
||||
normal_status(0, "添加成功")
|
||||
end
|
||||
|
||||
def destroy
|
||||
project_ids = params[:project_ids]
|
||||
if ComposeProject.where(project_id: project_ids, compose_id: @compose.id).delete_all
|
||||
normal_status(0, "项目删除成功")
|
||||
else
|
||||
normal_status(-1, "项目删除失败")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def set_compose
|
||||
@compose = Compose.find(params[:compose_id])
|
||||
unless @compose.present?
|
||||
normal_status(-1, "组织不存在")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,99 @@
|
|||
class ComposesController < ApplicationController
|
||||
before_action :require_login, except: [:index]
|
||||
before_action :find_compose, except: [:index, :new,:create]
|
||||
|
||||
def index
|
||||
@order_type = params[:order] || "created_at"
|
||||
@search_name = params[:search]
|
||||
composes = Compose.compose_includes
|
||||
if @search_name.present?
|
||||
composes = composes.where("title like ?", "%#{@search_name}%")
|
||||
end
|
||||
composes = composes.order("#{@order_type} desc")
|
||||
@page = params[:page] || 1
|
||||
@limit = params[:limit] || 15
|
||||
@composes_size = composes.size
|
||||
@composes = composes.page(@page).per(@limit)
|
||||
end
|
||||
|
||||
def new
|
||||
|
||||
end
|
||||
|
||||
def create
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
@compose = Compose.new(compose_params.merge(user_id: current_user.id))
|
||||
if @compose.save
|
||||
ComposeUser.create!(user_id: current_user.id, compose_id: @compose.id, is_manager: 1)
|
||||
normal_status(0,"组织创建成功")
|
||||
else
|
||||
error_messages = @compose.errors.messages[:title][0]
|
||||
normal_status(-1,"组织创建失败:#{error_messages}")
|
||||
end
|
||||
rescue Exception => e
|
||||
tip_exception("#{e}")
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
if @compose.update_attributes(compose_params)
|
||||
normal_status(0,"组织更新成功")
|
||||
else
|
||||
error_messages = @compose.errors.messages[:title][0]
|
||||
normal_status(-1,"组织更新失败:#{error_messages}")
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @compose.destroy
|
||||
normal_status(0,"组织删除成功")
|
||||
else
|
||||
normal_status(-1,"组织删除失败,请稍后重试")
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
compose_projects_ids = @compose&.compose_projects&.pluck(:project_id)
|
||||
search = params[:search]
|
||||
if compose_projects_ids.size > 0
|
||||
compose_projects = Project.where(id: compose_projects_ids)
|
||||
|
||||
if search.present?
|
||||
compose_projects = compose_projects.where("name like ? ", "%#{search.to_s.strip}%")
|
||||
end
|
||||
else
|
||||
compose_projects = []
|
||||
end
|
||||
|
||||
@compose_projects_size = compose_projects.size
|
||||
|
||||
if @compose_projects_size > 0
|
||||
@page = params[:page] || 1
|
||||
@limit = params[:limit] || 15
|
||||
@compose_projects = compose_projects.page(@page).per(@limit)
|
||||
else
|
||||
@compose_projects = compose_projects
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def compose_params
|
||||
params.require(:compose).permit(:user_id, :title, :description, :show_mode, :compose_mode, :compose_users_count, :compose_projects_count)
|
||||
end
|
||||
|
||||
def find_compose
|
||||
@compose = Compose.find(params[:compose_id])
|
||||
unless @compose.present?
|
||||
normal_status(-1, "组织不存在")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -86,7 +86,13 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
# 个人主页信息
|
||||
def homepage_info;end
|
||||
def homepage_info
|
||||
#待办事项,现在未做
|
||||
@undo_events = 10
|
||||
#用户的组织数量
|
||||
# @user_composes_count = @user.composes.size
|
||||
@user_composes_count = 10
|
||||
end
|
||||
|
||||
def brief_introduction
|
||||
content = params[:content].to_s.strip
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
class Compose < ApplicationRecord
|
||||
#组织
|
||||
belongs_to :user
|
||||
has_many :compose_projects
|
||||
has_many :compose_users
|
||||
|
||||
validates :title, presence: {message: "组织名称不能为空"}, uniqueness: {message: "组织名称已存在"}
|
||||
|
||||
scope :compose_includes, ->{includes(:compose_projects, :compose_users, :user)}
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
class ComposeProject < ApplicationRecord
|
||||
#组织的项目记录表
|
||||
belongs_to :compose
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
class ComposeUser < ApplicationRecord
|
||||
belongs_to :compose
|
||||
belongs_to :user
|
||||
end
|
|
@ -45,7 +45,8 @@ class User < ApplicationRecord
|
|||
enumerize :platform, in: [:forge, :educoder, :trustie, :military], default: :forge, scope: :shallow
|
||||
|
||||
belongs_to :laboratory, optional: true
|
||||
|
||||
has_many :composes, dependent: :destroy
|
||||
has_many :compose_users, dependent: :destroy
|
||||
has_one :user_extension, dependent: :destroy
|
||||
has_many :open_users, dependent: :destroy
|
||||
has_one :wechat_open_user, class_name: 'OpenUsers::Wechat'
|
||||
|
|
|
@ -14,6 +14,11 @@ class Projects::ListMyQuery < ApplicationQuery
|
|||
projects = Project.joins(:members).where(members: { user_id: user.id })
|
||||
elsif params[:category].to_s == "manage"
|
||||
projects = Project.where(user_id: user.id)
|
||||
elsif params[:category].to_s == "watched" #我关注的
|
||||
projects = Project.joins(:watchers).where("watchable_type = ? and user_id = ?", "Project", user.id)
|
||||
elsif params[:category].to_s == "forked" #我fork的
|
||||
fork_ids = user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id)
|
||||
projects = Project.where(id: fork_ids)
|
||||
else
|
||||
projects = Project.where.not(user_id: user.id).joins(:members).where(members: { user_id: user.id })
|
||||
end
|
||||
|
|
|
@ -17,6 +17,7 @@ json.branches_count @branches_count
|
|||
json.commits_count @commits_count
|
||||
json.permission render_edit_project_permission(current_user, @project) if current_user
|
||||
json.mirror_url @project&.repository.mirror_url
|
||||
json.mirror @project&.repository.mirror_url.present?
|
||||
json.watched current_user&.watched?(@project)
|
||||
json.praised current_user&.liked?(@project)
|
||||
json.status @project.status
|
||||
|
@ -35,6 +36,6 @@ json.clone_url @result['clone_url']
|
|||
json.default_branch @result['default_branch']
|
||||
json.empty @result['empty']
|
||||
json.full_name @result['full_name']
|
||||
json.mirror @result['mirror']
|
||||
|
||||
json.private @result['private']
|
||||
json.partial! 'author', locals: { user: @project.owner }
|
||||
|
|
|
@ -8,7 +8,8 @@ json.brief_introduction @user.user_extension&.brief_introduction
|
|||
json.professional_certification @user.professional_certification
|
||||
json.followed User.current.watched?(@user)
|
||||
json.projects_count @user.projects_count
|
||||
|
||||
json.undo_events @undo_events
|
||||
json.user_composes_count @user_composes_count
|
||||
# json.id @user.id
|
||||
# json.name @user.full_name
|
||||
# json.avatar_url url_to_avatar(@user)
|
||||
|
|
|
@ -14,6 +14,9 @@ Rails.application.routes.draw do
|
|||
resources :edu_settings
|
||||
|
||||
scope '/api' do
|
||||
resources :composes do
|
||||
resources :compose_projects, only: [:create, :destroy]
|
||||
end
|
||||
resources :attachments do
|
||||
collection do
|
||||
delete :destroy_files
|
||||
|
|
Loading…
Reference in New Issue