Просмотр исходного кода

Merge branch 'master' of https://github.com/mephi-ut/redmine_requireattachment

Dmitry Yu Okunev лет назад: 8
Родитель
Сommit
3229cf0519

+ 10 - 0
app/views/requireattachment/_settings.html.erb

@@ -0,0 +1,10 @@
+<fieldset>
+  <legend><%= l(:requireattacment_settings) %></legend>
+  <p>
+    <%= l(:field_requireattachment_forbidstatuses) %>:
+    <% IssueStatus.all.each do |status| %>
+      <br><%= check_box_tag "settings[requireattachment_forbidstatus_#{status.id.to_s}]", 1, @settings["requireattachment_forbidstatus_#{status.id.to_s}"] %><%= status.name %>
+    <% end %>
+  </p>
+</fieldset>
+

+ 2 - 0
config/locales/ru.yml

@@ -2,3 +2,5 @@
 ru:
   project_module_requireattachment: "Требовать вложение для закрытия задачи"
   issue_requires_attachment: "Перед закрытием необходимо добавить хотя бы одно вложение"
+  requireattacment_settings: "Настройки"
+  field_requireattachment_forbidstatuses: "Запретить переход на следующие статусы"

+ 2 - 0
init.rb

@@ -9,6 +9,8 @@ Redmine::Plugin.register :redmine_requireattachment do
   author 'Dmitry Yu Okunev'
   description "Plugin adds role-based permission to control who can close issues without any attachment. Yes, it's very specific use case."
   version '0.1'
+  settings :default => {}, :partial => 'requireattachment/settings'
+
   project_module :requireattachment do
     permission :close_without_attachment, :projects => :close_without_attachment
   end

+ 1 - 1
lib/requireattachment/patches/issue.rb

@@ -42,7 +42,7 @@ module Requireattachment
 			def new_statuses_allowed_to_with_requireattachment(user=User.current, include_default=false, force_has_attachments=false)
 				@statuses_allowed_to = new_statuses_allowed_to_without_requireattachment(user, include_default)
 				return @statuses_allowed_to if can_close_check_attachment(user, force_has_attachments)
-				return @statuses_allowed_to.reject {|s| s.is_closed}
+				return @statuses_allowed_to.reject {|s| status.id != s.id and (s.is_closed or not Setting.plugin_redmine_requireattachment["requireattachment_forbidstatus_#{s.id.to_s}"].nil?) }
 			end
 		end
 	end

+ 2 - 2
lib/requireattachment/patches/issues_controller.rb

@@ -28,10 +28,10 @@ module Requireattachment
 				# If can close without attachment then close
 				return update_without_requireattachment if can_close_check_attachment
 
-				# Checking if it is issues closing event. Otherwise just run the old method
+				# Checking if it is issues closing event or it's a forbidded issue status via the plugins settings. Otherwise just run the old method
 				@oldstatus = @issue.status
 				@newstatus = IssueStatus.find(params[:issue][:status_id])
-				return update_without_requireattachment unless @oldstatus.is_closed == false and @newstatus.is_closed = true
+				return update_without_requireattachment unless (@oldstatus.is_closed == false and @newstatus.is_closed == true) or not Setting.plugin_redmine_requireattachment["requireattachment_forbidstatus_#{@newstatus.id.to_s}"].nil?
 
 				# If not then it's time to disappoint the user and tell him to make an attachment
 				#@issue.errors.add :attachments, :issue_requires_attachment