forked from Gitlink/forgeplus
Merge pull request '上传头像、组织团队限制、文件下载问题修复、branch简化数据、webhook问题修复' (#298) from develop into standalone_develop
This commit is contained in:
commit
f76dad680a
|
@ -704,14 +704,20 @@ class ApplicationController < ActionController::Base
|
|||
Rails.application.config_for(:configuration)['platform_url'] || request.base_url
|
||||
end
|
||||
|
||||
def image_type?(str)
|
||||
default_type = %w(png jpg gif tif psd svg bmp webp jpeg ico psd)
|
||||
default_type.include?(str&.downcase)
|
||||
end
|
||||
|
||||
def convert_image!
|
||||
@image = params[:image]
|
||||
@image = @image.nil? && params[:user].present? ? params[:user][:image] : @image
|
||||
return unless @image.present?
|
||||
max_size = EduSetting.get('upload_avatar_max_size') || 2 * 1024 * 1024 # 2M
|
||||
if @image.class == ActionDispatch::Http::UploadedFile
|
||||
render_error('请上传文件') if @image.size.zero?
|
||||
render_error('文件大小超过限制') if @image.size > max_size.to_i
|
||||
return render_error('请上传文件') if @image.size.zero?
|
||||
return render_error('文件大小超过限制') if @image.size > max_size.to_i
|
||||
return render_error('头像格式不正确!') unless image_type?(File.extname(@image.original_filename.to_s)[1..-1])
|
||||
else
|
||||
image = @image.to_s.strip
|
||||
return render_error('请上传正确的图片') if image.blank?
|
||||
|
|
|
@ -4,15 +4,24 @@ class Organizations::TeamsController < Organizations::BaseController
|
|||
before_action :check_user_can_edit_org, only: [:create, :update, :destroy]
|
||||
|
||||
def index
|
||||
#if @organization.is_owner?(current_user) || current_user.admin?
|
||||
@teams = @organization.teams
|
||||
#else
|
||||
# @teams = @organization.teams.joins(:team_users).where(team_users: {user_id: current_user.id})
|
||||
#end
|
||||
@is_admin = can_edit_org?
|
||||
@teams = @teams.includes(:team_units, :team_users)
|
||||
|
||||
@teams = kaminari_paginate(@teams)
|
||||
if params[:is_full].present?
|
||||
if can_edit_org?
|
||||
@teams = @organization.teams
|
||||
else
|
||||
@teams = []
|
||||
end
|
||||
else
|
||||
#if @organization.is_owner?(current_user) || current_user.admin?
|
||||
@teams = @organization.teams
|
||||
#else
|
||||
# @teams = @organization.teams.joins(:team_users).where(team_users: {user_id: current_user.id})
|
||||
#end
|
||||
@is_admin = can_edit_org?
|
||||
@teams = @teams.includes(:team_units, :team_users)
|
||||
|
||||
@teams = kaminari_paginate(@teams)
|
||||
end
|
||||
end
|
||||
|
||||
def search
|
||||
|
@ -34,8 +43,12 @@ class Organizations::TeamsController < Organizations::BaseController
|
|||
|
||||
def create
|
||||
ActiveRecord::Base.transaction do
|
||||
Organizations::CreateTeamForm.new(team_params).validate!
|
||||
@team = Organizations::Teams::CreateService.call(current_user, @organization, team_params)
|
||||
if @organization.teams.count >= 50
|
||||
return render_forbidden("组织的团队数量已超过限制!")
|
||||
else
|
||||
Organizations::CreateTeamForm.new(team_params).validate!
|
||||
@team = Organizations::Teams::CreateService.call(current_user, @organization, team_params)
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
|
|
|
@ -82,8 +82,9 @@ class ProjectsController < ApplicationController
|
|||
def branches
|
||||
return @branches = [] unless @project.forge?
|
||||
|
||||
result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier)
|
||||
@branches = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
||||
# result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier)
|
||||
result = Gitea::Repository::Branches::ListNameService.call(@owner, @project.identifier)
|
||||
@branches = result.is_a?(Hash) ? (result.key?(:status) ? [] : result["branch_name"]) : result
|
||||
end
|
||||
|
||||
def branches_slice
|
||||
|
|
|
@ -252,7 +252,7 @@ class RepositoriesController < ApplicationController
|
|||
domain = Gitea.gitea_config[:domain]
|
||||
api_url = Gitea.gitea_config[:base_url]
|
||||
|
||||
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{URI.escape(params[:filepath])}?ref=#{CGI.escape(params[:ref])}"
|
||||
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{CGI.escape(params[:filepath])}?ref=#{CGI.escape(params[:ref])}"
|
||||
file_path = [domain, api_url, url].join
|
||||
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&")
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class UsersController < ApplicationController
|
|||
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard]
|
||||
before_action :require_login, only: %i[me list sync_user_info]
|
||||
before_action :connect_to_ci_db, only: [:get_user_info]
|
||||
before_action :convert_image!, only: [:update]
|
||||
before_action :convert_image!, only: [:update, :update_image]
|
||||
skip_before_action :check_sign, only: [:attachment_show]
|
||||
|
||||
def connect_to_ci_db(options={})
|
||||
|
@ -82,10 +82,21 @@ class UsersController < ApplicationController
|
|||
Util.write_file(@image, avatar_path(@user)) if user_params[:image].present?
|
||||
@user.attributes = user_params.except(:image)
|
||||
unless @user.save
|
||||
render_error(@user.errors.full_messages.join(", "))
|
||||
render_error(-1, @user.errors.full_messages.join(", "))
|
||||
end
|
||||
end
|
||||
|
||||
def update_image
|
||||
return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id])
|
||||
return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
|
||||
|
||||
Util.write_file(@image, avatar_path(@user))
|
||||
return render_ok({message: '头像修改成功'})
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
render_error(-1, '头像修改失败!')
|
||||
end
|
||||
|
||||
def me
|
||||
@user = current_user
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ module RepositoriesHelper
|
|||
end
|
||||
|
||||
def image_type?(str)
|
||||
default_type = %w(png jpg gif tif psd svg bmp webp jpeg)
|
||||
default_type = %w(png jpg gif tif psd svg bmp webp jpeg ico psd)
|
||||
default_type.include?(str&.downcase)
|
||||
end
|
||||
|
||||
|
|
|
@ -29,8 +29,9 @@ module TagChosenHelper
|
|||
if project.educoder?
|
||||
return ['master']
|
||||
else
|
||||
branches = Gitea::Repository::Branches::ListService.call(project&.owner, project.identifier)
|
||||
branches.collect{|i| i["name"] if i.is_a?(Hash)}
|
||||
branches = Gitea::Repository::Branches::ListNameService.call(project&.owner, project.identifier)
|
||||
return branches.collect{|i| i["name"] if i.is_a?(Hash)} if branches.is_a?(Array)
|
||||
return branches["branch_name"] if branches.is_a?(Hash)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class MigrateRemoteRepositoryJob < ApplicationJob
|
|||
return if repo.blank?
|
||||
|
||||
puts "############ MigrateRemoteRepositoryJob starting ... ############"
|
||||
|
||||
params.except!(:auth_password, :auth_username) if params[:auth_username].nil?
|
||||
gitea_repository = Gitea::Repository::MigrateService.new(token, params).call
|
||||
puts "#gitea_repository#{gitea_repository}"
|
||||
if gitea_repository[0]==201
|
||||
|
|
|
@ -29,6 +29,7 @@ module Util
|
|||
file.write(io)
|
||||
end
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def download_file(url, save_path)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
class Gitea::WebhookTask < Gitea::Base
|
||||
serialize :payload_content, JSON
|
||||
serialize :request_content, JSON
|
||||
serialize :response_content, JSON
|
||||
|
||||
self.inheritance_column = nil
|
||||
|
||||
|
@ -10,4 +9,10 @@ class Gitea::WebhookTask < Gitea::Base
|
|||
belongs_to :webhook, class_name: "Gitea::Webhook", foreign_key: :hook_id
|
||||
|
||||
enum type: {gogs: 1, slack: 2, gitea: 3, discord: 4, dingtalk: 5, telegram: 6, msteams: 7, feishu: 8, matrix: 9}
|
||||
|
||||
def response_content_json
|
||||
JSON.parse(response_content)
|
||||
rescue
|
||||
{}
|
||||
end
|
||||
end
|
|
@ -0,0 +1,22 @@
|
|||
class Gitea::Repository::Branches::ListNameService < Gitea::ClientService
|
||||
attr_reader :user, :repo
|
||||
|
||||
def initialize(user, repo)
|
||||
@user = user
|
||||
@repo = repo
|
||||
end
|
||||
|
||||
def call
|
||||
response = get(url, params)
|
||||
render_200_response(response)
|
||||
end
|
||||
|
||||
private
|
||||
def params
|
||||
Hash.new.merge(token: user.gitea_token)
|
||||
end
|
||||
|
||||
def url
|
||||
"/repos/#{user.login}/#{repo}/branch_name_set".freeze
|
||||
end
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
json.id team.id
|
||||
json.name team.name
|
||||
json.nickname team.nickname.blank? ? team.name : team.nickname
|
|
@ -1,4 +1,8 @@
|
|||
json.total_count @teams.total_count
|
||||
json.total_count params[:is_full].present? ? @teams.count : @teams.total_count
|
||||
json.teams @teams do |team|
|
||||
json.partial! "detail", team: team, organization: @organization
|
||||
if params[:is_full].present?
|
||||
json.partial! "simple_detail", team: team, organization: @organization
|
||||
else
|
||||
json.partial! "detail", team: team, organization: @organization
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
json.array! @branches do |branch|
|
||||
json.name branch['name']
|
||||
json.user_can_push branch['user_can_push']
|
||||
json.user_can_merge branch['user_can_merge']
|
||||
json.protected branch['protected']
|
||||
branch_name = branch.is_a?(Hash) ? branch['name'] : branch
|
||||
json.name branch_name
|
||||
# json.user_can_push branch['user_can_push']
|
||||
# json.user_can_merge branch['user_can_merge']
|
||||
# json.protected branch['protected']
|
||||
json.http_url render_http_url(@project)
|
||||
json.zip_url render_zip_url(@owner, @repository, branch['name'])
|
||||
json.tar_url render_tar_url(@owner, @repository, branch['name'])
|
||||
json.last_commit do
|
||||
json.sha branch['commit']['id']
|
||||
json.message branch['commit']['message']
|
||||
json.timestamp render_unix_time(branch['commit']['timestamp'])
|
||||
json.time_from_now time_from_now(branch['commit']['timestamp'])
|
||||
json.author do
|
||||
json.partial! 'repositories/commit_author', user: render_cache_commit_author(branch['commit']['author']), name: branch['commit']['author']['name']
|
||||
end
|
||||
json.committer do
|
||||
json.partial! 'repositories/commit_author', user: render_cache_commit_author(branch['commit']['committer']), name: branch['commit']['committer']['name']
|
||||
end
|
||||
end
|
||||
json.zip_url render_zip_url(@owner, @repository, branch_name)
|
||||
json.tar_url render_tar_url(@owner, @repository, branch_name)
|
||||
# json.last_commit do
|
||||
# json.sha branch['commit']['id']
|
||||
# json.message branch['commit']['message']
|
||||
# json.timestamp render_unix_time(branch['commit']['timestamp'])
|
||||
# json.time_from_now time_from_now(branch['commit']['timestamp'])
|
||||
# json.author do
|
||||
# json.partial! 'repositories/commit_author', user: render_cache_commit_author(branch['commit']['author']), name: branch['commit']['author']['name']
|
||||
# end
|
||||
# json.committer do
|
||||
# json.partial! 'repositories/commit_author', user: render_cache_commit_author(branch['commit']['committer']), name: branch['commit']['committer']['name']
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
json.(webhook, :id, :url, :http_method, :is_active)
|
||||
json.type webhook.hook_task_type
|
||||
json.type webhook.type
|
||||
json.last_status webhook.last_status
|
||||
json.create_time Time.at(webhook.created_unix).strftime("%Y-%m-%d %H:%M:%S")
|
|
@ -1,6 +1,6 @@
|
|||
json.id @webhook.id
|
||||
json.(@webhook, :id, :http_method, :content_type, :url, :secret, :last_status, :is_active)
|
||||
json.type @webhook.hook_task_type
|
||||
json.type @webhook.type
|
||||
json.create_time Time.at(@webhook.created_unix).strftime("%Y-%m-%d %H:%M:%S")
|
||||
event = @webhook.events
|
||||
json.branch_filter event["branch_filter"]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
json.total_count @tasks.total_count
|
||||
json.tasks @tasks.each do |task|
|
||||
json.(task, :id, :type, :uuid, :is_succeed, :is_delivered, :payload_content, :request_content, :response_content)
|
||||
json.(task, :id, :event_type, :type, :uuid, :is_succeed, :is_delivered, :payload_content, :request_content)
|
||||
json.response_content task.response_content_json
|
||||
json.delivered_time Time.at(task.delivered*10**-9).strftime("%Y-%m-%d %H:%M:%S")
|
||||
end
|
|
@ -225,6 +225,7 @@ Rails.application.routes.draw do
|
|||
get :watch_users
|
||||
get :fan_users
|
||||
get :hovercard
|
||||
put :update_image
|
||||
end
|
||||
collection do
|
||||
post :following
|
||||
|
|
Loading…
Reference in New Issue