| @@ -0,0 +1,59 @@ | |||
| class Api::Pm::BaseController < ApplicationController | |||
| include Api::ProjectHelper | |||
| include Api::UserHelper | |||
| include Api::PullHelper | |||
| # before_action :doorkeeper_authorize! | |||
| # skip_before_action :user_setup | |||
| protected | |||
| def kaminary_select_paginate(relation) | |||
| limit = params[:limit] || params[:per_page] | |||
| limit = (limit.to_i.zero? || limit.to_i > 200) ? 200 : limit.to_i | |||
| page = params[:page].to_i.zero? ? 1 : params[:page].to_i | |||
| relation.page(page).per(limit) | |||
| end | |||
| def limit | |||
| params.fetch(:limit, 15) | |||
| end | |||
| def page | |||
| params.fetch(:page, 1) | |||
| end | |||
| def load_project | |||
| @project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm', is_public:true) | |||
| end | |||
| def load_issue | |||
| @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) | |||
| render_not_found('疑修不存在!') if @issue.blank? | |||
| end | |||
| # 具有对仓库的管理权限 | |||
| def require_manager_above | |||
| @project = load_project | |||
| return render_forbidden if !current_user.admin? && !@project.manager?(current_user) | |||
| end | |||
| # 具有对仓库的操作权限 | |||
| def require_operate_above | |||
| @project = load_project | |||
| return render_forbidden if !current_user.admin? && !@project.operator?(current_user) | |||
| end | |||
| # 具有仓库的操作权限或者fork仓库的操作权限 | |||
| def require_operate_above_or_fork_project | |||
| @project = load_project | |||
| return render_forbidden if !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user)) | |||
| end | |||
| # 具有对仓库的访问权限 | |||
| def require_public_and_member_above | |||
| @project = load_project | |||
| return render_forbidden if !@project.is_public && !current_user.admin? && !@project.member?(current_user) | |||
| end | |||
| end | |||
| @@ -1,8 +1,11 @@ | |||
| class Api::Pm::IssuesController < ApplicationController | |||
| class Api::Pm::IssuesController < Api::Pm::BaseController | |||
| before_action :require_login, except: [:index] | |||
| before_action :load_issue, only: [:show, :children, :update, :destroy] | |||
| before_action :load_project | |||
| before_action :load_issue, only: %i[show update destroy] | |||
| before_action :load_issues, only: [:batch_update, :batch_destroy] | |||
| before_action :check_issue_operate_permission, only: [:update, :destroy] | |||
| def index | |||
| @project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm') | |||
| @object_result = Api::V1::Issues::ListService.call(@project, query_params, current_user) | |||
| @total_issues_count = @object_result[:total_issues_count] | |||
| @opened_issues_count = @object_result[:opened_issues_count] | |||
| @@ -13,22 +16,64 @@ class Api::Pm::IssuesController < ApplicationController | |||
| else | |||
| @issues = kaminari_paginate(@object_result[:data]) | |||
| end | |||
| render "api/v1/issues/index" | |||
| render 'api/v1/issues/index' | |||
| end | |||
| def show | |||
| @issue.associate_attachment_container | |||
| render "api/v1/issues/show" | |||
| render 'api/v1/issues/show' | |||
| end | |||
| def create | |||
| project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm') | |||
| @object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user) | |||
| render "api/v1/issues/create" | |||
| @object_result = Api::V1::Issues::CreateService.call(@project, issue_params, current_user) | |||
| render 'api/v1/issues/create' | |||
| end | |||
| def update | |||
| @object_result = Api::V1::Issues::UpdateService.call(@project, @issue, issue_params, current_user) | |||
| render 'api/v1/issues/update' | |||
| end | |||
| def batch_update | |||
| @object_result = Api::V1::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user) | |||
| if @object_result | |||
| render_ok | |||
| else | |||
| render_error('批量更新疑修失败!') | |||
| end | |||
| end | |||
| def batch_destroy | |||
| @object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user) | |||
| if @object_result | |||
| render_ok | |||
| else | |||
| render_error('批量删除疑修失败!') | |||
| end | |||
| end | |||
| def priorities | |||
| @priorities = IssuePriority.order(position: :asc) | |||
| @priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword] | |||
| @priorities = kaminary_select_paginate(@priorities) | |||
| render "api/v1/issues/issue_priorities/index" | |||
| end | |||
| def tags | |||
| @issue_tags = IssueTag.init_mp_issues_tags | |||
| render_ok(@issue_tags) | |||
| end | |||
| def statues | |||
| @statues = IssueStatus.order("position asc") | |||
| @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? | |||
| @statues = kaminary_select_paginate(@statues) | |||
| render "api/v1/issues/statues/index" | |||
| end | |||
| def pm_index | |||
| @issue_tags = IssueTag.init_mp_issues_tags | |||
| render_ok(@issue_tags) | |||
| end | |||
| def destroy | |||
| @@ -39,15 +84,30 @@ class Api::Pm::IssuesController < ApplicationController | |||
| render_error('删除疑修失败!') | |||
| end | |||
| end | |||
| private | |||
| def check_issue_operate_permission | |||
| return if params[:project_id].zero? | |||
| render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user | |||
| end | |||
| def load_issue | |||
| @project = Project.new(id: params[:project_id], user_id: 0, name: 'pm_mm', identifier: 'pm_mm') | |||
| @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id], pm_sprint_id:params[:pm_sprint_id]).find_by_id(params[:id]) | |||
| if @issue.blank? | |||
| render_not_found("疑修不存在!") | |||
| @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) | |||
| render_not_found('疑修不存在!') if @issue.blank? | |||
| end | |||
| def load_issues | |||
| return render_error('请输入正确的ID数组!') unless params[:ids].is_a?(Array) | |||
| params[:ids].each do |id| | |||
| @issue = Issue.find_by(id: id, pm_project_id: params[:pm_project_id]) | |||
| if @issue.blank? | |||
| return render_not_found("ID为#{id}的疑修不存在!") | |||
| end | |||
| end | |||
| @issues = Issue.where(id: params[:ids], pm_project_id: params[:pm_project_id]) | |||
| end | |||
| def query_params | |||
| params.permit( | |||
| :only_name, | |||
| @@ -0,0 +1,57 @@ | |||
| class Api::Pm::JournalsController < Api::Pm::BaseController | |||
| before_action :require_login, except: [:index, :children_journals] | |||
| before_action :load_project | |||
| before_action :load_issue | |||
| before_action :load_journal, only: [:children_journals, :update, :destroy] | |||
| def index | |||
| @object_result = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user) | |||
| @total_journals_count = @object_result[:total_journals_count] | |||
| @total_operate_journals_count = @object_result[:total_operate_journals_count] | |||
| @total_comment_journals_count = @object_result[:total_comment_journals_count] | |||
| @journals = kaminary_select_paginate(@object_result[:data]) | |||
| end | |||
| def create | |||
| @object_result = Api::V1::Issues::Journals::CreateService.call(@issue, journal_params, current_user) | |||
| end | |||
| def children_journals | |||
| @object_results = Api::V1::Issues::Journals::ChildrenListService.call(@issue, @journal, query_params, current_user) | |||
| @journals = kaminari_paginate(@object_results) | |||
| end | |||
| def update | |||
| @object_result = Api::V1::Issues::Journals::UpdateService.call(@issue, @journal, journal_params, current_user) | |||
| end | |||
| def destroy | |||
| TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!)) | |||
| if @journal.destroy! | |||
| render_ok | |||
| else | |||
| render_error('删除评论失败!') | |||
| end | |||
| end | |||
| private | |||
| def query_params | |||
| params.permit(:category, :keyword, :sort_by, :sort_direction) | |||
| end | |||
| def journal_params | |||
| params.permit(:notes, :parent_id, :reply_id, :attachment_ids => [], :receivers_login => []) | |||
| end | |||
| def load_issue | |||
| @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:issue_id]) | |||
| render_not_found('疑修不存在!') if @issue.blank? | |||
| end | |||
| def load_journal | |||
| @journal = Journal.find_by_id(params[:id]) | |||
| render_not_found('评论不存在!') unless @journal.present? | |||
| end | |||
| end | |||
| @@ -57,7 +57,7 @@ class Api::V1::BaseController < ApplicationController | |||
| # 具有对仓库的访问权限 | |||
| def require_public_and_member_above | |||
| @project = load_project | |||
| @project = load_project | |||
| return render_forbidden if !@project.is_public && !current_user.admin? && !@project.member?(current_user) | |||
| end | |||
| end | |||
| @@ -7,12 +7,4 @@ class Api::V1::Issues::IssuePrioritiesController < Api::V1::BaseController | |||
| @priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword] | |||
| @priorities = kaminary_select_paginate(@priorities) | |||
| end | |||
| def pm_index | |||
| @priorities = IssuePriority.order(position: :asc) | |||
| @priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword] | |||
| @priorities = kaminary_select_paginate(@priorities) | |||
| render "index" | |||
| end | |||
| end | |||
| @@ -13,12 +13,7 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController | |||
| end | |||
| end | |||
| def pm_index | |||
| @issue_tags = IssueTag.init_mp_issues_tags | |||
| render_ok(@issue_tags) | |||
| end | |||
| def create | |||
| def create | |||
| @issue_tag = @project.issue_tags.new(issue_tag_params) | |||
| if @issue_tag.save! | |||
| render_ok | |||
| @@ -8,11 +8,4 @@ class Api::V1::Issues::StatuesController < Api::V1::BaseController | |||
| @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? | |||
| @statues = kaminary_select_paginate(@statues) | |||
| end | |||
| def pm_index | |||
| @statues = IssueStatus.order("position asc") | |||
| @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? | |||
| @statues = kaminary_select_paginate(@statues) | |||
| render "index" | |||
| end | |||
| end | |||
| @@ -1,4 +1,4 @@ | |||
| json.total_count @priorities.total_count | |||
| json.priorities @priorities.each do |priority| | |||
| json.partial! "simple_detail", locals: {priority: priority} | |||
| json.partial! "api/v1/issues/issue_priorities/simple_detail", locals: {priority: priority} | |||
| end | |||
| @@ -1,8 +1,8 @@ | |||
| json.total_count @issue_tags.total_count | |||
| json.issue_tags @issue_tags.each do |tag| | |||
| if params[:only_name] | |||
| json.partial! "simple_detail", locals: {tag: tag} | |||
| json.partial! "api/v1/issues/issue_tags/simple_detail", locals: {tag: tag} | |||
| else | |||
| json.partial! "detail", locals: {tag: tag} | |||
| json.partial! "api/v1/issues/issue_tags/detail", locals: {tag: tag} | |||
| end | |||
| end | |||
| @@ -1,4 +1,4 @@ | |||
| json.total_count @statues.total_count | |||
| json.statues @statues.each do |status| | |||
| json.partial! "simple_detail", locals: {status: status} | |||
| json.partial! "api/v1/issues/statues/simple_detail", locals: {status: status} | |||
| end | |||
| @@ -1,12 +1,25 @@ | |||
| defaults format: :json do | |||
| namespace :api do | |||
| namespace :pm do | |||
| resources :issues | |||
| resources :issues do | |||
| collection do | |||
| patch :batch_update | |||
| delete :batch_destroy | |||
| get :priorities | |||
| get :tags | |||
| get :statues | |||
| end | |||
| resources :journals do | |||
| member do | |||
| get :children_journals | |||
| end | |||
| end | |||
| end | |||
| end | |||
| namespace :v1 do | |||
| resources :users, only: [:index] do | |||
| resources :users, only: [:index] do | |||
| collection do | |||
| post :check_user_id | |||
| post :check_user_login | |||
| @@ -62,24 +75,12 @@ defaults format: :json do | |||
| scope module: :issues do | |||
| resources :issue_tags, except: [:new, :edit] do | |||
| collection do | |||
| get :pm_index | |||
| end | |||
| end | |||
| resources :issue_tags, except: [:new, :edit] | |||
| resources :milestones, except: [:new, :edit] | |||
| resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' do | |||
| collection do | |||
| get :pm_index | |||
| end | |||
| end | |||
| resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' | |||
| resources :issue_authors, only: [:index], controller: '/api/v1/issues/authors' | |||
| resources :issue_assigners, only: [:index], controller: '/api/v1/issues/assigners' | |||
| resources :issue_priorities, only: [:index] do | |||
| collection do | |||
| get :pm_index | |||
| end | |||
| end | |||
| resources :issue_priorities, only: [:index] | |||
| end | |||
| # projects文件夹下的 | |||