mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-18 02:35:57 +08:00
Merge branch 'dev_change_route' into dev_trustie
This commit is contained in:
78
app/assets/stylesheets/oauth.scss
Normal file
78
app/assets/stylesheets/oauth.scss
Normal file
@@ -0,0 +1,78 @@
|
||||
html{margin:0px;padding: 0px;font-size: 14px;font-family: "微软雅黑","宋体";}
|
||||
body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset, legend, button, input, textarea, th, td {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.IndexContent{
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
background-image: url('/images/oauth/backImg.png');
|
||||
background-repeat: no-repeat;
|
||||
background-size: cover;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
.indexLogo{
|
||||
width:80px;
|
||||
margin-bottom: 35px;
|
||||
}
|
||||
.indexPanel{
|
||||
width: 580px;
|
||||
min-height: 400px;
|
||||
background-color: #fff;
|
||||
box-shadow: 0px 2px 10px 5px rgba(0,0,0,0.05);
|
||||
border-radius: 5px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.indexTitle{
|
||||
height: 75px;
|
||||
line-height: 75px;
|
||||
font-size: 18px;
|
||||
color:#333;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
.indexInfo{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.indexInfos{
|
||||
padding:40px 60px;
|
||||
}
|
||||
.indexInfo > span{
|
||||
color: #333;
|
||||
font-size: 16px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
.indexInfo input{
|
||||
width: 100%;
|
||||
height:40px;
|
||||
border-radius: 2px;
|
||||
border:1px solid #eee;
|
||||
margin-top: 5px;
|
||||
padding:0px 0px 0px 8px;
|
||||
outline: none;
|
||||
}
|
||||
.indexInfo .checkInfo{
|
||||
height: 15px;
|
||||
color: red;
|
||||
}
|
||||
.indexBtn{
|
||||
text-align: center;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.indexSubmit{
|
||||
width: 50%;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
background-color: #1890FF;
|
||||
border:none;
|
||||
color: #fff;
|
||||
border-radius: 2px;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
}
|
||||
@@ -13,24 +13,12 @@ class AccountsController < ApplicationController
|
||||
password = params[:password]
|
||||
platform = (params[:platform] || 'forge')&.gsub(/\s+/, "")
|
||||
|
||||
@user = User.new(admin: false, login: username, mail: email, type: "User")
|
||||
@user.password = password
|
||||
@user.platform = platform
|
||||
@user.activate
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
interactor = Gitea::RegisterInteractor.call({username: username, email: email, password: password})
|
||||
if interactor.success?
|
||||
gitea_user = interactor.result
|
||||
result = Gitea::User::GenerateTokenService.new(username, password).call
|
||||
@user.gitea_token = result['sha1']
|
||||
@user.gitea_uid = gitea_user['id']
|
||||
if @user.save!
|
||||
UserExtension.create!(user_id: @user.id)
|
||||
render_ok({user: {id: @user.id, token: @user.gitea_token}})
|
||||
end
|
||||
result = autologin_register(username, email, password, platform)
|
||||
if result[:message].blank?
|
||||
render_ok({user: result[:user]})
|
||||
else
|
||||
render_error(interactor.error)
|
||||
render_error(result[:message])
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
|
||||
@@ -9,7 +9,8 @@ class ApplicationController < ActionController::Base
|
||||
include GitHelper
|
||||
include LoggerHelper
|
||||
include LoginHelper
|
||||
|
||||
include RegisterHelper
|
||||
|
||||
protect_from_forgery prepend: true, unless: -> { request.format.json? }
|
||||
|
||||
before_action :check_sign
|
||||
@@ -384,7 +385,7 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
def current_user
|
||||
if Rails.env.development?
|
||||
User.current = User.find 1
|
||||
User.current = User.find 36480
|
||||
else
|
||||
User.current
|
||||
end
|
||||
@@ -727,11 +728,6 @@ class ApplicationController < ActionController::Base
|
||||
render_not_found("未找到’#{project}’相关的项目") unless @project
|
||||
end
|
||||
|
||||
def find_project_with_identifier
|
||||
@project = Project.find_by_identifier! params[:id]
|
||||
render_not_found("未找到’#{params[:id]}’相关的项目") unless @project
|
||||
end
|
||||
|
||||
def find_project_with_id
|
||||
@project = Project.find(params[:project_id] || params[:id])
|
||||
rescue Exception => e
|
||||
@@ -743,6 +739,32 @@ class ApplicationController < ActionController::Base
|
||||
interactor.success? ? render_ok : render_error(interactor.error)
|
||||
end
|
||||
|
||||
# projects
|
||||
def load_project
|
||||
namespace = params[:owner]
|
||||
id = params[:repo] || params[:id]
|
||||
|
||||
@project = Project.find_with_namespace(namespace, id)
|
||||
|
||||
if @project and current_user.can_read_project?(@project)
|
||||
logger.info "###########: has project and can read project"
|
||||
@project
|
||||
elsif current_user.is_a?(AnonymousUser)
|
||||
logger.info "###########:This is AnonymousUser"
|
||||
@project = nil if !@project.is_public?
|
||||
render_forbidden and return
|
||||
else
|
||||
logger.info "###########:project not found"
|
||||
@project = nil
|
||||
render_not_found and return
|
||||
end
|
||||
@project
|
||||
end
|
||||
|
||||
def load_repository
|
||||
@repository ||= load_project.repository
|
||||
end
|
||||
|
||||
private
|
||||
def object_not_found
|
||||
uid_logger("Missing template or cant't find record, responding with 404")
|
||||
|
||||
@@ -10,7 +10,7 @@ module OperateProjectAbilityAble
|
||||
end
|
||||
|
||||
def authorizate_user_can_edit_repo!
|
||||
return if @repo.project.manager?(current_user) || current_user.admin?
|
||||
return if @repository.project.manager?(current_user) || current_user.admin?
|
||||
render_forbidden('你没有权限操作.')
|
||||
end
|
||||
|
||||
|
||||
28
app/controllers/concerns/register_helper.rb
Normal file
28
app/controllers/concerns/register_helper.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module RegisterHelper
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def autologin_register(username, email, password, platform= '')
|
||||
result = {message: nil, user: nil}
|
||||
|
||||
user = User.new(admin: false, login: username, mail: email, type: "User")
|
||||
user.password = password
|
||||
user.platform = platform
|
||||
user.activate
|
||||
|
||||
interactor = Gitea::RegisterInteractor.call({username: username, email: email, password: password})
|
||||
if interactor.success?
|
||||
gitea_user = interactor.result
|
||||
result = Gitea::User::GenerateTokenService.new(username, password).call
|
||||
user.gitea_token = result['sha1']
|
||||
user.gitea_uid = gitea_user['id']
|
||||
if user.save!
|
||||
UserExtension.create!(user_id: user.id)
|
||||
result[:user] = {id: user.id, token: user.gitea_token}
|
||||
end
|
||||
else
|
||||
result[:message] = interactor.error
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,5 +1,6 @@
|
||||
class ForksController < ApplicationController
|
||||
before_action :require_login, :find_project_with_id
|
||||
before_action :require_login
|
||||
before_action :load_project
|
||||
before_action :authenticate_project!, :authenticate_user!
|
||||
|
||||
def create
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class IssueTagsController < ApplicationController
|
||||
before_action :require_login, except: [:index]
|
||||
before_action :find_project_with_id
|
||||
before_action :set_project
|
||||
before_action :load_repository
|
||||
before_action :set_user
|
||||
before_action :check_issue_permission, except: :index
|
||||
before_action :set_issue_tag, only: [:edit, :update, :destroy]
|
||||
|
||||
@@ -38,12 +38,12 @@ class IssueTagsController < ApplicationController
|
||||
begin
|
||||
issue_tag = IssueTag.new(tag_params.merge(project_id: @project.id, user_id: current_user.id))
|
||||
if issue_tag.save
|
||||
gitea_tag = Gitea::Labels::CreateService.new(current_user, @repository.try(:identifier), tag_params).call
|
||||
if gitea_tag && issue_tag.update_attributes(gid: gitea_tag["id"], gitea_url: gitea_tag["url"])
|
||||
normal_status(0, "标签创建成功")
|
||||
else
|
||||
normal_status(-1, "标签创建失败")
|
||||
end
|
||||
# gitea_tag = Gitea::Labels::CreateService.new(current_user, @repository.try(:identifier), tag_params).call
|
||||
# if gitea_tag && issue_tag.update_attributes(gid: gitea_tag["id"], gitea_url: gitea_tag["url"])
|
||||
# normal_status(0, "标签创建成功")
|
||||
# else
|
||||
# normal_status(-1, "标签创建失败")
|
||||
# end
|
||||
else
|
||||
normal_status(-1, "标签创建失败")
|
||||
end
|
||||
@@ -79,12 +79,12 @@ class IssueTagsController < ApplicationController
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
if @issue_tag.update_attributes(tag_params)
|
||||
gitea_tag = Gitea::Labels::UpdateService.new(current_user, @repository.try(:identifier),@issue_tag.try(:gid), tag_params).call
|
||||
if gitea_tag
|
||||
normal_status(0, "标签更新成功")
|
||||
else
|
||||
normal_status(-1, "标签更新失败")
|
||||
end
|
||||
# gitea_tag = Gitea::Labels::UpdateService.new(current_user, @repository.try(:identifier),@issue_tag.try(:gid), tag_params).call
|
||||
# if gitea_tag
|
||||
# normal_status(0, "标签更新成功")
|
||||
# else
|
||||
# normal_status(-1, "标签更新失败")
|
||||
# end
|
||||
else
|
||||
normal_status(-1, "标签更新失败")
|
||||
end
|
||||
@@ -103,12 +103,12 @@ class IssueTagsController < ApplicationController
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
if @issue_tag.destroy
|
||||
issue_tag = Gitea::Labels::DeleteService.new(@user, @repository.try(:identifier), @issue_tag.try(:gid)).call
|
||||
if issue_tag
|
||||
normal_status(0, "标签删除成功")
|
||||
else
|
||||
normal_status(-1, "标签删除失败")
|
||||
end
|
||||
# issue_tag = Gitea::Labels::DeleteService.new(@user, @repository.try(:identifier), @issue_tag.try(:gid)).call
|
||||
# if issue_tag
|
||||
# normal_status(0, "标签删除成功")
|
||||
# else
|
||||
# normal_status(-1, "标签删除失败")
|
||||
# end
|
||||
else
|
||||
normal_status(-1, "标签删除失败")
|
||||
end
|
||||
@@ -121,13 +121,8 @@ class IssueTagsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def set_project
|
||||
# @project = Project.find_by_identifier! params[:project_id]
|
||||
@repository = @project.repository
|
||||
def set_user
|
||||
@user = @project.owner
|
||||
normal_status(-1, "项目不存在") unless @project.present?
|
||||
normal_status(-1, "仓库不存在") unless @repository.present?
|
||||
normal_status(-1, "用户不存在") unless @user.present?
|
||||
end
|
||||
|
||||
def check_issue_permission
|
||||
@@ -143,4 +138,4 @@ class IssueTagsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class IssuesController < ApplicationController
|
||||
before_action :require_login, except: [:index, :show, :index_chosen]
|
||||
before_action :find_project_with_id
|
||||
before_action :set_project_and_user
|
||||
before_action :load_project
|
||||
before_action :set_user
|
||||
before_action :check_issue_permission
|
||||
before_action :check_project_public, only: [:index ,:show, :copy, :index_chosen, :close_issue]
|
||||
|
||||
@@ -15,7 +15,7 @@ class IssuesController < ApplicationController
|
||||
@user_admin_or_member = current_user.present? && current_user.logged? && (current_user.admin || @project.member?(current_user))
|
||||
issues = @project.issues.issue_issue.issue_index_includes
|
||||
issues = issues.where(is_private: false) unless @user_admin_or_member
|
||||
|
||||
|
||||
@all_issues_size = issues.size
|
||||
@open_issues_size = issues.where.not(status_id: 5).size
|
||||
@close_issues_size = issues.where(status_id: 5).size
|
||||
@@ -347,11 +347,8 @@ class IssuesController < ApplicationController
|
||||
end
|
||||
|
||||
private
|
||||
def set_project_and_user
|
||||
# @project = Project.find_by_identifier(params[:project_id]) || (Project.find params[:project_id]) || (Project.find params[:id])
|
||||
def set_user
|
||||
@user = @project&.owner
|
||||
# normal_status(-1, "项目不存在") unless @project.present?
|
||||
normal_status(-1, "用户不存在") unless @user.present?
|
||||
end
|
||||
|
||||
def check_project_public
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class MembersController < ApplicationController
|
||||
before_action :require_login
|
||||
before_action :find_project_with_id
|
||||
before_action :load_project
|
||||
before_action :find_user_with_id, only: %i[create remove change_role]
|
||||
before_action :operate!, except: %i[index]
|
||||
before_action :check_member_exists!, only: %i[create]
|
||||
|
||||
39
app/controllers/oauth/educoder_controller.rb
Normal file
39
app/controllers/oauth/educoder_controller.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
class Oauth::EducoderController < Oauth::BaseController
|
||||
def bind
|
||||
begin
|
||||
login = params[:login]
|
||||
callback_url = params[:callback_url]
|
||||
token = params[:token]
|
||||
|
||||
::OauthEducoderForm.new({login: login, token: token, callback_url: callback_url}).validate!
|
||||
|
||||
open_user= OpenUsers::Educoder.find_by(uid: login)
|
||||
|
||||
if open_user.present? && open_user.user.present? && open_user.user.email_binded?
|
||||
if current_user != open_user.user
|
||||
logout_user
|
||||
successful_authentication(open_user.user)
|
||||
end
|
||||
redirect_to callback_url
|
||||
else
|
||||
if current_user.blank? || !current_user.logged?
|
||||
user = User.find_by(login: login)
|
||||
if user
|
||||
successful_authentication(user)
|
||||
OpenUsers::Educoder.create!(user: user, uid: user.login)
|
||||
|
||||
redirect_to callback_url
|
||||
else
|
||||
redirect_to oauth_register_path(login: login, callback_url: callback_url)
|
||||
end
|
||||
else
|
||||
# forge平台已登录
|
||||
OpenUsers::Educoder.create!(user: current_user, uid: login)
|
||||
redirect_to callback_url
|
||||
end
|
||||
end
|
||||
rescue WechatOauth::Error => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,6 @@
|
||||
class OauthController < ApplicationController
|
||||
layout "oauth_register", only: [:register]
|
||||
|
||||
DEFAULT_PASSWORD = "a12345678"
|
||||
TOKEN_CALL_BACK = "/oauth/get_token_callback"
|
||||
USER_INFO = "/oauth/userinfo"
|
||||
@@ -51,4 +53,35 @@ class OauthController < ApplicationController
|
||||
|
||||
def get_token_callback
|
||||
end
|
||||
|
||||
def register
|
||||
end
|
||||
|
||||
def auto_register
|
||||
login = params[:login]
|
||||
email = params[:mail]
|
||||
password = params[:password]
|
||||
callback_url = params[:callback_url]
|
||||
platform = params[:plathform] || 'educoder'
|
||||
|
||||
if User.where(mail: email).exists?
|
||||
render_error("该邮箱已使用过.") and return
|
||||
end
|
||||
|
||||
result = autologin_register(login, email, password, platform)
|
||||
logger.info "[Oauth educoer] =====#{result}"
|
||||
if result[:message].blank?
|
||||
logger.info "[Oauth educoer] ====auto_register success"
|
||||
user = User.find result[:user][:id]
|
||||
successful_authentication(user)
|
||||
OpenUsers::Educoder.create!(user: user, uid: user.login)
|
||||
|
||||
render_ok({callback_url: callback_url})
|
||||
# redirect_to callback_url
|
||||
else
|
||||
logger.info "[Oauth educoer] ====auto_register failed."
|
||||
render :action => "auto_register"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class ProjectTrendsController < ApplicationController
|
||||
before_action :find_project_with_id
|
||||
before_action :load_repository
|
||||
before_action :check_project_public
|
||||
|
||||
def index
|
||||
@@ -44,4 +44,4 @@ class ProjectTrendsController < ApplicationController
|
||||
normal_status(-1, "您没有权限")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
class Projects::BaseController < ApplicationController
|
||||
include PaginateHelper
|
||||
|
||||
before_action :require_login, :check_auth
|
||||
before_action :load_project
|
||||
before_action :load_repository
|
||||
|
||||
end
|
||||
|
||||
@@ -2,8 +2,8 @@ class ProjectsController < ApplicationController
|
||||
include ApplicationHelper
|
||||
include OperateProjectAbilityAble
|
||||
include ProjectsHelper
|
||||
before_action :require_login, except: %i[index branches group_type_list simple]
|
||||
before_action :find_project_with_id, only: %i[show branches update destroy fork_users praise_users watch_users]
|
||||
before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users]
|
||||
before_action :load_project, except: %i[index group_type_list migrate create]
|
||||
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
||||
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
||||
|
||||
@@ -100,8 +100,7 @@ class ProjectsController < ApplicationController
|
||||
end
|
||||
|
||||
def simple
|
||||
project = Project.includes(:owner, :repository).select(:id, :name, :identifier, :user_id, :project_type).find params[:id]
|
||||
json_response(project)
|
||||
json_response(@project)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class PullRequestsController < ApplicationController
|
||||
before_action :require_login, except: [:index, :show]
|
||||
before_action :find_project_with_id
|
||||
before_action :set_repository
|
||||
before_action :load_repository
|
||||
before_action :set_user, only: [:new, :get_branches]
|
||||
before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge,:get_branches,:create_merge_infos]
|
||||
# before_action :get_relatived, only: [:edit]
|
||||
include TagChosenHelper
|
||||
@@ -234,12 +234,8 @@ class PullRequestsController < ApplicationController
|
||||
|
||||
|
||||
private
|
||||
|
||||
def set_repository
|
||||
@repository = @project.repository
|
||||
def set_user
|
||||
@user = @project.owner
|
||||
normal_status(-1, "仓库不存在") unless @repository.present?
|
||||
normal_status(-1, "用户不存在") unless @user.present?
|
||||
end
|
||||
|
||||
def find_pull_request
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
class RepositoriesController < ApplicationController
|
||||
include ApplicationHelper
|
||||
include OperateProjectAbilityAble
|
||||
|
||||
before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror]
|
||||
before_action :find_project_with_includes, only: :show
|
||||
before_action :find_project, except: [:tags, :commit, :sync_mirror, :show]
|
||||
before_action :load_repository
|
||||
before_action :authorizate!, except: [:sync_mirror, :tags, :commit]
|
||||
before_action :find_repository_by_id, only: %i[commit sync_mirror tags]
|
||||
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
|
||||
before_action :get_ref, only: %i[entries sub_entries top_counts]
|
||||
before_action :get_latest_commit, only: %i[entries sub_entries top_counts]
|
||||
@@ -56,18 +55,18 @@ class RepositoriesController < ApplicationController
|
||||
end
|
||||
|
||||
def commit
|
||||
@commit = Gitea::Repository::Commits::GetService.new(@repo.user.login, @repo.identifier, params[:sha], current_user.gitea_token).call
|
||||
@commit = Gitea::Repository::Commits::GetService.new(@repository.user.login, @repository.identifier, params[:sha], current_user.gitea_token).call
|
||||
end
|
||||
|
||||
def tags
|
||||
@tags = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @repo.user.login, @repo.identifier, {page: params[:page], limit: params[:limit]}).call
|
||||
@tags = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier, {page: params[:page], limit: params[:limit]}).call
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create_file
|
||||
interactor = Gitea::CreateFileInteractor.call(current_user, content_params)
|
||||
interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @project.owner.login, content_params)
|
||||
if interactor.success?
|
||||
@file = interactor.result
|
||||
create_new_pr(params)
|
||||
@@ -77,7 +76,7 @@ class RepositoriesController < ApplicationController
|
||||
end
|
||||
|
||||
def update_file
|
||||
interactor = Gitea::UpdateFileInteractor.call(current_user, params.merge(identifier: @project.identifier))
|
||||
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @project.owner.login, params.merge(identifier: @project.identifier))
|
||||
if interactor.success?
|
||||
@file = interactor.result
|
||||
create_new_pr(params)
|
||||
@@ -88,7 +87,7 @@ class RepositoriesController < ApplicationController
|
||||
end
|
||||
|
||||
def delete_file
|
||||
interactor = Gitea::DeleteFileInteractor.call(current_user, params.merge(identifier: @project.identifier))
|
||||
interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @project.owner.login, params.merge(identifier: @project.identifier))
|
||||
if interactor.success?
|
||||
@file = interactor.result
|
||||
render_result(1, "文件删除成功")
|
||||
@@ -102,10 +101,10 @@ class RepositoriesController < ApplicationController
|
||||
end
|
||||
|
||||
def sync_mirror
|
||||
return render_error("正在镜像中..") if @repo.mirror.waiting?
|
||||
return render_error("正在镜像中..") if @repository.mirror.waiting?
|
||||
|
||||
@repo.sync_mirror!
|
||||
SyncMirroredRepositoryJob.perform_later(@repo.id, current_user.id)
|
||||
@repository.sync_mirror!
|
||||
SyncMirroredRepositoryJob.perform_later(@repository.id, current_user.id)
|
||||
render_ok
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class VersionReleasesController < ApplicationController
|
||||
before_action :find_project_with_id
|
||||
before_action :set_user_and_project
|
||||
before_action :load_repository
|
||||
before_action :set_user
|
||||
before_action :require_login, except: [:index]
|
||||
before_action :find_version , only: [:edit, :update, :destroy]
|
||||
|
||||
@@ -78,14 +78,14 @@ class VersionReleasesController < ApplicationController
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
version_params = releases_params
|
||||
|
||||
|
||||
if @version.update_attributes!(version_params)
|
||||
create_attachments(params[:attachment_ids], @version) if params[:attachment_ids].present?
|
||||
git_version_release = Gitea::Versions::UpdateService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier), version_params, @version.try(:version_gid)).call
|
||||
unless git_version_release
|
||||
raise Error, "更新失败"
|
||||
end
|
||||
|
||||
|
||||
normal_status(0, "更新成功")
|
||||
else
|
||||
normal_status(-1, "更新失败")
|
||||
@@ -123,14 +123,8 @@ class VersionReleasesController < ApplicationController
|
||||
|
||||
|
||||
private
|
||||
|
||||
def set_user_and_project
|
||||
# @project = Project.find_by_id(params[:project_id])
|
||||
@repository = @project.repository #项目的仓库
|
||||
@user = @project.owner
|
||||
unless @user.present? && @project.present? && @repository.present?
|
||||
normal_status(-1, "仓库不存在")
|
||||
end
|
||||
def set_user
|
||||
@user = @repository.user
|
||||
end
|
||||
|
||||
def find_version
|
||||
@@ -140,7 +134,7 @@ class VersionReleasesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def releases_params
|
||||
def releases_params
|
||||
{
|
||||
body: params[:body],
|
||||
draft: params[:draft] || false,
|
||||
@@ -151,7 +145,7 @@ class VersionReleasesController < ApplicationController
|
||||
}
|
||||
end
|
||||
|
||||
def create_attachments(attachment_ids, target)
|
||||
def create_attachments(attachment_ids, target)
|
||||
attachment_ids.each do |id|
|
||||
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
||||
unless attachment.blank?
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class VersionsController < ApplicationController
|
||||
before_action :require_login, except: [:index, :show]
|
||||
before_action :find_project_with_id
|
||||
before_action :load_repository
|
||||
before_action :check_issue_permission, except: [:show, :index]
|
||||
before_action :set_version, only: [:edit, :update, :destroy, :show,:update_status]
|
||||
|
||||
@@ -166,4 +166,4 @@ class VersionsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
36
app/forms/oauth_educoder_form.rb
Normal file
36
app/forms/oauth_educoder_form.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
class OauthEducoderForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :login, :token, :callback_url
|
||||
|
||||
validates :login, presence: true
|
||||
validates :token, presence: true
|
||||
validates :callback_url, presence: true
|
||||
|
||||
validate :check_callback_url!
|
||||
validate :check_auth!
|
||||
|
||||
def check_auth!
|
||||
Rails.logger.info "====login: #{login} ====token: #{token} ==== callback_url: #{callback_url}"
|
||||
secret = OauthEducoder.config[:access_key_secret]
|
||||
Rails.logger.info "==== secret: #{secret}"
|
||||
before_raw_pay_load = Digest::SHA1.hexdigest("#{login}#{secret}#{Time.now.to_i/60-1}")
|
||||
now_raw_pay_load = Digest::SHA1.hexdigest("#{login}#{secret}#{Time.now.to_i/60}")
|
||||
|
||||
Rails.logger.info "==== before_raw_pay_load: #{before_raw_pay_load}"
|
||||
Rails.logger.info "==== now_raw_pay_load: #{now_raw_pay_load}"
|
||||
Rails.logger.info "==== token: #{token}"
|
||||
|
||||
if token != now_raw_pay_load && token != before_raw_pay_load
|
||||
raise '你的请求无效值无效.'
|
||||
end
|
||||
end
|
||||
|
||||
def check_callback_url!
|
||||
request_host = URI.parse(callback_url).host
|
||||
callback_url = OauthEducoder.config[:callback_url_host]
|
||||
|
||||
raise 'callback_url参数无效.' if request_host != callback_url
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,15 +1,15 @@
|
||||
module Gitea
|
||||
class CreateFileInteractor
|
||||
def self.call(user, params={})
|
||||
interactor = new(user, params)
|
||||
def self.call(token, owner, params={})
|
||||
interactor = new(token, owner, params)
|
||||
interactor.run
|
||||
interactor
|
||||
end
|
||||
|
||||
attr_reader :error, :result
|
||||
|
||||
def initialize(user, params)
|
||||
@user = user
|
||||
def initialize(token, owner, params)
|
||||
@owner = owner
|
||||
@params = params
|
||||
end
|
||||
|
||||
@@ -23,7 +23,7 @@ module Gitea
|
||||
|
||||
def run
|
||||
Contents::CreateForm.new(valid_params).validate!
|
||||
response = Gitea::Repository::Entries::CreateService.new(user, @params[:identifier], @params[:filepath], file_params).call
|
||||
response = Gitea::Repository::Entries::CreateService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call
|
||||
render_result(response)
|
||||
rescue Exception => exception
|
||||
Rails.logger.info "Exception ===========> #{exception.message}"
|
||||
@@ -33,7 +33,7 @@ module Gitea
|
||||
|
||||
private
|
||||
|
||||
attr_reader :params, :user
|
||||
attr_reader :params, :owner, :token
|
||||
|
||||
def fail!(error)
|
||||
@error = error
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
module Gitea
|
||||
class DeleteFileInteractor
|
||||
def self.call(user, params={})
|
||||
interactor = new(user, params)
|
||||
def self.call(token, owner, params={})
|
||||
interactor = new(token, owner, params)
|
||||
interactor.run
|
||||
interactor
|
||||
end
|
||||
|
||||
attr_reader :error, :result
|
||||
|
||||
def initialize(user, params)
|
||||
@user = user
|
||||
def initialize(token, owner, params)
|
||||
@token = token
|
||||
@owner = owner
|
||||
@params = params
|
||||
end
|
||||
|
||||
@@ -23,7 +24,7 @@ module Gitea
|
||||
|
||||
def run
|
||||
Contents::DeleteForm.new(valid_params).validate!
|
||||
response = Gitea::Repository::Entries::DeleteService.new(user, @params[:identifier], @params[:filepath], file_params).call
|
||||
response = Gitea::Repository::Entries::DeleteService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call
|
||||
render_result(response)
|
||||
rescue Exception => exception
|
||||
fail!(exception.message)
|
||||
@@ -31,7 +32,7 @@ module Gitea
|
||||
|
||||
private
|
||||
|
||||
attr_reader :params, :user
|
||||
attr_reader :params, :owner, :token
|
||||
|
||||
def fail!(error)
|
||||
puts "[exception]: error"
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
module Gitea
|
||||
class UpdateFileInteractor
|
||||
def self.call(user, params={})
|
||||
interactor = new(user, params)
|
||||
def self.call(token, owner, params={})
|
||||
interactor = new(token, owner, params)
|
||||
interactor.run
|
||||
interactor
|
||||
end
|
||||
|
||||
attr_reader :error, :result
|
||||
|
||||
def initialize(user, params)
|
||||
@user = user
|
||||
def initialize(token, owner, params)
|
||||
@owner = owner
|
||||
@token = token
|
||||
@params = params
|
||||
end
|
||||
|
||||
@@ -23,7 +24,7 @@ module Gitea
|
||||
|
||||
def run
|
||||
Contents::UpdateForm.new(valid_params).validate!
|
||||
response = Gitea::Repository::Entries::UpdateService.new(user, @params[:identifier], @params[:filepath], file_params).call
|
||||
response = Gitea::Repository::Entries::UpdateService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call
|
||||
render_result(response)
|
||||
rescue Exception => exception
|
||||
fail!(exception.message)
|
||||
@@ -31,7 +32,7 @@ module Gitea
|
||||
|
||||
private
|
||||
|
||||
attr_reader :params, :user
|
||||
attr_reader :params, :owner, :token
|
||||
|
||||
def fail!(error)
|
||||
puts "[exception]: error"
|
||||
|
||||
20
app/libs/oauth_educoder.rb
Normal file
20
app/libs/oauth_educoder.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
module OauthEducoder
|
||||
class << self
|
||||
def config
|
||||
educoder_config = {}
|
||||
|
||||
begin
|
||||
config = Rails.application.config_for(:configuration).symbolize_keys!
|
||||
educoder_config = config[:oauth_educoder].symbolize_keys!
|
||||
raise 'oauth educoder config missing' if educoder_config.blank?
|
||||
rescue => ex
|
||||
raise ex if Rails.env.production?
|
||||
|
||||
puts %Q{\033[33m [warning] educoder config or configuration.yml missing,
|
||||
please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m}
|
||||
educoder_config = {}
|
||||
end
|
||||
educoder_config
|
||||
end
|
||||
end
|
||||
end
|
||||
14
app/models/concerns/project_ability.rb
Normal file
14
app/models/concerns/project_ability.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
module ProjectAbility
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
|
||||
end
|
||||
|
||||
def can_read_project?(project)
|
||||
return true if self.admin?
|
||||
return false if !project.is_public? && !project.member?(self.id)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
9
app/models/open_users/educoder.rb
Normal file
9
app/models/open_users/educoder.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class OpenUsers::Educoder < OpenUser
|
||||
def nickname
|
||||
extra&.[]('nickname')
|
||||
end
|
||||
|
||||
def en_type
|
||||
'educoder'
|
||||
end
|
||||
end
|
||||
@@ -160,7 +160,7 @@ class Project < ApplicationRecord
|
||||
member&.roles&.last&.name || permission
|
||||
end
|
||||
|
||||
def fork_project
|
||||
def fork_project
|
||||
Project.find_by(id: self.forked_from_project_id)
|
||||
end
|
||||
|
||||
@@ -168,4 +168,15 @@ class Project < ApplicationRecord
|
||||
joins(:members).where(members: { user_id: member_user_id})
|
||||
end
|
||||
|
||||
def self.find_with_namespace(namespace_path, identifier)
|
||||
logger.info "########namespace_path: #{namespace_path} ########identifier: #{identifier} "
|
||||
|
||||
user = User.find_by_login namespace_path
|
||||
return nil if user.blank?
|
||||
|
||||
project = user.projects.find_by(identifier: identifier)
|
||||
|
||||
return nil if project.blank?
|
||||
project
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,6 +5,7 @@ class User < ApplicationRecord
|
||||
include Likeable
|
||||
include BaseModel
|
||||
include ProjectOperable
|
||||
include ProjectAbility
|
||||
# include Searchable::Dependents::User
|
||||
|
||||
# Account statuses
|
||||
@@ -70,8 +71,8 @@ class User < ApplicationRecord
|
||||
# 关注
|
||||
has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
|
||||
has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
|
||||
|
||||
has_many :watchers, as: :watchable, dependent: :destroy
|
||||
|
||||
has_many :watchers, as: :watchable, dependent: :destroy
|
||||
|
||||
# 认证
|
||||
has_many :apply_user_authentication
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Gitea::Repository::Entries::CreateService < Gitea::ClientService
|
||||
attr_reader :user, :repo_name, :filepath, :body
|
||||
attr_reader :token, :owner, :repo_name, :filepath, :body
|
||||
|
||||
# ref: The name of the commit/branch/tag. Default the repository’s default branch (usually master)
|
||||
# filepath: path of the dir, file, symlink or submodule in the repo
|
||||
@@ -20,8 +20,9 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService
|
||||
# "new_branch": "string"
|
||||
# }
|
||||
#
|
||||
def initialize(user, repo_name, filepath, body)
|
||||
@user = user
|
||||
def initialize(token, owner, repo_name, filepath, body)
|
||||
@token = token
|
||||
@owner = owner
|
||||
@repo_name = repo_name
|
||||
@filepath = filepath
|
||||
@body = body
|
||||
@@ -33,11 +34,11 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService
|
||||
|
||||
private
|
||||
def params
|
||||
Hash.new.merge(token: user.gitea_token, data: body)
|
||||
Hash.new.merge(token: token, data: body)
|
||||
end
|
||||
|
||||
def url
|
||||
"/repos/#{user.login}/#{repo_name}/contents/#{filepath}".freeze
|
||||
"/repos/#{owner}/#{repo_name}/contents/#{filepath}".freeze
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Gitea::Repository::Entries::DeleteService < Gitea::ClientService
|
||||
attr_reader :user, :repo_name, :filepath, :body
|
||||
attr_reader :token, :owner, :repo_name, :filepath, :body
|
||||
|
||||
# ref: The name of the commit/branch/tag. Default the repository’s default branch (usually master)
|
||||
# filepath: path of the dir, file, symlink or submodule in the repo
|
||||
@@ -19,8 +19,9 @@ class Gitea::Repository::Entries::DeleteService < Gitea::ClientService
|
||||
# "new_branch": "string",
|
||||
# "sha": "string", #require
|
||||
# }
|
||||
def initialize(user, repo_name, filepath, body)
|
||||
@user = user
|
||||
def initialize(token, owner, repo_name, filepath, body)
|
||||
@token = token
|
||||
@owner = owner
|
||||
@repo_name = repo_name
|
||||
@filepath = filepath
|
||||
@body = body
|
||||
@@ -32,11 +33,11 @@ class Gitea::Repository::Entries::DeleteService < Gitea::ClientService
|
||||
|
||||
private
|
||||
def params
|
||||
Hash.new.merge(token: user.gitea_token, data: body)
|
||||
Hash.new.merge(token: token, data: body)
|
||||
end
|
||||
|
||||
def url
|
||||
"/repos/#{user.login}/#{repo_name}/contents/#{filepath}".freeze
|
||||
"/repos/#{owner}/#{repo_name}/contents/#{filepath}".freeze
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Gitea::Repository::Entries::UpdateService < Gitea::ClientService
|
||||
attr_reader :user, :repo_name, :filepath, :body
|
||||
attr_reader :token, :owner, :repo_name, :filepath, :body
|
||||
|
||||
# ref: The name of the commit/branch/tag. Default the repository’s default branch (usually master)
|
||||
# filepath: path of the dir, file, symlink or submodule in the repo
|
||||
@@ -20,8 +20,9 @@ class Gitea::Repository::Entries::UpdateService < Gitea::ClientService
|
||||
# "new_branch": "string"
|
||||
# }
|
||||
#
|
||||
def initialize(user, repo_name, filepath, body)
|
||||
@user = user
|
||||
def initialize(token, owner, repo_name, filepath, body)
|
||||
@token = token
|
||||
@owner = owner
|
||||
@repo_name = repo_name
|
||||
@filepath = filepath
|
||||
@body = body
|
||||
@@ -33,11 +34,11 @@ class Gitea::Repository::Entries::UpdateService < Gitea::ClientService
|
||||
|
||||
private
|
||||
def params
|
||||
Hash.new.merge(token: user.gitea_token, data: body)
|
||||
Hash.new.merge(token: token, data: body)
|
||||
end
|
||||
|
||||
def url
|
||||
"/repos/#{user.login}/#{repo_name}/contents/#{filepath}".freeze
|
||||
"/repos/#{owner}/#{repo_name}/contents/#{filepath}".freeze
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
14
app/views/layouts/oauth_register.html.erb
Normal file
14
app/views/layouts/oauth_register.html.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<html>
|
||||
<head>
|
||||
<%= csrf_meta_tags %>
|
||||
<%= csp_meta_tag %>
|
||||
<%= javascript_include_tag '/javascripts/jquery-1.8.3-ui-1.9.2-ujs-2.0.3', '': '' %>
|
||||
<%= stylesheet_link_tag '/stylesheets/css/oauth', '', :media => 'all' %>
|
||||
</head>
|
||||
<body>
|
||||
<div class="IndexContent">
|
||||
<%= image_tag('/images/oauth/logo.png') %>
|
||||
<%= yield %>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
78
app/views/oauth/register.html.erb
Normal file
78
app/views/oauth/register.html.erb
Normal file
@@ -0,0 +1,78 @@
|
||||
<div class="indexPanel">
|
||||
<p class="indexTitle">完善信息,进入比赛</p>
|
||||
<div class="indexInfos">
|
||||
|
||||
<%= form_tag('', method: :post, id: 'oauth_form', class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<%= hidden_field_tag 'callback_url', params[:callback_url] %>
|
||||
<div class="indexInfo">
|
||||
<span>用户名:</span>
|
||||
<%= text_field_tag :login, params[:login], placeholder: '请输入用户名', readonly: true, id: 'login' %>
|
||||
<p class="checkInfo loginCheck"><span></span></p>
|
||||
</div>
|
||||
<div class="indexInfo">
|
||||
<span>邮箱:</span>
|
||||
<%= text_field_tag :mail, '', placeholder: '请输入绑定邮箱', maxlength: 40, id: 'email' %>
|
||||
<p class="checkInfo emailCheck"><span></span></p>
|
||||
</div>
|
||||
<div class="indexInfo">
|
||||
<span>密码:</span>
|
||||
<%= password_field_tag :password, '', placeholder: '请输入账号密码', id: 'password' %>
|
||||
<p class="checkInfo passwordCheck"><span></span></p>
|
||||
</div>
|
||||
<div class="indexBtn">
|
||||
<button type="button" class="indexSubmit" id="indexSubmit" onclick="submitdata();">确定</button>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
function submitdata(){
|
||||
var login = $("#login").val();
|
||||
var email = $("#email").val();
|
||||
var password = $("#password").val();
|
||||
|
||||
if(!login){
|
||||
$(".loginCheck span").html("请输入账号");
|
||||
return;
|
||||
}else{
|
||||
$(".loginCheck span").html("");
|
||||
}
|
||||
if(!email){
|
||||
$(".emailCheck span").html("请输入绑定的邮箱");
|
||||
return;
|
||||
}else{
|
||||
$(".emailCheck span").html("");
|
||||
}
|
||||
if(!password){
|
||||
$(".passwordCheck span").html("请输入账号密码");
|
||||
return;
|
||||
}else if(password.length < 8){
|
||||
$(".passwordCheck span").html("密码最少为8位数");
|
||||
return;
|
||||
}else{
|
||||
$(".passwordCheck span").html("");
|
||||
}
|
||||
$.ajax({
|
||||
url: "<%= oauth_auto_register_path %>",
|
||||
data: $("#oauth_form").serialize(),
|
||||
type: 'post',
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
console.log(data)
|
||||
if (data) {
|
||||
if(data.message){
|
||||
$(".emailCheck span").html("该邮箱已存在.");
|
||||
return;
|
||||
}
|
||||
// data.redirect contains the string URL to redirect to
|
||||
// window.location.href = "<%#= params[:callback_url] %>";
|
||||
window.location.href = data.callback_url;
|
||||
}
|
||||
},
|
||||
error: function (data) {
|
||||
console.log('ajax error handling',data);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
</script>
|
||||
@@ -1,12 +1,13 @@
|
||||
json.count @forks_count
|
||||
json.users do
|
||||
json.users do
|
||||
json.array! @fork_users.each do |f|
|
||||
user = f.user
|
||||
fork_project = Project.select(:id,:name).find_by(id: f.fork_project_id)
|
||||
user = f.user
|
||||
fork_project = Project.select(:id,:name, :identifier).find_by(id: f.fork_project_id)
|
||||
json.id f.fork_project_id
|
||||
json.identifier fork_project.identifier
|
||||
json.name "#{user.try(:show_real_name)}/#{fork_project.try(:name)}"
|
||||
json.login user.try(:login)
|
||||
json.image_url url_to_avatar(user)
|
||||
json.format_time f.created_at.strftime("%Y-%m-%d")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
json.commit do
|
||||
json.sha commit['sha']
|
||||
json.url EduSetting.get('host_name') + commit_repository_path(project.repository, commit['sha'])
|
||||
# json.url EduSetting.get('host_name') + commit_repository_path(project.repository, commit['sha'])
|
||||
json.message commit['commit']['message']
|
||||
json.author commit['commit']['author']
|
||||
json.committer commit['commit']['committer']
|
||||
|
||||
@@ -31,6 +31,7 @@ json.fork_info do
|
||||
if @fork_project.present?
|
||||
json.fork_form_name @fork_project.try(:name)
|
||||
json.fork_project_user_login @fork_project_user.try(:login)
|
||||
json.fork_project_identifier @fork_project.identifier
|
||||
json.fork_project_user_name @fork_project_user.try(:show_real_name)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,8 +5,8 @@ json.members_count project.members.count
|
||||
json.issues_count project.issues.count
|
||||
json.changesets_count project.project_score&.changeset_num.to_i
|
||||
|
||||
json.is_public project&.is_public
|
||||
json.can_visited project&.can_visited?
|
||||
json.is_public project.is_public?
|
||||
json.can_visited project.can_visited?
|
||||
|
||||
json.owner do
|
||||
json.partial! 'users/shared/real_user', user: project.owner
|
||||
|
||||
@@ -5,4 +5,4 @@ json.image_url url_to_avatar(subject)
|
||||
json.owner_id subject.user.id
|
||||
json.owner_name subject.user.full_name
|
||||
json.visits_count subject.visits
|
||||
json.can_visited subject&.can_visited?
|
||||
json.can_visited subject.can_visited?
|
||||
|
||||
Reference in New Issue
Block a user