| @@ -532,17 +532,18 @@ curl -X POST http://localhost:3000/api/repositories/1244/sync_mirror | jq | |||
| #### 项目详情 | |||
| ``` | |||
| GET api/projects/:id | |||
| GET /api/:namespace_id/:id | |||
| ``` | |||
| *示例* | |||
| ``` | |||
| curl -X GET http://localhost:3000/api/projects/3263 | jq | |||
| curl -X GET http://localhost:3000/api/jasder/jasder_test | jq | |||
| ``` | |||
| *请求参数说明:* | |||
| |参数名|必选|类型|说明| | |||
| |-|-|-|-| | |||
| |id |是|int |项目id | | |||
| |namespace_id |是|string |用户登录名 | | |||
| |id |是|string |项目标识identifier | | |||
| *返回参数说明:* | |||
| @@ -571,6 +572,50 @@ curl -X GET http://localhost:3000/api/projects/3263 | jq | |||
| ``` | |||
| --- | |||
| #### 项目详情(简版) | |||
| ``` | |||
| GET /api/:namespace_id/:id/simple | |||
| ``` | |||
| *示例* | |||
| ``` | |||
| curl -X GET http://localhost:3000/api/jasder/jasder_test/simple | jq | |||
| ``` | |||
| *请求参数说明:* | |||
| |参数名|必选|类型|说明| | |||
| |-|-|-|-| | |||
| |id |是|int |项目id | | |||
| *返回参数说明:* | |||
| |参数名|类型|说明| | |||
| |-|-|-| | |||
| |id |int |id | | |||
| |name |string|项目名称| | |||
| |identifier |string|项目标识| | |||
| |is_public |boolean|项目是否公开, true:公开,false:私有| | |||
| |description |string|项目简介| | |||
| |repo_id |int|仓库id| | |||
| |repo_identifier|string|仓库标识| | |||
| 返回值 | |||
| ``` | |||
| { | |||
| "identifier": "jasder_test", | |||
| "name": "jasder的测试项目", | |||
| "id": 4967, | |||
| "type": 0, | |||
| "author": { | |||
| "login": "jasder", | |||
| "name": "姓名", | |||
| "image_url": "avatars/User/b" | |||
| } | |||
| } | |||
| ``` | |||
| --- | |||
| #### 编辑仓库信息 | |||
| ``` | |||
| GET /api/repositories/:id/edit.json | |||
| @@ -898,13 +943,13 @@ curl -X POST http://localhost:3000/api/projects/3297/forks | jq | |||
| #### 获取代码目录列表 | |||
| ``` | |||
| POST /api/repositories/:id/entries.json | |||
| POST /api/:namespace_id/:project_id/repository/entries | |||
| ``` | |||
| *示例* | |||
| ``` | |||
| curl -X GET \ | |||
| -d "ref=develop" \ | |||
| http://localhost:3000//api/repositories/3687/entries.json | jq | |||
| http://localhost:3000//api/jasder/jasder_test/repository/entries | jq | |||
| ``` | |||
| *请求参数说明:* | |||
| @@ -1321,11 +1366,11 @@ http://localhost:3000/api/projects | jq | |||
| ### 获取分支列表 | |||
| ``` | |||
| GET /api/projects/:id/branches | |||
| GET /api/:namespace_id/:id/branches | |||
| ``` | |||
| *示例* | |||
| ``` | |||
| curl -X GET http://localhost:3000/api/projects/4797/branches | jq | |||
| curl -X GET http://localhost:3000/api/jasder/jasder_test/branches | jq | |||
| ``` | |||
| *请求参数说明:* | |||
| @@ -1488,18 +1533,19 @@ http://localhost:3000/api/repositories/5836/tags.json | jq | |||
| ## 仓库详情 | |||
| ``` | |||
| GET /api/repositories/:id | |||
| GET /api/:namespace_id/:project_id/repository | |||
| ``` | |||
| *示例* | |||
| ``` | |||
| curl -X GET \ | |||
| http://localhost:3000/api/repositories/23.json | jq | |||
| http://192.168.2.230:3000/api/jasder/forgeplus/repository | jq | |||
| ``` | |||
| *请求参数说明:* | |||
| |参数名|必选|类型|说明| | |||
| |-|-|-|-| | |||
| |id |是|string |项目id | | |||
| |namespace_id |是|string |用户登录名 | | |||
| |project_id |是|string |项目标识identifier | | |||
| *返回参数说明:* | |||
| @@ -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 | |||
| @@ -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] | |||
| @@ -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 | |||
| @@ -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" | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -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> | |||
| @@ -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? | |||
| @@ -12,5 +12,4 @@ Rails.application.config.assets.paths << Rails.root.join('vendor/assets') | |||
| # Precompile additional assets. | |||
| # application.js, application.css, and all non-JS/CSS in the app/assets | |||
| # folder are already added. | |||
| Rails.application.config.assets.precompile += %w( admin.js admin.css college.js college.css cooperative.js cooperative.css ) | |||
| Rails.application.config.assets.precompile += %w( admin.js admin.css college.js college.css cooperative.js cooperative.css oauth.css ) | |||
| @@ -13,11 +13,16 @@ Rails.application.routes.draw do | |||
| get 'auth/qq/callback', to: 'oauth/qq#create' | |||
| get 'auth/failure', to: 'oauth/base#auth_failure' | |||
| get 'auth/cas/callback', to: 'oauth/cas#create' | |||
| get 'oauth/bind', to: 'oauth/educoder#bind' | |||
| get 'oauth/register', to: 'oauth#register' | |||
| post 'oauth/auto_register', to: 'oauth#auto_register' | |||
| resources :edu_settings | |||
| scope '/api' do | |||
| resources :sync_forge, only: [:create] do | |||
| collection do | |||
| resources :sync_forge, only: [:create] do | |||
| collection do | |||
| post :sync_users | |||
| post :sync_range_projects | |||
| end | |||
| @@ -68,41 +73,6 @@ Rails.application.routes.draw do | |||
| end | |||
| end | |||
| resources :projects do | |||
| resources :hooks | |||
| resources :pull_requests, except: [:destroy] do | |||
| member do | |||
| post :pr_merge | |||
| # post :check_merge | |||
| post :refuse_merge | |||
| end | |||
| collection do | |||
| post :check_can_merge | |||
| get :create_merge_infos | |||
| get :get_branches | |||
| end | |||
| end | |||
| resources :version_releases, only: [:index,:new, :create, :edit, :update, :destroy] | |||
| resources :project_trends, only: [:index, :create] | |||
| resources :issues do | |||
| collection do | |||
| get :commit_issues | |||
| get :index_chosen | |||
| post :clean | |||
| post :series_update | |||
| end | |||
| member do | |||
| post :copy | |||
| post :close_issue | |||
| post :lock_issue | |||
| end | |||
| end | |||
| resources :issue_tags, only: [:create, :edit, :update, :destroy, :index] | |||
| resources :versions do | |||
| member do | |||
| post :update_status | |||
| end | |||
| end | |||
| resources :praise_tread, only: [:index] do | |||
| collection do | |||
| post :like | |||
| @@ -110,25 +80,10 @@ Rails.application.routes.draw do | |||
| get :check_like | |||
| end | |||
| end | |||
| resources :members, only: [:index, :create] do | |||
| collection do | |||
| delete :remove | |||
| put :change_role | |||
| end | |||
| end | |||
| resources :forks, only: [:create] | |||
| collection do | |||
| post :migrate | |||
| get :group_type_list | |||
| post :watch | |||
| end | |||
| member do | |||
| get :branches | |||
| post :watch | |||
| get :watch_users | |||
| get :praise_users | |||
| get :fork_users | |||
| get :simple | |||
| end | |||
| end | |||
| @@ -177,7 +132,7 @@ Rails.application.routes.draw do | |||
| scope module: :users do | |||
| # resources :courses, only: [:index] | |||
| resources :projects, only: [:index] | |||
| # resources :projects, only: [:index] | |||
| # resources :subjects, only: [:index] | |||
| resources :project_packages, only: [:index] | |||
| # 私信 | |||
| @@ -187,11 +142,6 @@ Rails.application.routes.draw do | |||
| # resource :unread_message_info, only: [:show] | |||
| end | |||
| resources :projects, module: :users, only: [] do | |||
| get :search, on: :collection | |||
| end | |||
| resources :tidings, only: [:index] | |||
| scope module: :users do | |||
| @@ -210,23 +160,6 @@ Rails.application.routes.draw do | |||
| end | |||
| end | |||
| resources :repositories, only: [:index, :show, :edit] do | |||
| member do | |||
| get :entries | |||
| match :sub_entries, :via => [:get, :put] | |||
| get :commits | |||
| post :files | |||
| get :tags | |||
| post :create_file | |||
| put :update_file | |||
| delete :delete_file | |||
| post :repo_hook | |||
| post :sync_mirror | |||
| get :top_counts | |||
| get 'commits/:sha', to: 'repositories#commit', as: 'commit' | |||
| end | |||
| end | |||
| resources :users_for_private_messages, only: [:index] | |||
| resources :files, only: [:index, :show, :update] do | |||
| @@ -246,119 +179,6 @@ Rails.application.routes.draw do | |||
| end | |||
| end | |||
| resources :courses do | |||
| member do | |||
| get 'settings', :action => 'settings', :as => 'settings' | |||
| post 'set_invite_code_halt' | |||
| post 'set_public_or_private' | |||
| post 'search_teacher_candidate' | |||
| post 'add_teacher' | |||
| post 'create_graduation_group' | |||
| post 'join_graduation_group' | |||
| post 'set_course_group' | |||
| post 'change_course_admin' | |||
| post 'change_member_role' | |||
| post 'change_course_teacher' | |||
| post 'delete_course_teacher' | |||
| post 'teacher_application_review' | |||
| post 'transfer_to_course_group' | |||
| post 'delete_from_course' | |||
| post 'add_students_by_search' | |||
| post 'create_group_by_importing_file' | |||
| post 'duplicate_course' | |||
| post 'visits_plus_one' | |||
| get 'get_historical_courses' | |||
| get 'get_historical_course_students' | |||
| get 'course_group_list' | |||
| get 'add_teacher_popup' | |||
| get 'teachers' | |||
| get 'apply_teachers' | |||
| get 'graduation_group_list' | |||
| get 'top_banner' | |||
| get 'left_banner' | |||
| get 'students' | |||
| get 'all_course_groups' | |||
| get 'search_users' | |||
| get 'base_info' | |||
| get 'attahcment_category_list' | |||
| get 'export_member_scores_excel' #导出课堂信息 | |||
| get 'export_couser_info' | |||
| get 'export_member_act_score' | |||
| post 'switch_to_teacher' | |||
| post 'switch_to_assistant' | |||
| post 'switch_to_student' | |||
| post 'exit_course' | |||
| get 'informs' | |||
| post 'update_informs' | |||
| post 'new_informs' | |||
| delete 'delete_informs' | |||
| get 'online_learning' | |||
| post 'join_excellent_course' | |||
| get 'tasks_list' | |||
| post 'update_task_position' | |||
| get 'course_groups' | |||
| post 'join_course_group' | |||
| get 'work_score' | |||
| get 'act_score' | |||
| get 'statistics' | |||
| get 'course_videos' | |||
| delete 'delete_course_video' | |||
| post :inform_up | |||
| post :inform_down | |||
| end | |||
| collection do | |||
| post 'apply_to_join_course' | |||
| post 'search_course_list' | |||
| get 'board_list' | |||
| get 'mine' | |||
| get 'search_slim' | |||
| end | |||
| resources :course_stages, shallow: true do | |||
| member do | |||
| post :up_position | |||
| post :down_position | |||
| end | |||
| end | |||
| resources :course_groups, shallow: true do | |||
| member do | |||
| post 'rename_group' | |||
| post 'move_category' | |||
| post 'set_invite_code_halt' | |||
| end | |||
| end | |||
| end | |||
| resources :course_modules, shallow: true do | |||
| member do | |||
| get 'sticky_module' | |||
| get 'hidden_module' | |||
| post 'rename_module' | |||
| post 'add_second_category' | |||
| end | |||
| collection do | |||
| post 'unhidden_modules' | |||
| end | |||
| end | |||
| resources :course_second_categories, shallow: true do | |||
| member do | |||
| post 'rename_category' | |||
| post 'move_category' | |||
| end | |||
| end | |||
| resources :repertoires, only: [:index] | |||
| scope module: :projects do | |||
| resources :project_applies, only: [:create] | |||
| end | |||
| namespace :wechats do | |||
| resource :js_sdk_signature, only: [:create] | |||
| end | |||
| @@ -411,6 +231,151 @@ Rails.application.routes.draw do | |||
| end | |||
| end | |||
| end | |||
| # Project Area START | |||
| scope "/:owner/:repo" do | |||
| scope do | |||
| get( | |||
| '/activity', | |||
| to: 'project_trends#index', | |||
| as: :project_activity | |||
| ) | |||
| end | |||
| resource :projects, path: '/', except: [:show, :edit] do | |||
| member do | |||
| get :branches | |||
| get :simple | |||
| get :watchers, to: 'projects#watch_users' | |||
| get :stargazers, to: 'projects#praise_users' | |||
| get :members, to: 'projects#fork_users' | |||
| end | |||
| end | |||
| resource :repositories, path: '/', only: [:show, :create, :edit] do | |||
| member do | |||
| get :archive | |||
| get :top_counts | |||
| get :entries | |||
| match :sub_entries, :via => [:get, :put] | |||
| get :commits | |||
| get :tags | |||
| post :create_file | |||
| put :update_file | |||
| delete :delete_file | |||
| post :repo_hook | |||
| post :sync_mirror | |||
| get :top_counts | |||
| get 'commits/:sha', to: 'repositories#commit', as: 'commit' | |||
| end | |||
| end | |||
| resources :issues do | |||
| collection do | |||
| get :commit_issues | |||
| get :index_chosen | |||
| post :clean | |||
| post :series_update | |||
| end | |||
| member do | |||
| post :copy | |||
| post :close_issue | |||
| post :lock_issue | |||
| end | |||
| end | |||
| resources :pull_requests, :path => :pulls, except: [:destroy] do | |||
| member do | |||
| post :pr_merge | |||
| # post :check_merge | |||
| post :refuse_merge | |||
| end | |||
| collection do | |||
| post :check_can_merge | |||
| get :create_merge_infos | |||
| get :get_branches | |||
| end | |||
| end | |||
| resources :versions, :path => :milestones do | |||
| member do | |||
| post :update_status | |||
| end | |||
| end | |||
| resources :members, :path => :collaborators, only: [:index, :create] do | |||
| collection do | |||
| delete :remove | |||
| put :change_role | |||
| end | |||
| end | |||
| resources :hooks | |||
| resources :forks, only: [:create] | |||
| resources :project_trends, :path => :activity, only: [:index, :create] | |||
| resources :issue_tags, :path => :labels, only: [:create, :edit, :update, :destroy, :index] | |||
| resources :version_releases, :path => :releases, only: [:index,:new, :create, :edit, :update, :destroy] | |||
| scope module: :projects do | |||
| scope do | |||
| get( | |||
| '/blob/*id/diff', | |||
| to: 'blob#diff', | |||
| constraints: { id: /.+/, format: false }, | |||
| as: :blob_diff | |||
| ) | |||
| get( | |||
| '/blob/*id', | |||
| to: 'blob#show', | |||
| constraints: { id: /.+/, format: false }, | |||
| as: :blob | |||
| ) | |||
| delete( | |||
| '/blob/*id', | |||
| to: 'blob#destroy', | |||
| constraints: { id: /.+/, format: false } | |||
| ) | |||
| put( | |||
| '/blob/*id', | |||
| to: 'blob#update', | |||
| constraints: { id: /.+/, format: false } | |||
| ) | |||
| post( | |||
| '/blob/*id', | |||
| to: 'blob#create', | |||
| constraints: { id: /.+/, format: false } | |||
| ) | |||
| end | |||
| scope do | |||
| get( | |||
| '/raw/*id', | |||
| to: 'raw#show', | |||
| constraints: { id: /.+/, format: /(html|js)/ }, | |||
| as: :raw | |||
| ) | |||
| end | |||
| scope do | |||
| get( | |||
| '/blame/*id', | |||
| to: 'blame#show', | |||
| constraints: { id: /.+/, format: /(html|js)/ }, | |||
| as: :blame | |||
| ) | |||
| end | |||
| scope do | |||
| get( | |||
| '/tree/*id', | |||
| to: 'tree#show', | |||
| constraints: { id: /.+/, format: /(html|js)/ }, | |||
| as: :tree | |||
| ) | |||
| end | |||
| end | |||
| end | |||
| # Project Area END | |||
| end | |||
| namespace :admins do | |||
| @@ -687,4 +652,6 @@ Rails.application.routes.draw do | |||
| ## react用 | |||
| get '*path', to: 'main#index', constraints: ReactConstraint.new | |||
| end | |||
| @@ -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; | |||
| } | |||