Merge branch 'pre_trustie_server' into trustie_server

This commit is contained in:
yystopf 2021-12-13 18:35:53 +08:00
commit 9c5ff55b70
20 changed files with 677 additions and 423 deletions

View File

@ -0,0 +1,138 @@
#coding=utf-8
class ClaimsController < ApplicationController
# skip_before_action :verify_authenticity_token
protect_from_forgery with: :null_session
before_action :require_login, except: [:index]
before_action :set_issue
def index
@user_claimed = 0
@claims = @issue.claims.claim_includes.order("created_at desc")
@claims.each do |claim|
if claim.user_id == current_user.id
@user_claimed = 1
break
end
end
render file: 'app/views/claims/list.json.jbuilder'
end
def create
@claim = Claim.find_by_sql(["select id from claims where issue_id=? and user_id=?",params[:issue_id], current_user.id])
if @claim.present?
return normal_status(-1,"您已经声明过该易修")
end
ActiveRecord::Base.transaction do
@claim = Claim.new(parse_issue_params(params))
if @claim.save
@claims = @issue.claims.claim_includes.order("created_at desc")
@user_claimed = 1
journal_params = {
journalized_id: params[:issue_id],
journalized_type: "Issue",
user_id: current_user.id ,
notes: "新建声明: #{params[:claim_note]}",
}
journal = Journal.new(journal_params)
if journal.save
render file: 'app/views/claims/list.json.jbuilder'
else
normal_status(-1,"新建声明关联评论操作失败")
end
else
normal_status(-1,"新建声明操作失败")
end
end
end
def update
@claim = Claim.find_by_id(params[:claim_id])
if @claim.blank?
return normal_status(-1,"易修不存在")
end
if @claim.user_id != current_user.id
return normal_status(-1,"你不能更新别人的声明")
end
ActiveRecord::Base.transaction do
if @claim.update_attribute(:note,params[:claim_note])
@claims = @issue.claims.claim_includes.order("created_at desc")
@user_claimed = 1
journal_params = {
journalized_id: params[:issue_id],
journalized_type: "Issue",
user_id: current_user.id ,
notes: "更新声明: #{params[:claim_note]}",
}
journal = Journal.new(journal_params)
if journal.save
render file: 'app/views/claims/list.json.jbuilder'
else
normal_status(-1,"新建声明关联评论操作失败")
end
else
normal_status(-1,"声明更新操作失败")
end
end
end
def destroy
@claim = Claim.find_by_sql(["select id from claims where issue_id=? and user_id=?",params[:issue_id], current_user.id])
if @claim.blank?
normal_status(-1,"您未曾声明过该易修")
else
@claim = @claim[0]
# 判断current user是否是claimer
ActiveRecord::Base.transaction do
if @claim.destroy
@claims = @issue.claims.claim_includes.order("created_at desc")
@user_claimed = 0
journal_params = {
journalized_id: params[:issue_id],
journalized_type: "Issue",
user_id: current_user.id ,
notes: "取消声明",
}
journal = Journal.new(journal_params)
if journal.save
render file: 'app/views/claims/list.json.jbuilder'
else
normal_status(-1,"新建声明关联评论操作失败")
end
else
normal_status(-1,"取消声明操作失败")
end
end
end
end
private
def parse_issue_params(params)
{
issue_id: params[:issue_id],
user_id: current_user.id,
note: params[:claim_note],
}
end
def set_issue
@issue = Issue.find_by_id(params[:issue_id])
unless @issue.present?
normal_status(-1, "易修不存在")
end
end
end

View File

