OSDN Git Service

data locking for issues
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 9 Sep 2006 16:07:02 +0000 (16:07 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 9 Sep 2006 16:07:02 +0000 (16:07 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@23 e93f8b46-1217-0410-a6f0-8f06a7374b81

redmine/app/controllers/issues_controller.rb
redmine/app/views/issues/change_status.rhtml
redmine/app/views/issues/edit.rhtml
redmine/app/views/issues/show.rhtml
redmine/db/migrate/001_setup.rb
redmine/lang/de.yml
redmine/lang/en.yml
redmine/lang/es.yml
redmine/lang/fr.yml

index 07f2c77..9452995 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
 \r
 class IssuesController < ApplicationController\r
-       layout 'base'\r
-       before_filter :find_project, :authorize\r
+  layout 'base'\r
+  before_filter :find_project, :authorize\r
 \r
-       helper :custom_fields\r
-       include CustomFieldsHelper\r
-       
-       def show
-    @status_options = @issue.status.workflows.find(:all, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } if self.logged_in_user\r
+  helper :custom_fields\r
+  include CustomFieldsHelper\r
+
+  def show
+    @status_options = @issue.status.workflows.find(:all, :include => :new_status, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } if self.logged_in_user\r
     @custom_values = @issue.custom_values.find(:all, :include => :custom_field)\r
-       end
+  end
 
-       def edit\r
-               @priorities = Enumeration::get_values('IPRI')\r
-               \r
-               if request.get?\r
-                       @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) }\r
-               else\r
-                       # Retrieve custom fields and values\r
-                       @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }\r
-                       @issue.custom_values = @custom_values\r
-                       @issue.attributes = params[:issue]\r
-                       if @issue.save
-                               flash[:notice] = l(:notice_successful_update)\r
-                               redirect_to :action => 'show', :id => @issue
-                       end\r
-               end             
-       end\r
-       \r
-       def change_status\r
-               @history = @issue.histories.build(params[:history])     \r
+  def edit\r
+    @priorities = Enumeration::get_values('IPRI')\r
+    if request.get?\r
+      @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) }\r
+    else\r
+      begin\r
+        # Retrieve custom fields and values\r
+        @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }\r
+        @issue.custom_values = @custom_values\r
+        @issue.attributes = params[:issue]\r
+        if @issue.save
+          flash[:notice] = l(:notice_successful_update)\r
+          redirect_to :action => 'show', :id => @issue
+        end\r
+      rescue ActiveRecord::StaleObjectError\r
+        # Optimistic locking exception\r
+        flash[:notice] = l(:notice_locking_conflict)\r
+      end\r
+    end                
+  end\r
+\r
+  def change_status\r
+    @history = @issue.histories.build(params[:history])        \r
     @status_options = @issue.status.workflows.find(:all, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } if self.logged_in_user\r
-               \r
-               if params[:confirm]\r
-                               @history.author_id = self.logged_in_user.id if self.logged_in_user\r
-       \r
-                       if @history.save                        \r
-                               @issue.status = @history.status\r
-                               @issue.fixed_version_id = (params[:issue][:fixed_version_id])\r
-                               @issue.assigned_to_id = (params[:issue][:assigned_to_id])       \r
-                               if @issue.save\r
-                                       flash[:notice] = l(:notice_successful_update)\r
-                                       Mailer.deliver_issue_change_status(@issue) if Permission.find_by_controller_and_action(@params[:controller], @params[:action]).mail_enabled?\r
-                                       redirect_to :action => 'show', :id => @issue\r
-                               end
-                       end\r
-               end    \r
+    if params[:confirm]\r
+      begin\r
+        @history.author_id = self.logged_in_user.id if self.logged_in_user\r
+        @issue.status = @history.status\r
+        @issue.fixed_version_id = (params[:issue][:fixed_version_id])\r
+        @issue.assigned_to_id = (params[:issue][:assigned_to_id])\r
+        @issue.lock_version = (params[:issue][:lock_version])\r
+        if @issue.save\r
+          flash[:notice] = l(:notice_successful_update)\r
+          Mailer.deliver_issue_change_status(@issue) if Permission.find_by_controller_and_action(@params[:controller], @params[:action]).mail_enabled?\r
+          redirect_to :action => 'show', :id => @issue\r
+        end\r
+      rescue ActiveRecord::StaleObjectError\r
+        # Optimistic locking exception\r
+        flash[:notice] = l(:notice_locking_conflict)\r
+      end\r
+    end    \r
     @assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user }\r
