diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index b546ea717..e21c087bf 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -109,7 +109,7 @@ class IssuesController < ApplicationController def create issue_params = issue_send_params(params) - Issues::CreateForm.new({subject:issue_params[:subject]}).validate! + Issues::CreateForm.new(issue_params.slice(:subject, :description)).validate! @issue = Issue.new(issue_params) if @issue.save! SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if Site.has_notice_menu? @@ -223,7 +223,7 @@ class IssuesController < ApplicationController normal_status(-1, "不允许修改为关闭状态") else issue_params = issue_send_params(params).except(:issue_classify, :author_id, :project_id) - Issues::UpdateForm.new({subject:issue_params[:subject]}).validate! + Issues::UpdateForm.new(issue_params.slice(:subject, :description)).validate! if @issue.update_attributes(issue_params) if @issue&.pull_request.present? SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @issue&.pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value)) if Site.has_notice_menu? diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index 8fbe46924..2dd1fef69 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -23,6 +23,7 @@ class JournalsController < ApplicationController normal_status(-1, "评论内容不能为空") else ActiveRecord::Base.transaction do + Journals::CreateForm.new({notes: notes.to_s.strip}).validate! journal_params = { journalized_id: @issue.id , journalized_type: "Issue", @@ -53,6 +54,9 @@ class JournalsController < ApplicationController end end end + rescue Exception => exception + puts exception.message + normal_status(-1, exception.message) end def destroy @@ -70,7 +74,8 @@ class JournalsController < ApplicationController def update content = params[:content] - if content.present? + if content.present? + Journals::UpdateForm.new({notes: notes.to_s.strip}).validate! if @journal.update_attribute(:notes, content) normal_status(0, "更新成功") else @@ -79,7 +84,9 @@ class JournalsController < ApplicationController else normal_status(-1, "评论的内容不能为空") end - + rescue Exception => exception + puts exception.message + normal_status(-1, exception.message) end def get_children_journals diff --git a/app/forms/issues/create_form.rb b/app/forms/issues/create_form.rb index 602775ff4..7ab942bc5 100644 --- a/app/forms/issues/create_form.rb +++ b/app/forms/issues/create_form.rb @@ -1,11 +1,11 @@ class Issues::CreateForm include ActiveModel::Model - attr_accessor :subject + attr_accessor :subject, :description validates :subject, presence: { message: "不能为空" } validates :subject, length: { maximum: 200, too_long: "不能超过200个字符" } - + validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"} end diff --git a/app/forms/issues/update_form.rb b/app/forms/issues/update_form.rb index 64acdfb5c..1aa971e98 100644 --- a/app/forms/issues/update_form.rb +++ b/app/forms/issues/update_form.rb @@ -1,10 +1,12 @@ class Issues::UpdateForm include ActiveModel::Model - attr_accessor :subject + attr_accessor :subject, :description validates :subject, presence: { message: "不能为空" } validates :subject, length: { maximum: 200, too_long: "不能超过200个字符" } + validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"} + end \ No newline at end of file diff --git a/app/forms/journals/create_form.rb b/app/forms/journals/create_form.rb new file mode 100644 index 000000000..8b96bc642 --- /dev/null +++ b/app/forms/journals/create_form.rb @@ -0,0 +1,7 @@ +class Journals::CreateForm + include ActiveModel::Model + + attr_accessor :notes + + validates :notes, length: { maximum: 65535, too_long: "不能超过65535个字符"} +end diff --git a/app/forms/journals/update_form.rb b/app/forms/journals/update_form.rb new file mode 100644 index 000000000..74f8fa6f4 --- /dev/null +++ b/app/forms/journals/update_form.rb @@ -0,0 +1,8 @@ +class Journals::UpdateForm + include ActiveModel::Model + + attr_accessor :notes + + validates :notes, length: { maximum: 65535, too_long: "不能超过65535个字符"} + +end \ No newline at end of file diff --git a/app/models/fork_user.rb b/app/models/fork_user.rb index bddf8f75c..4177392ee 100644 --- a/app/models/fork_user.rb +++ b/app/models/fork_user.rb @@ -17,7 +17,7 @@ class ForkUser < ApplicationRecord belongs_to :project - belongs_to :user + belongs_to :owner belongs_to :fork_project, class_name: 'Project', foreign_key: :fork_project_id after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic diff --git a/app/services/pull_requests/create_service.rb b/app/services/pull_requests/create_service.rb index 703bb5de3..258d0e31b 100644 --- a/app/services/pull_requests/create_service.rb +++ b/app/services/pull_requests/create_service.rb @@ -157,7 +157,7 @@ class PullRequests::CreateService < ApplicationService raise "head参数不能为空" if @params[:head].blank? raise "base参数不能为空" if @params[:base].blank? raise "fork_project_id参数错误" if is_original && !@project.forked_projects.pluck(:id).include?(@params[:fork_project_id].to_i) - raise "merge_user_login参数错误" if is_original && @project.fork_users.joins(:user).where(users: {login: @params[:merge_user_login]}).blank? + raise "merge_user_login参数错误" if is_original && @project.fork_users.joins(:owner).where(users: {login: @params[:merge_user_login]}).blank? raise "分支内容相同,无需创建合并请求" if @params[:head] === @params[:base] && !is_original raise "合并请求已存在" if @project&.pull_requests.where(head: @params[:head], base: @params[:base], status: 0, is_original: is_original, fork_project_id: @params[:fork_project_id]).present? raise @pull_issue.errors.full_messages.join(", ") unless pull_issue.valid? diff --git a/config/locales/forms/create_issuse_form.zh-CN.yml b/config/locales/forms/create_issuse_form.zh-CN.yml index 643c68667..bebab7e22 100644 --- a/config/locales/forms/create_issuse_form.zh-CN.yml +++ b/config/locales/forms/create_issuse_form.zh-CN.yml @@ -3,5 +3,11 @@ attributes: issues/create_form: subject: 标题 + description: 描述 issues/update_form: - subject: 标题 \ No newline at end of file + subject: 标题 + description: 描述 + journals/create_form: + notes: 评论 + journals/update_form: + notes: 评论 \ No newline at end of file