@ -16,13 +16,13 @@ class ProjectsController < ApplicationController
menu.append(menu_hash_by_name("home")) menu.append(menu_hash_by_name("home"))
menu.append(menu_hash_by_name("code")) if @project.has_menu_permission("code") menu.append(menu_hash_by_name("code")) if @project.has_menu_permission("code")
menu.append(menu_hash_by_name("issues")) if @project.has_menu_permission("issues") menu.append(menu_hash_by_name("issues")) if @project.has_menu_permission("issues")
menu.append(menu_hash_by_name("pulls")) if @project.has_menu_permission("pulls") menu.append(menu_hash_by_name("pulls")) if @project.has_menu_permission("pulls") && @project.forge?
menu.append(menu_hash_by_name("wiki")) if @project.has_menu_permission("wiki") menu.append(menu_hash_by_name("devops")) if @project.has_menu_permission("devops") && @project.forge?
menu.append(menu_hash_by_name("devops")) if @project.has_menu_permission("devops")
menu.append(menu_hash_by_name("versions")) if @project.has_menu_permission("versions") menu.append(menu_hash_by_name("versions")) if @project.has_menu_permission("versions")
menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources") menu.append(menu_hash_by_name("wiki")) if @project.has_menu_permission("wiki") && @project.forge?
menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources") && @project.forge?
menu.append(menu_hash_by_name("activity")) menu.append(menu_hash_by_name("activity"))
menu.append(menu_hash_by_name("settings")) if current_user.admin? || @project.manager?(current_user) menu.append(menu_hash_by_name("settings")) if (current_user.admin? || @project.manager?(current_user)) && @project.forge?
render json: menu render json: menu
end end

View File

@ -71,16 +71,32 @@ class RepositoriesController < ApplicationController
logger.info "######### sub_entries: #{@sub_entries}" logger.info "######### sub_entries: #{@sub_entries}"
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1 return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
tmp_entries = [{ tmp_entries = {
"content" => @sub_entries['data']['content'], "content" => @sub_entries['data']['content'],
"type" => "blob" "type" => "blob"
}] }
@sub_entries = { @sub_entries = {
"trees"=>tmp_entries, "trees"=>tmp_entries,
"commits" => [{}] "commits" => [{}]
} }
else else
begin
@sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri}) @sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri})
if @sub_entries.blank? || @sub_entries['status'].to_i === -1
@sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri)
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
tmp_entries = {
"content" => @sub_entries['data']['content'],
"type" => "blob"
}
@sub_entries = {
"trees"=>tmp_entries,
"commits" => [{}]
}
end
rescue
return render_error('该文件暂未开放,敬请期待.')
end
end end
else else
@path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/" @path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
@ -96,7 +112,7 @@ class RepositoriesController < ApplicationController
def commits def commits
if @project.educoder? if @project.educoder?
@hash_commit = nil @commits = Educoder::Repository::Commits::ListService.call(@project&.project_educoder&.repo_name)
else else
if params[:filepath].present? if params[:filepath].present?
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
@ -110,15 +126,14 @@ class RepositoriesController < ApplicationController
end end
def commits_slice def commits_slice
@hash_commit = Gitea::Repository::Commits::ListSliceService.call(@owner&.login, @project.identifier, @hash_commit = Gitea::Repository::Commits::ListSliceService.call(@owner.login, @project.identifier,
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token) sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token)
end end
def commit def commit
@sha = params[:sha] @sha = params[:sha]
if @project.educoder? if @project.educoder?
@commit = {} return render_error('暂未开放,敬请期待.')
@commit_diff ={}
else else
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token) @commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token)
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true}) @commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true})
@ -132,7 +147,7 @@ class RepositoriesController < ApplicationController
end end
def contributors def contributors
if params[:filepath].present? if params[:filepath].present? || @project.educoder?
@contributors = [] @contributors = []
else else
@contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier) @contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier)
@ -213,8 +228,12 @@ class RepositoriesController < ApplicationController
end end
def languages def languages
if @project.educoder?
render json: {}
else
render json: languages_precentagable render json: languages_precentagable
end end
end
def archive def archive
domain = Gitea.gitea_config[:domain] domain = Gitea.gitea_config[:domain]
@ -357,7 +376,7 @@ class RepositoriesController < ApplicationController
local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id)) local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id))
if local_requests.save if local_requests.save
gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @owner.login, @project.try(:identifier), requests_params).call gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @owner.login, @project.try(:identifier), requests_params).call
if gitea_request[:status] == :success && local_requests.update_attributes(gitea_number: gitea_request["body"]["number"], gpid: gitea_request["body"]["number"]) if gitea_request[:status] == :success && local_requests.update_attributes(gpid: gitea_request["body"]["number"])
local_requests.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create") local_requests.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
end end
end end