-    
-       end
-       
-       def destroy
-               @issue.destroy
-               redirect_to :controller => 'projects', :action => 'list_issues', :id => @project
-       end\r
-  \r
+  end
+
+  def destroy
+    @issue.destroy
+    redirect_to :controller => 'projects', :action => 'list_issues', :id => @project
+  end\r
+\r
   def add_attachment\r
     # Save the attachment\r
     if params[:attachment][:file].size > 0\r
@@ -94,7 +99,7 @@ class IssuesController < ApplicationController
 \r
 private\r
   def find_project\r
-    @issue = Issue.find(params[:id])\r
+    @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])\r
     @project = @issue.project\r
   end  
 end
index 9c14bdb..e525de6 100644 (file)
@@ -24,6 +24,7 @@
 <p><label for="history_notes"><%=l(:field_notes)%></label>\r
 <%= text_area 'history', 'notes', :cols => 60, :rows => 10  %></p>\r
 </div>
-\r
+
+<%= hidden_field 'issue', 'lock_version' %>
 <%= submit_tag l(:button_save) %>\r
 <%= end_form_tag %>\r
index 5a118f8..13f9e43 100644 (file)
@@ -21,6 +21,6 @@
 </select></p>
 <!--[eoform:issue]-->
 </div>
-
+<%= f.hidden_field :lock_version %>
 <%= submit_tag l(:button_save) %>
 <% end %>
\ No newline at end of file
index acba6af..fc48e47 100644 (file)
@@ -49,7 +49,7 @@
 <div class="box">\r
 <h3><%=l(:label_history)%></h3>\r
 <table width="100%">\r
-<% for history in @issue.histories.find(:all, :include => :author) %>\r
+<% for history in @issue.histories.find(:all, :include => [:author, :status]) %>\r
 <tr>\r
 <td><%= format_date(history.created_on) %></td>\r
 <td><%= history.author.display_name %></td>\r
index 65fd234..00d788b 100644 (file)
@@ -120,7 +120,8 @@ class Setup < ActiveRecord::Migration
       t.column "assigned_to_id", :integer\r
       t.column "priority_id", :integer, :default => 0, :null => false\r
       t.column "fixed_version_id", :integer\r
-      t.column "author_id", :integer, :default => 0, :null => false\r
+      t.column "author_id", :integer, :default => 0, :null => false
+      t.column "lock_version", :integer, :default => 0, :null => false\r
       t.column "created_on", :timestamp\r
       t.column "updated_on", :timestamp\r
     end\r
index cdfffab..7fcecca 100644 (file)
@@ -58,6 +58,7 @@ notice_successful_update: Erfolgreiches Update.
 notice_successful_delete: Erfolgreiche Auslassung.\r
 notice_successful_connection: Erfolgreicher Anschluß.\r
 notice_file_not_found: Erbetene Akte besteht nicht oder ist gelöscht worden.\r
+notice_locking_conflict: Data have been updated by another user.\r
 \r
 gui_validation_error: 1 Störung\r
 gui_validation_error_plural: %d Störungen\r
index 7fd8063..780d06c 100644 (file)
@@ -58,6 +58,7 @@ notice_successful_update: Successful update.
 notice_successful_delete: Successful deletion.\r
 notice_successful_connection: Successful connection.\r
 notice_file_not_found: Requested file doesn't exist or has been deleted.\r
+notice_locking_conflict: Data have been updated by another user.\r
 \r
 gui_validation_error: 1 error\r
 gui_validation_error_plural: %d errors\r
index a9806b3..85d78d3 100644 (file)
@@ -58,6 +58,7 @@ notice_successful_update: Successful update.
 notice_successful_delete: Successful deletion.\r
 notice_successful_connection: Successful connection.\r
 notice_file_not_found: Requested file doesn't exist or has been deleted.\r
+notice_locking_conflict: Data have been updated by another user.\r
 \r
 gui_validation_error: 1 error\r
 gui_validation_error_plural: %d errores\r
index 5c29368..a321b7d 100644 (file)
@@ -58,6 +58,7 @@ notice_successful_update: Mise à jour effectuée avec succès.
 notice_successful_delete: Suppression effectuée avec succès.\r
 notice_successful_connection: Connection réussie.\r
 notice_file_not_found: Le fichier demandé n'existe pas ou a été supprimé.\r
+notice_locking_conflict: Les données ont été mises à jour par un autre utilisateur. Mise à jour impossible.\r
 \r
 gui_validation_error: 1 erreur\r
 gui_validation_error_plural: %d erreurs\r