diff --git a/app/assets/javascripts/admins/faqs.js b/app/assets/javascripts/admins/faqs.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/admins/faqs.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/helps/faqs.js b/app/assets/javascripts/helps/faqs.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/helps/faqs.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/admins/faqs.scss b/app/assets/stylesheets/admins/faqs.scss new file mode 100644 index 000000000..8d1a08d30 --- /dev/null +++ b/app/assets/stylesheets/admins/faqs.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the admins/faqs controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/helps/faqs.scss b/app/assets/stylesheets/helps/faqs.scss new file mode 100644 index 000000000..4d3d2bc49 --- /dev/null +++ b/app/assets/stylesheets/helps/faqs.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the helps/faqs controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/admins/faqs_controller.rb b/app/controllers/admins/faqs_controller.rb new file mode 100644 index 000000000..fc00f847c --- /dev/null +++ b/app/controllers/admins/faqs_controller.rb @@ -0,0 +1,58 @@ +class Admins::FaqsController < Admins::BaseController + before_action :find_faq, only: [:edit,:update, :destroy] + + def index + sort_by = params[:sort_by] ||= 'updated_at' + sort_direction = params[:sort_direction] ||= 'desc' + + keyword = params[:keyword].to_s.strip + collection = Faq.search_question(keyword).order("#{sort_by} #{sort_direction}") + @faqs = paginate collection + end + + def new + @faq = Faq.new + end + + def edit + end + + def update + begin + @faq.update!(faq_params) + flash[:success] = '修改成功' + rescue Exception + flash[:danger] = @faq.errors.full_messages.to_sentence + end + + redirect_to admins_faqs_path + end + + def destroy + @faq.destroy + + redirect_to admins_faqs_path + flash[:success] = "删除成功" + end + + def create + @faq = Faq.new(faq_params) + begin + @faq.save! + flash[:success] = '创建成功' + rescue Exception + flash[:danger] = @faq.errors.full_messages.to_sentence + end + redirect_to admins_faqs_path + end + + private + def find_faq + @faq = Faq.find params[:id] + end + + def faq_params + params.require(:faq).permit(:question, :url) + end + +end diff --git a/app/controllers/concerns/acceleratorable.rb b/app/controllers/concerns/acceleratorable.rb index 9a11e46c2..5243ac538 100644 --- a/app/controllers/concerns/acceleratorable.rb +++ b/app/controllers/concerns/acceleratorable.rb @@ -2,7 +2,7 @@ module Acceleratorable extend ActiveSupport::Concern def enable_accelerator?(clone_addr) - clone_addr.include?(github_domain) || clone_addr.include?(gitlab_domain) + is_foreign_url?(clone_addr) && config_accelerator? end def accelerator_url(repo_name) @@ -25,4 +25,12 @@ module Acceleratorable Gitea.gitea_config[:accelerator]["access_key_id"] end + def config_accelerator? + Gitea.gitea_config[:accelerator].present? + end + + def is_foreign_url?(clone_addr) + clone_addr.include?(github_domain) || clone_addr.include?(gitlab_domain) + end + end \ No newline at end of file diff --git a/app/controllers/helps/faqs_controller.rb b/app/controllers/helps/faqs_controller.rb new file mode 100644 index 000000000..a18f49270 --- /dev/null +++ b/app/controllers/helps/faqs_controller.rb @@ -0,0 +1,8 @@ +class Helps::FaqsController < ApplicationController + skip_before_action :check_sign, :user_setup + + def index + faqs = Faq.select_without_id.order(updated_at: :desc) + render json: faqs.as_json(:except => [:id]) + end +end diff --git a/app/controllers/organizations/organizations_controller.rb b/app/controllers/organizations/organizations_controller.rb index c8f4f4aa0..29cb15a6a 100644 --- a/app/controllers/organizations/organizations_controller.rb +++ b/app/controllers/organizations/organizations_controller.rb @@ -1,5 +1,5 @@ class Organizations::OrganizationsController < Organizations::BaseController - before_action :require_login, except: [:index, :show] + before_action :require_login, except: [:index, :show, :recommend] before_action :convert_image!, only: [:create, :update] before_action :load_organization, only: [:show, :update, :destroy] before_action :check_user_can_edit_org, only: [:update, :destroy] @@ -62,6 +62,13 @@ class Organizations::OrganizationsController < Organizations::BaseController tip_exception(e.message) end + def recommend + recommend = %W(xuos Huawei_Technology openatom_foundation pkecosystem TensorLayer) + + @organizations = Organization.with_visibility(%w(common)) + .where(login: recommend).select(:id, :login, :firstname, :lastname, :nickname) + end + private def convert_image! return unless params[:image].present? diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 500c584cd..7612003f2 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -106,19 +106,29 @@ class ProjectsController < ApplicationController def update ActiveRecord::Base.transaction do - Projects::UpdateForm.new(project_params).validate! - private = params[:private] || false + # TODO: + # 临时特殊处理修改website、lesson_url操作方法 + if project_params.has_key?("website") + @project.update(project_params) + else + validate_params = project_params.slice(:name, :description, + :project_category_id, :project_language_id, :private) + + Projects::UpdateForm.new(validate_params).validate! + + private = params[:private] || false - new_project_params = project_params.except(:private).merge(is_public: !private) - @project.update_attributes!(new_project_params) - gitea_params = { - private: private, - default_branch: @project.default_branch, - website: @project.website - } - if [true, false].include? private - Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) - @project.repository.update_column(:hidden, private) + new_project_params = project_params.except(:private).merge(is_public: !private) + @project.update_attributes!(new_project_params) + gitea_params = { + private: private, + default_branch: @project.default_branch, + website: @project.website + } + if [true, false].include? private + Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) + @project.repository.update_column(:hidden, private) + end end end rescue Exception => e @@ -167,7 +177,7 @@ class ProjectsController < ApplicationController end def recommend - @projects = Project.recommend.includes(:repository, :project_category, :owner).order(id: :desc).limit(5) + @projects = Project.recommend.includes(:repository, :project_category, :owner).order(id: :desc) end def about diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 0dbcdc942..139ea9526 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -136,7 +136,8 @@ class PullRequestsController < ApplicationController def show @issue_user = @issue.user @issue_assign_to = @issue.get_assign_user - + @gitea_pull = Gitea::PullRequest::GetService.call(@owner.login, + @repository.identifier, @pull_request.gpid, current_user&.gitea_token) end def pr_merge diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 10b352ae6..6594d06e9 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -53,6 +53,18 @@ class RepositoriesController < ApplicationController @entries = Gitea::Repository::Entries::ListService.new(@owner, @project.identifier, ref: @ref).call @entries = @entries.present? ? @entries.sort_by{ |hash| hash['type'] } : [] @path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/" + + # TODO + # 临时处理readme文件问题 + admin = current_user.blank? ? User.where(admin: true).last : current_user + + result = Gitea::Repository::Readme::GetService.call(@owner.login, @project.identifier, @ref, admin&.gitea_token) + @readme = + if result[:status] == :success + result[:body] + else + {} + end end end diff --git a/app/helpers/admins/faqs_helper.rb b/app/helpers/admins/faqs_helper.rb new file mode 100644 index 000000000..0316d44fd --- /dev/null +++ b/app/helpers/admins/faqs_helper.rb @@ -0,0 +1,2 @@ +module Admins::FaqsHelper +end diff --git a/app/helpers/helps/faqs_helper.rb b/app/helpers/helps/faqs_helper.rb new file mode 100644 index 000000000..68b8279f7 --- /dev/null +++ b/app/helpers/helps/faqs_helper.rb @@ -0,0 +1,2 @@ +module Helps::FaqsHelper +end diff --git a/app/models/ci/user.rb b/app/models/ci/user.rb index fc82596c4..e4a4d0623 100644 --- a/app/models/ci/user.rb +++ b/app/models/ci/user.rb @@ -47,6 +47,7 @@ # watchers_count :integer default("0") # devops_step :integer default("0") # gitea_token :string(255) +# platform :string(255) # # Indexes # diff --git a/app/models/faq.rb b/app/models/faq.rb new file mode 100644 index 000000000..5965de036 --- /dev/null +++ b/app/models/faq.rb @@ -0,0 +1,20 @@ +# == Schema Information +# +# Table name: faqs +# +# id :integer not null, primary key +# question :string(255) +# url :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# + +class Faq < ApplicationRecord + + validates :question, presence: true,length: { maximum: 100, too_long: "最多%{count}个字符" } + validates :url, format: { with: CustomRegexp::URL, multiline: true, message: "格式不正确" } + + scope :select_without_id, -> { select(:question, :url) } + scope :search_question, ->(keyword) { where("question LIKE ?", "%#{keyword}%") unless keyword.blank?} + +end diff --git a/app/models/organization.rb b/app/models/organization.rb index f12c8b0a6..444938e72 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -47,6 +47,7 @@ # watchers_count :integer default("0") # devops_step :integer default("0") # gitea_token :string(255) +# platform :string(255) # # Indexes # diff --git a/app/models/user.rb b/app/models/user.rb index 256cc7b41..03989cbab 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -47,6 +47,7 @@ # watchers_count :integer default("0") # devops_step :integer default("0") # gitea_token :string(255) +# platform :string(255) # # Indexes # @@ -167,7 +168,8 @@ class User < Owner # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } scope :like, lambda { |keywords| - where("LOWER(concat(lastname, firstname, login, mail)) LIKE ?", "%#{keywords.split(" ").join('|')}%") unless keywords.blank? + sql = "CONCAT(lastname, firstname) LIKE :keyword OR login LIKE :keyword OR mail LIKE :keyword OR nickname LIKE :keyword" + where(sql, :search => "%#{keywords.split(" ").join('|')}%") unless keywords.blank? } scope :simple_select, -> {select(:id, :login, :lastname,:firstname, :nickname, :gitea_uid, :type)} diff --git a/app/services/gitea/pull_request/get_service.rb b/app/services/gitea/pull_request/get_service.rb index 6a7ec30f4..601c669e1 100644 --- a/app/services/gitea/pull_request/get_service.rb +++ b/app/services/gitea/pull_request/get_service.rb @@ -1,15 +1,14 @@ # Get a pull request class Gitea::PullRequest::GetService < Gitea::ClientService - attr_reader :user, :repo, :pull_request_id + attr_reader :owner, :repo, :number, :token - # user: 用户 - # repo: 仓库名称/标识 - # pull_request_id: pull request主键id - def initialize(user, repo, pull_request_id) - super({token: user.gitea_token}) - @user = user + #eq: + # Gitea::PullRequest::GetService.call(user.login, repository.identifier, pull.gpid, user.gitea_token) + def initialize(owner, repo, number, token=nil) + @owner = owner @repo = repo - @pull_request_id = pull_request_id + @number = number + @token = token end def call @@ -19,11 +18,11 @@ class Gitea::PullRequest::GetService < Gitea::ClientService private def params - Hash.new.merge(token: user.gitea_token) + Hash.new.merge(token: token) end def url - "/repos/#{user.login}/#{repo}/pulls/#{pull_request_id}".freeze + "/repos/#{owner}/#{repo}/pulls/#{number}".freeze end def render_result(response) @@ -31,7 +30,7 @@ class Gitea::PullRequest::GetService < Gitea::ClientService when 200 JSON.parse(response.body) else - nil + {} end end end diff --git a/app/services/issues/list_query_service.rb b/app/services/issues/list_query_service.rb index dbb502ab6..1718db97d 100644 --- a/app/services/issues/list_query_service.rb +++ b/app/services/issues/list_query_service.rb @@ -28,7 +28,7 @@ class Issues::ListQueryService < ApplicationService end if search_name.present? - issues = issues.where("subject like ?", "%#{search_name}%") + issues = issues.where("subject LIKE ? OR description LIKE ? ", "%#{search_name}%", "%#{search_name}%") end if start_time&.present? || end_time&.present? diff --git a/app/services/repositories/migrate_service.rb b/app/services/repositories/migrate_service.rb index b737b2ef5..374115bf0 100644 --- a/app/services/repositories/migrate_service.rb +++ b/app/services/repositories/migrate_service.rb @@ -21,9 +21,7 @@ class Repositories::MigrateService < ApplicationService private def repository_params - params.merge(project_id: project.id, - identifier: params[:identifier], - source_clone_url: params[:source_clone_url]) + params.merge(project_id: project.id) end def gitea_repository_params diff --git a/app/views/admins/faqs/_form_modal.html.erb b/app/views/admins/faqs/_form_modal.html.erb new file mode 100644 index 000000000..45ceb901c --- /dev/null +++ b/app/views/admins/faqs/_form_modal.html.erb @@ -0,0 +1,24 @@ +
\ No newline at end of file diff --git a/app/views/admins/faqs/_list.html.erb b/app/views/admins/faqs/_list.html.erb new file mode 100644 index 000000000..81e658edd --- /dev/null +++ b/app/views/admins/faqs/_list.html.erb @@ -0,0 +1,33 @@ +序号 | +标题 | +url | +<%= sort_tag('创建于', name: 'created_at', path: admins_faqs_path) %> | +<%= sort_tag('更新于', name: 'updated_at', path: admins_faqs_path) %> | +操作 | +
---|---|---|---|---|---|
<%= list_index_no((params[:page] || 1).to_i, index) %> | +<%= faq.question%> | +<%= link_to faq.url, target: '_blank' %> | +<%= display_text(faq.created_at&.strftime('%Y-%m-%d %H:%M')) %> | +<%= display_text(faq.updated_at&.strftime('%Y-%m-%d %H:%M')) %> | ++ <%= link_to "编辑", edit_admins_faq_path(faq), remote: true, class: "action" %> + <%= link_to "删除", admins_faqs_path(faq.id), method: :delete, data:{confirm: "确认删除的吗?"}, class: "delete-project-action" %> + | +