View File

@ -26,9 +26,13 @@ module TagChosenHelper
end end
def render_branches(project) def render_branches(project)
if project.educoder?
return ['master']
else
branches = Gitea::Repository::Branches::ListService.call(project&.owner, project.identifier) branches = Gitea::Repository::Branches::ListService.call(project&.owner, project.identifier)
branches.collect{|i| i["name"] if i.is_a?(Hash)} branches.collect{|i| i["name"] if i.is_a?(Hash)}
end end
end
def render_cache_trackers def render_cache_trackers
cache_key = "all_trackers/#{Tracker.maximum('id')}" cache_key = "all_trackers/#{Tracker.maximum('id')}"

21
app/models/claim.rb Normal file
View File

@ -0,0 +1,21 @@
# == Schema Information
#
# Table name: claims
#
# id :integer not null, primary key
# issue_id :integer
# user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# note :text(65535)
#
# Indexes
#
# index_claims_on_issue_id (issue_id)
# index_claims_on_user_id (user_id)
#
class Claim < ApplicationRecord
belongs_to :user, foreign_key: :user_id
scope :claim_includes, ->{includes(:user)}
end

View File

@ -64,6 +64,7 @@ class Issue < ApplicationRecord
# has_many :memos # has_many :memos
has_many :journals, :as => :journalized, :dependent => :destroy has_many :journals, :as => :journalized, :dependent => :destroy
has_many :journal_details, through: :journals has_many :journal_details, through: :journals
has_many :claims, :dependent => :destroy
has_many :issue_tags_relates, dependent: :destroy has_many :issue_tags_relates, dependent: :destroy
has_many :issue_tags, through: :issue_tags_relates has_many :issue_tags, through: :issue_tags_relates
has_many :issue_times, dependent: :destroy has_many :issue_times, dependent: :destroy

View File

@ -10,20 +10,12 @@ class Repositories::DetailService < ApplicationService
def call def call
return { return {
repo: repo_suitable, repo: repo_suitable,
contributor: contributor_suitable,
language: language_suitable,
branch_tag_total_count: branch_tag_total_count branch_tag_total_count: branch_tag_total_count
} }
rescue rescue
return { return {
repo: {}, repo: {},
release: [], branch_tag_total_count: {}
branch: [],
branch_type: [],
tag: [],
contributor: [],
language: {},
readme: {}
} }
end end
@ -35,14 +27,4 @@ class Repositories::DetailService < ApplicationService
def repo_suitable def repo_suitable
Gitea::Repository::GetService.call(@owner, @repo.identifier) Gitea::Repository::GetService.call(@owner, @repo.identifier)
end end
def contributor_suitable
contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repo.identifier)
contributors.is_a?(Hash) && contributors.key?(:status) ? [] : contributors
end
def language_suitable
result = Gitea::Repository::Languages::ListService.call(@owner.login, @repo.identifier, @user&.gitea_token)
result[:status] === :success ? hash_transform_precentagable(result[:body]) : nil
end
end end

View File

@ -0,0 +1,7 @@
json.user_name claimer.user.try(:show_real_name)
json.user_login claimer.user.try(:login)
json.user_picture url_to_avatar(claimer.user)
json.created_at time_from_now(claimer.created_at)
json.note_body claimer.note
json.claim_id claimer.id
json.visible false

View File

@ -0,0 +1,7 @@
json.partial! "commons/success"
json.currentUserclaimed @user_claimed
json.claimers do
json.array! @claims do |claimer|
json.partial! "claims/claim_item", claimer: claimer
end
end

View File

