Changeset 712

Show
Ignore:
Timestamp:
11/01/07 14:01:38 (1 year ago)
Author:
markku
Message:
  • Comment open service requests - Closes #481.
  • Simplified Task#save.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/customer_interface_controller.rb

    r711 r712  
    5353    # Find timeline events that: 
    5454    # - Belong to an asset the user is authorized to view. 
    55     # - Are not only comments to tasks (customers doesn't need to see these). 
     55    # - Are not only comments created by Users to tasks (customers doesn't need to see these). 
    5656    from = 'timeline_events e' 
    5757    condition_strings = [] 
     
    6060    if TaskEvent.count > 0 
    6161      from += ', tasks t' 
    62       condition_strings.push('(e.type = ? AND e.event_type != ? AND e.task_id = t.id AND t.asset_id = assets.id)') 
    63       conditions.push('TaskEvent', TaskEvent.TYPES[:COMMENTED]
     62      condition_strings.push('(e.type = ? AND (e.event_type != ? OR e.created_by = ?) AND e.task_id = t.id AND t.asset_id = assets.id)') 
     63      conditions.push('TaskEvent', TaskEvent.TYPES[:COMMENTED], session[:user].id
    6464    end 
    6565 
     
    196196    render(:partial => 'shared/create_or_edit', 
    197197           :layout => 'customer_interface', 
    198            :locals => {:cancel_url_options => {:action => 'index'}}) 
     198           :locals => {:submit_text => _('Submit'), :cancel_url_options => {:action => 'index'}}) 
    199199  end 
    200200 
     
    242242  end 
    243243 
     244  # Method: comment_service_request 
     245  # =============================== 
     246  # Enables a customer to comment her open service request. 
     247  # 
     248  def comment_service_request 
     249    @task = Task.find(params[:id], :conditions => ['state != ?', Task.CLOSED]) 
     250    @title = _('Comment service request %s', @task.to_s) 
     251 
     252    unless @assets.include?(@task.asset) and @task.task_type and @task.task_type.is_service_request_type 
     253      flash[:error] = _('Service request %s not found!', @task.to_s) 
     254      redirect_to(:action => 'index') 
     255      return 
     256    end 
     257 
     258    if request.post? 
     259      if params[:comment] and params[:comment].strip != '' 
     260        if TaskEvent.create(:task => @task, :event_type => TaskEvent.TYPES[:COMMENTED], :comment_text => params[:comment]) 
     261          flash[:notice] = _('Comment successfully received') 
     262          redirect_to(:action => 'index') 
     263        else 
     264          flash[:error] = msg_saving_failed 
     265        end 
     266      else 
     267        flash[:notice] = _("Comment can't be empty. Please provide one.") 
     268      end 
     269    end 
     270  end 
     271 
    244272  protected 
    245273 
  • trunk/app/helpers/customer_interface_helper.rb

    r710 r712  
    2121  # include_name   - Include name of the <Asset> 
    2222  # max_code_width - Maximum width for the full code of the <Asset>. 
     23  #                  Non-positive value means infinite width. 
    2324  #                  Ignored if include_name is true. 
    2425  # 
    25   def format_asset(asset, include_name = false, max_code_width = 12
     26  def format_asset(asset, include_name = false, max_code_width = nil
    2627    return '' unless asset 
    2728 
     
    2930 
    3031    return span_tag(tag_class, '%s (%s)' % [asset.full_code, asset.name]) if include_name 
     32    return span_tag(tag_class, asset.full_code) unless max_code_width and max_code_width > 0 
    3133 
    3234    text = '' 
     
    8587  # asset_code_width - Maximum width for the full code of the <Asset>. 
    8688  #                    Ignored if show_asset_and_description is false. 
    87   # 
    88   def format_task(task, no_text = false, show_type = true, show_asset_and_description = false, asset_code_width = 10) 
     89  # show_comment_link - If true, shows a link to the 'Comment service request' 
     90  #                     function. 
     91  # 
     92  def format_task(task, no_text = false, show_type = true, show_asset_and_description = false, asset_code_width = 10, show_comment_link = false) 
    8993    return '' unless task 
    9094 
     
    9296    content = _('Task') + ' ' + content unless no_text 
    9397    content += " (#{task.task_type.name})" if show_type 
    94     result = span_tag('task', content) 
     98    result = show_comment_link ? link_to(content, {:action => 'comment_service_request', :id => task.id}, {:class => 'task', :title => _('Comment service request %s', task.to_s)}) : span_tag('task', content) 
    9599    return result unless show_asset_and_description 
    96100    result += nbsp(1) 
  • trunk/app/models/customer.rb

    r710 r712  
    3333                 'customer_interface/submit_service_request', 
    3434                 'customer_interface/edit_my_information', 
    35                  'customer_interface/change_password' 
     35                 'customer_interface/change_password', 
     36                 'customer_interface/comment_service_request' 
    3637                ] 
    3738 
  • trunk/app/models/task.rb

    r710 r712  
    107107  end 
    108108 
    109   # Arguments: 
    110   #   +create_state_change_event+:: If +true+, a new TaskEvent (representing the 
    111   #                                 change to the object's current state) is created. 
    112   def save(create_state_change_event = false) 
    113     return super() unless create_state_change_event 
     109  # Method: save 
     110  # ============ 
     111  # Saves the object. 
     112  # 
     113  # Parameters: 
     114  # ----------- 
     115  # create_event - If true, a new <TaskEvent> is created. The event 
     116  #                represents the change to the object's current state 
     117  #                (the only exception being the <COMMENTED> event) 
     118  #                and can also contain a comment text. 
     119  # 
     120  def save(create_event = false) 
     121    return super() unless create_event 
    114122 
    115123    if new_record? 
    116124      task_events << TaskEvent.new(:event_type => TaskEvent.TYPES[:CREATED], 
    117                                               :comment_text => self.short_description) 
     125                                   :comment_text => self.short_description) 
    118126      return super() 
    119127    end 
    120128 
    121     new_state = (self.state == @original_state) ? nil : self.state 
    122  
    123     case new_state 
     129    case self.state 
     130      when @original_state 
     131        # State unchanged -> comment only 
     132        if @comment and @comment != '' 
     133          @event = TaskEvent.create(:event_type => TaskEvent.TYPES[:COMMENTED], 
     134                                    :task_id => self.id, 
     135                                    :comment_text => @comment) 
     136        end 
    124137      when @@ACCEPTED 
    125138        @event = TaskEvent.create(:event_type => TaskEvent.TYPES[:ACCEPTED], 
    126                                     :task_id => self.id, 
    127                                     :comment_text => @comment) 
     139                                  :task_id => self.id, 
     140                                  :comment_text => @comment) 
    128141      when @@CLOSED 
    129142        @event = TaskEvent.create(:event_type => TaskEvent.TYPES[:CLOSED], 
    130                                     :task_id => self.id, 
    131                                     :comment_text => @comment) 
     143                                  :task_id => self.id, 
     144                                  :comment_text => @comment) 
    132145      when @@ASSIGNED 
    133146        @event = TaskEvent.create(:event_type => TaskEvent.TYPES[:ASSIGNED], 
    134                                     :task_id => self.id, 
    135                                     :comment_text => @comment, 
    136                                     :task_owner => self.responsible_user) 
     147                                  :task_id => self.id, 
     148                                  :comment_text => @comment, 
     149                                  :task_owner => self.responsible_user) 
    137150        _('Task was assigned to you') # This is to trigger the gettext 
    138151        @message = Message.create(:receiver => self.responsible_user, 
     
    141154      when @@NEW 
    142155        @event = TaskEvent.create(:event_type => TaskEvent.TYPES[:REOPENED], 
    143                                     :task_id => self.id, 
    144                                     :comment_text => @comment) 
    145       when nil # State unchanged 
    146         if @comment and @comment != '' 
    147           @event = TaskEvent.create(:event_type => TaskEvent.TYPES[:COMMENTED], 
    148                                       :task_id => self.id, 
    149                                       :comment_text => @comment) 
    150         end 
     156                                  :task_id => self.id, 
     157                                  :comment_text => @comment) 
    151158    end 
    152159 
  • trunk/app/views/customer_interface/_item_list.rhtml

    r710 r712  
    1818  # table_id     - id attribute for the table containing the items 
    1919  # asset_code_width - Width for the full code of an asset 
     20  # show_comment_task_link - Show 'Comment task' link for task items 
    2021  # 
    2122  # Optional instance variables: 
     
    4647    table_id ||= 'itemlist' 
    4748    asset_code_width ||= 10 
     49    show_comment_task_link ||= false 
    4850  -%> 
    4951  <!-- The item list --> 
     
    9799                  format_attachment_event(value) 
    98100                when 'Task' 
    99                   format_task(value, true, false, true, asset_code_width
     101                  format_task(value, true, false, true, asset_code_width, show_comment_task_link
    100102                when 'User' 
    101103                  format_user(value, true) 
  • trunk/app/views/customer_interface/index.rhtml

    r710 r712  
    3333                            :items_offset => @service_request_offset, 
    3434                            :table_id => 'service_request_list', 
    35                             :asset_code_width => 12 }) %> 
     35                            :asset_code_width => 12, 
     36                            :show_comment_task_link => true }) %> 
    3637  </div> 
    3738  <div id="statistics" class="boxblock"> 
  • trunk/app/views/layouts/customer_interface.rhtml

    r710 r712  
    4848 
    4949  <div id="loginstatus"> 
    50     <div id="logged"><%= _('Logged in as') %>:&nbsp;<%= @show_login_name_link ? link_to(h(session[:user].login_and_name), {:action => 'edit_my_information'}, {:id => 'login_name'}) : "<span class=\"login_name\">#{h(session[:user].login_and_name)}</span>" %></div> 
     50    <div id="logged"><%= _('Logged in as') %>:&nbsp;<%= @show_login_name_link ? link_to(h(session[:user].login_and_name), {:action => 'edit_my_information'}, {:id => 'login_name', :title => _('My information')}) : "<span id=\"login_name\">#{h(session[:user].login_and_name)}</span>" %></div> 
    5151    <div id="logbutton"><%= link_to( image_tag('customer_interface/logout.jpg'), {:controller => 'user', :action => 'logout'} ) %></div> 
    5252  </div> 
  • trunk/db/migrate/010_customer_interface_data.rb

    r710 r712  
    1414     'customer_interface/submit_service_request', 
    1515     'customer_interface/edit_my_information', 
    16      'customer_interface/change_password' 
     16     'customer_interface/change_password', 
     17     'customer_interface/comment_service_request' 
    1718    ].each { |name| 
    1819      TempActionKey.create!(:name => name) 
  • trunk/doc/manual/latex/tex/customer_interface.tex

    r711 r712  
    66\item Submit service requests 
    77\item View and follow their open service request 
    8 %\item Comment open service requests 
     8\item Comment open service requests 
    99\item View statistics: Open service requests by asset 
    1010\end{itemize} 
     
    2020\subsubsection{Submit a service request} 
    2121Customers can submit service requests with this function. The service request will show up in the service request list in the Tasks menu found from the Application section. If a customer doesn't select an asset for the a service request, the service request will be saved to the customer's first asset --- You can move it to another asset if you wish. 
     22\subsubsection{Comment service request} 
     23An open Service request can be commented by  
    2224\subsubsection{My information} 
    2325Customers can view and edit their contact information and language by clicking the account name link after the 'Logged in as:' text at the top of the page.  Changes to the account information can be saved with the 'Save changes' button. 
  • trunk/public/stylesheets/customer_interface_timeline.css

    r710 r712  
    88} 
    99 
    10 span.task
     10span.task, a.task
    1111        padding-left: 20px; 
    1212        background: transparent url(../images/16x16/timeline_task.gif) 0px 0px no-repeat; 
  • trunk/test/functional/customer_interface_controller_test.rb

    r710 r712  
    189189  # Method: test_submit_service_request 
    190190  # =================================== 
    191   # Check that service request submitting works when asset is given. 
     191  # Check that service request submitting works when required input (including asset) is given. 
    192192  # 
    193193  def test_submit_service_request 
     
    280280  end 
    281281 
     282  # Method: test_comment_service_request 
     283  # =================================== 
     284  # Checks that the service request commenting function works with valid input. 
     285  # 
     286  def test_comment_service_request 
     287    service_request = create_simple_task(@asset1, @service_request_type) 
     288 
     289    login(@customer.login) 
     290 
     291    # GET form 
     292    get 'comment_service_request', :id => service_request.id 
     293    assert_response :success 
     294    assert_template 'customer_interface/comment_service_request' 
     295    assert_equal service_request, assigns(:task) 
     296    assert_nil flash[:error] 
     297    assert_nil flash[:notice] 
     298 
     299    # POST form 
     300    comment = 'This is the comment we want to submit to the open service request' 
     301    post 'comment_service_request', :id => service_request.id, :comment => comment 
     302    assert_redirected_to :action => 'index' 
     303    assert_nil flash[:error] 
     304    assert_not_nil flash[:notice] 
     305    assert_equal service_request, assigns(:task) 
     306    comment_event = assigns(:task).task_events.find_by_event_type(TaskEvent.TYPES[:COMMENTED]) 
     307    assert_equal comment, comment_event.comment_text 
     308    assert_equal @customer, comment_event.creator 
     309  end 
     310 
     311  # Method: test_comment_closed_service_request 
     312  # =================================== 
     313  # Checks that closed service requests can't be commented. 
     314  # 
     315  def test_comment_closed_service_request 
     316    service_request = create_simple_task(@asset1, @service_request_type) 
     317    service_request.close 
     318    service_request.save! 
     319 
     320    login(@customer.login) 
     321 
     322    # GET form 
     323    assert_raise(ActiveRecord::RecordNotFound) { get('comment_service_request', :id => service_request.id) } 
     324 end 
     325 
     326  # Method: test_comment_service_request_unautorized_asset 
     327  # ===================================================== 
     328  # Checks that customer can't comment service request in unauthorized assets. 
     329  # 
     330  def test_comment_service_request_unautorized_asset 
     331    service_request = create_simple_task(@asset2, @service_request_type) 
     332 
     333    login(@customer.login) 
     334 
     335    # GET form 
     336    get 'comment_service_request', :id => service_request.id 
     337    assert_redirected_to :action => 'index' 
     338    assert_not_nil flash[:error] 
     339    assert_nil flash[:notice] 
     340  end 
     341 
     342  # Method: test_comment_service_request_unautorized_task 
     343  # ===================================================== 
     344  # Checks that customer can't comment tasks which aren't service requests 
     345  # 
     346  def test_comment_service_request_unautorized_task 
     347    service_request = create_simple_task(@asset1, @task_type) 
     348 
     349    login(@customer.login) 
     350 
     351    # GET form 
     352    get 'comment_service_request', :id => service_request.id 
     353    assert_redirected_to :action => 'index' 
     354    assert_not_nil flash[:error] 
     355    assert_nil flash[:notice] 
     356  end 
     357 
     358  # Method: test_comment_service_request_empty_comment 
     359  # ================================================== 
     360  # Checks that empty comments can't be submitted to the service request commenting function works with valid input. 
     361  # 
     362  def test_comment_service_request_empty_comment 
     363    service_request = create_simple_task(@asset1, @service_request_type) 
     364 
     365    login(@customer.login) 
     366 
     367    post 'comment_service_request', :id => service_request.id, :comment => '  ' 
     368    assert_response :success 
     369    assert_template 'customer_interface/comment_service_request' 
     370    assert_nil flash[:error] 
     371    assert_not_nil flash[:notice] 
     372    assert_equal service_request, assigns(:task) 
     373    assert_nil assigns(:task).task_events.find_by_event_type(TaskEvent.TYPES[:COMMENTED]) 
     374  end 
    282375 
    283376  def test_edit_my_information_get 

© 2004-2007 Norfello Oy All Rights Reserved