You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/controllers/projects_controller.rb

73 lines
2.3 KiB

6 years ago
class ProjectsController < ApplicationController
5 years ago
include ApplicationHelper
5 years ago
include OperateProjectAbilityAble
5 years ago
before_action :require_login, except: %i[index branches group_type_list]
5 years ago
before_action :find_project_with_identifier, only: %i[branches]
before_action :find_project_with_id, only: %i[update show]
before_action :authorizate_user_can_edit_project!, only: %i[update]
def index
5 years ago
scope = Projects::ListQuery.call(params)
@total_count = scope.size
5 years ago
@projects = paginate(scope)
end
def create
ActiveRecord::Base.transaction do
Projects::CreateForm.new(project_params).validate!
@project = Projects::CreateService.new(current_user, project_params).call
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
def migrate
ActiveRecord::Base.transaction do
Projects::MigrateForm.new(mirror_params).validate!
@project = Projects::MigrateService.new(current_user, mirror_params).call
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
def branches
5 years ago
@branches = Gitea::Repository::BranchesService.new(@project.owner, @project.identifier).call
end
5 years ago
def group_type_list
@project_group_list = Project.visible.group(:project_type).select('project_type, count(*) AS projects_count')
end
5 years ago
def update
ActiveRecord::Base.transaction do
# Projects::CreateForm.new(project_params).validate!
private = params[:private]
if [true, false].include? private
new_project_params = project_params.merge(is_public: !private)
Gitea::Repository::UpdateService.new(@project.owner, @project.repository.identifier, {private: private}).call
@project.repository.update_column(:hidden, private)
end
@project.update_attributes!(new_project_params)
5 years ago
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
def show
end
private
def project_params
params.permit(:user_id, :name, :description, :repository_name,
:project_category_id, :project_language_id, :license_id, :ignore_id)
end
def mirror_params
params.permit(:user_id, :name, :description, :repository_name,
:project_category_id, :project_language_id, :clone_addr, :private)
end
end