@ -3,8 +3,17 @@ owner_common = $redis_cache.hgetall("v2-owner-common:#{project_common["owner_id"
json.id item[0] json.id item[0]
json.score item[1] json.score item[1]
json.name project_common["name"] json.name project_common["name"]
if project_common['identifier'].include?("/")
json.identifier project_common["identifier"].split('/')[1]
json.owner do
json.id nil
json.type 'User'
json.name project_common["identifier"].split('/')[0]
json.login project_common["identifier"].split('/')[0]
json.avatar_url User::Avatar.get_letter_avatar_url(project_common["identifier"].split('/')[0])
end
else
json.identifier project_common["identifier"] json.identifier project_common["identifier"]
json.description project_common["description"]
json.owner do json.owner do
json.id project_common["owner_id"] json.id project_common["owner_id"]
json.type owner_common["type"] json.type owner_common["type"]
@ -12,6 +21,8 @@ json.owner do
json.login owner_common["login"] json.login owner_common["login"]
json.avatar_url owner_common["avatar_url"] json.avatar_url owner_common["avatar_url"]
end end
end
json.description project_common["description"]
json.visits project_common["visits"] json.visits project_common["visits"]
json.forks project_common["forks"] json.forks project_common["forks"]
json.watchers project_common["watchers"] json.watchers project_common["watchers"]

View File

@ -7,11 +7,22 @@ if @project.educoder?
json.timestamp 0 json.timestamp 0
json.time_from_now commit[0]['time'] json.time_from_now commit[0]['time']
end end
if commit[0]['author'].present?
json.author do json.author do
{} json.id nil
# json.partial! '/projects/author', user: render_commit_author(commit['author']) json.login commit[0]['author']['username']
json.name commit[0]['author']['username']
json.type nil
json.image_url commit[0]['author']['image_url']
end
json.committer do
json.id nil
json.login commit[0]['author']['username']
json.name commit[0]['author']['username']
json.type nil
json.image_url commit[0]['author']['image_url']
end
end end
json.committer {}
end end
if @project.forge? if @project.forge?

View File

@ -32,6 +32,8 @@ end
if @project.educoder? if @project.educoder?
file_path = params[:filepath].present? ? [params[:filepath], entry['name']].join('/') : entry['name'] file_path = params[:filepath].present? ? [params[:filepath], entry['name']].join('/') : entry['name']
file_type = File.extname(entry['name'].to_s)[1..-1]
image_type = image_type?(file_type)
json.name entry['name'] json.name entry['name']
json.sha nil json.sha nil
@ -42,7 +44,7 @@ if @project.educoder?
json.target nil json.target nil
json.download_url nil json.download_url nil
json.direct_download false json.direct_download false
json.image_type false json.image_type image_type
json.is_readme_file false json.is_readme_file false
json.commit do json.commit do
json.message entry['title'] json.message entry['title']

View File

@ -1,6 +1,26 @@
if @hash_commit.blank? #如果有状态值,则表示报错了 if @hash_commit.blank? || @project.educoder? #如果有状态值,则表示报错了
json.total_count 0 json.total_count 0
json.commits [] json.commits do
json.array! @commits do |commit|
json.sha commit['id']
json.message commit['title']
json.time_from_now commit['time']
json.author do
json.id nil
json.login commit['author']['username']
json.name commit['author']['username']
json.type nil
json.image_url commit['author']['image_url']
end
json.committer do
json.id nil
json.login commit['author']['username']
json.name commit['author']['username']
json.type nil
json.image_url commit['author']['image_url']
end
end
end
else else
json.total_count @hash_commit[:total_count] json.total_count @hash_commit[:total_count]
json.commits do json.commits do

View File

@ -1,5 +1,5 @@
total_count = @contributors.size total_count = @contributors.size
json.contributors @contributors.each do |contributor| json.list @contributors.each do |contributor|
json.partial! 'contributor', locals: { contributor: contributor } json.partial! 'contributor', locals: { contributor: contributor }
end end
json.total_count total_count json.total_count total_count

View File

@ -44,7 +44,7 @@ end
if @result[:repo] if @result[:repo]
json.size replace_bytes_to_b(number_to_human_size(@result[:repo]['size'].to_i*1024)) json.size replace_bytes_to_b(number_to_human_size(@result[:repo]['size'].to_i*1024))
json.ssh_url @result[:repo]['ssh_url'] json.ssh_url @result[:repo]['ssh_url']
json.clone_url @result[:repo]['clone_url'] json.clone_url @project.educoder? ? "#{Rails.application.config_for(:configuration)['educoder']['git_site']}/#{@project&.project_educoder&.repo_name}.git" : @result[:repo]['clone_url']
json.default_branch @project.educoder? ? "master" : @result[:repo]['default_branch'] json.default_branch @project.educoder? ? "master" : @result[:repo]['default_branch']
json.empty @result[:repo]['empty'] json.empty @result[:repo]['empty']
json.full_name @result[:repo]['full_name'] json.full_name @result[:repo]['full_name']
@ -53,13 +53,13 @@ end
json.license_name @project.license_name json.license_name @project.license_name
json.branches_count @result[:branch_tag_total_count].present? ? (@result[:branch_tag_total_count]['branch_count'] || 0) : 0 json.branches_count @result[:branch_tag_total_count].present? ? (@result[:branch_tag_total_count]['branch_count'] || 0) : 0
json.tags_count @result[:branch_tag_total_count].present? ? (@result[:branch_tag_total_count]['tag_count'] || 0) : 0 json.tags_count @result[:branch_tag_total_count].present? ? (@result[:branch_tag_total_count]['tag_count'] || 0) : 0
json.contributors do # json.contributors do
total_count = @result[:contributor].size # total_count = @result[:contributor].size
json.list @result[:contributor].each do |contributor| # json.list @result[:contributor].each do |contributor|
json.partial! 'contributor', locals: { contributor: contributor } # json.partial! 'contributor', locals: { contributor: contributor }
end # end
json.total_count total_count # json.total_count total_count
end # end
json.languages @result[:language].blank? ? nil : @result[:language] # json.languages @result[:language].blank? ? nil : @result[:language]
json.partial! 'author', locals: { user: @project.owner } json.partial! 'author', locals: { user: @project.owner }

View File

@ -7,7 +7,7 @@ if @project.educoder?
end end
end end
json.commits_count @entries['commit_count'] json.commits_count @entries['commit_count']
json.zip_url @entries['git_url'] json.zip_url ''
json.tar_url '' json.tar_url ''
json.entries do json.entries do
json.array! @entries['trees'] do |entry| json.array! @entries['trees'] do |entry|

View File

@ -24,8 +24,12 @@ if @project.educoder?
end end
end end
json.entries do json.entries do
if @sub_entries['trees'].is_a?(Array)
json.array! @sub_entries['trees'] do |entry| json.array! @sub_entries['trees'] do |entry|
json.partial! 'repositories/simple_entry', locals: { entry: entry } json.partial! 'repositories/simple_entry', locals: { entry: entry }
end end
elsif @sub_entries['trees'].is_a?(Hash)
json.partial! 'repositories/simple_entry', locals: { entry: @sub_entries['trees'] }
end
end end
end end

View File

@ -9,6 +9,7 @@ Rails.application.routes.draw do
# Serve websocket cable requests in-process # Serve websocket cable requests in-process
mount ActionCable.server => '/cable' mount ActionCable.server => '/cable'
get 'attachments/entries/get_file', to: 'attachments#get_file' get 'attachments/entries/get_file', to: 'attachments#get_file'
get 'attachments/download/:id', to: 'attachments#show' get 'attachments/download/:id', to: 'attachments#show'
get 'attachments/download/:id/:filename', to: 'attachments#show' get 'attachments/download/:id/:filename', to: 'attachments#show'
@ -146,6 +147,16 @@ Rails.application.routes.draw do
get :get_children_journals get :get_children_journals
end end
end end
resources :claims, only: [:index] do
collection do
post :create
delete :destroy
get :index
put :update
end
end
resources :issue_times, only: [:create] do resources :issue_times, only: [:create] do
collection do collection do
post :end_work post :end_work

View File

@ -0,0 +1,11 @@
class CreateClaims < ActiveRecord::Migration[5.2]
def change
create_table :claims do |t|
t.integer :issue_id
t.integer :user_id
t.timestamps
t.index :issue_id
t.index :user_id
end
end
end

View File

@ -0,0 +1,5 @@
class AddNoteToClaim < ActiveRecord::Migration[5.2]
def change
add_column :claims, :note, :text
end
end