backlogs / redmine_backlogs

A Redmine plugin for agile teams
https://backlogs.github.io/www/
GNU General Public License v2.0
773 stars 460 forks source link

"Blocked by" rule overloaded #1093

Closed phoebusnetto closed 9 years ago

phoebusnetto commented 9 years ago

When i create any task that blocks some other I can move "blocked" task on Backlog TaskBoard to Closed status.

By default, closing a task "blocked by" another task is forbidden (see relation issues), but Backlogs plugin ignores that rule.

phoebusnetto commented 9 years ago

Common workflow works fine, i.e, if I try to close one task by Editing that task and if it have one or more task blocking the main task I cannot close the main task.

surick1 commented 9 years ago

To solve this issue: 1. We changed update_with_relationships method in [Redmine Root]/plugins/redmine_backlogs/app/models/rb_task.rb as follows:

      def update_with_relationships(params, is_impediment = false)
        time_entry_add(params)

        raise "You Are Trying To Close Issue Which Blocked By Impediment !!!" if blocked? && (params[:status_id].to_i == 5)

        attribs = RbTask.rb_safe_attributes(params)

        # Auto assign task to current user when
        # 1. the task is not assigned to anyone yet
        # 2. task status changed (i.e. Updating task name or remaining hours won't assign task to user)
        # Can be enabled/disabled in setting page
        if Backlogs.setting[:auto_assign_task] && self.assigned_to_id.blank? && (self.status_id != params[:status_id].to_i)
          attribs[:assigned_to_id] = User.current.id
        end

        valid_relationships = if is_impediment && params[:blocks] #if blocks param was not sent, that means the impediment was just dragged
                                validate_blocks_list(params[:blocks])
                              else
                                true
                              end

        if valid_relationships && result = self.journalized_update_attributes!(attribs)
          move_before params[:next] unless is_impediment # impediments are not hosted under a single parent, so you can't tree-order them
          update_blocked_list params[:blocks].split(/\D+/) if params[:blocks]

          if params.has_key?(:remaining_hours)
            begin
              self.remaining_hours = Float(params[:remaining_hours].to_s.gsub(',', '.'))
            rescue ArgumentError, TypeError
              Rails.logger.warn "#{params[:remaining_hours]} is wrong format for remaining hours." 
            end
            sprint_start = self.story.fixed_version.becomes(RbSprint).sprint_start_date if self.story
            self.estimated_hours = self.remaining_hours if (sprint_start == nil) || (Date.today < sprint_start)
            save
          end

          result
        else
          false
        end
      end
We added the line
raise "You Are Trying To Close Issue Which Blocked By Impediment !!!" if blocked? && (params[:status_id].to_i == 5)

2. We changed update method in [Redmine Root]/plugins/redmine_backlogs/app/controllers/rb_tasks_controller.rb as follows:

      def update
        @task = RbTask.find_by_id(params[:id])
        @settings = Backlogs.settings
        begin
          result = @task.update_with_relationships(params)
        rescue => e
          render :text => e.message.blank? ? e.to_s : e.message, :status => 400
          return
        end
        status = (result ? 200 : 400)
        @include_meta = true

        @task.story.story_follow_task_state if @task.story

        respond_to do |format|
          format.html { render :partial => "task", :object => @task, :status => status }
        end
      end
We added the lines
      begin
and
      rescue => e
        render :text => e.message.blank? ? e.to_s : e.message, :status => 400
        return
      end
After these changes the user shouldn't be able to change task status to closed from taskboard if it has blocked tasks.

Tested on: Environment: Redmine version 2.5.3.stable Ruby version 1.9.3 Rails version 3.2.19

phoebusnetto commented 9 years ago

Thank you!

I'll test. I'm using Redmine 2.6.3.