Changeset 469
- Timestamp:
- 01/23/07 14:43:00 (2 years ago)
- Files:
-
- branches/workorder_report_rename/app/controllers/application.rb (modified) (3 diffs)
- branches/workorder_report_rename/app/controllers/asset_permission_controller.rb (modified) (2 diffs)
- branches/workorder_report_rename/app/controllers/asset_tree_controller.rb (modified) (1 diff)
- branches/workorder_report_rename/app/controllers/data_permission_controller.rb (modified) (3 diffs)
- branches/workorder_report_rename/app/controllers/form_controller.rb (modified) (4 diffs)
- branches/workorder_report_rename/app/controllers/overview_controller.rb (modified) (3 diffs)
- branches/workorder_report_rename/app/controllers/search_controller.rb (modified) (1 diff)
- branches/workorder_report_rename/app/controllers/timeline_controller.rb (modified) (1 diff)
- branches/workorder_report_rename/app/controllers/user_controller.rb (modified) (1 diff)
- branches/workorder_report_rename/app/helpers/application_helper.rb (modified) (3 diffs)
- branches/workorder_report_rename/app/helpers/asset_helper.rb (modified) (1 diff)
- branches/workorder_report_rename/app/models/asset.rb (modified) (8 diffs)
- branches/workorder_report_rename/app/models/asset_condition_analysis.rb (modified) (3 diffs)
- branches/workorder_report_rename/app/models/assets_user_group.rb (modified) (10 diffs)
- branches/workorder_report_rename/app/models/form.rb (modified) (1 diff)
- branches/workorder_report_rename/app/models/form_tag.rb (modified) (1 diff)
- branches/workorder_report_rename/app/models/user.rb (modified) (2 diffs)
- branches/workorder_report_rename/app/models/user_group.rb (modified) (1 diff)
- branches/workorder_report_rename/app/views/asset_permission/edit.rhtml (modified) (3 diffs)
- branches/workorder_report_rename/app/views/data_permission/edit.rhtml (modified) (1 diff)
- branches/workorder_report_rename/app/views/data_permission/preview.rhtml (modified) (1 diff)
- branches/workorder_report_rename/app/views/form/_creation_form.rhtml (modified) (1 diff)
- branches/workorder_report_rename/app/views/form/view.rhtml (modified) (2 diffs)
- branches/workorder_report_rename/app/views/overview/executive_view.rhtml (modified) (1 diff)
- branches/workorder_report_rename/app/views/shared/_list_items.rhtml (modified) (2 diffs)
- branches/workorder_report_rename/app/views/timeline/_display_event.rhtml (modified) (1 diff)
- branches/workorder_report_rename/db/migrate/021_version_one_dot_two_tables.rb (modified) (5 diffs)
- branches/workorder_report_rename/db/migrate/022_version_one_dot_two_data.rb (modified) (1 diff)
- branches/workorder_report_rename/db/migrate/023_version_one_dot_two_data_type_tags.rb (modified) (1 diff)
- branches/workorder_report_rename/lib/cmms_markup.rb (modified) (3 diffs)
- branches/workorder_report_rename/test/fixtures/action_keys.yml (modified) (2 diffs)
- branches/workorder_report_rename/test/fixtures/assets.yml (modified) (3 diffs)
- branches/workorder_report_rename/test/fixtures/assets_user_groups.yml (modified) (12 diffs)
- branches/workorder_report_rename/test/fixtures/data_permission_profiles.yml (modified) (13 diffs)
- branches/workorder_report_rename/test/fixtures/data_permissions.yml (modified) (4 diffs)
- branches/workorder_report_rename/test/fixtures/forms.yml (modified) (1 diff)
- branches/workorder_report_rename/test/fixtures/forms_work_orders.yml (modified) (1 diff)
- branches/workorder_report_rename/test/fixtures/selenium/assets_user_groups.yml (modified) (210 diffs)
- branches/workorder_report_rename/test/fixtures/selenium/data_permission_profiles.yml (modified) (130 diffs)
- branches/workorder_report_rename/test/fixtures/selenium/permissions.yml (modified) (1 diff)
- branches/workorder_report_rename/test/fixtures/selenium/work_orders.yml (modified) (10 diffs)
- branches/workorder_report_rename/test/fixtures/timeline_events.yml (modified) (4 diffs)
- branches/workorder_report_rename/test/fixtures/users.yml (modified) (1 diff)
- branches/workorder_report_rename/test/fixtures/work_order_types.yml (modified) (1 diff)
- branches/workorder_report_rename/test/fixtures/work_orders.yml (modified) (25 diffs)
- branches/workorder_report_rename/test/functional/asset_controller_test.rb (modified) (1 diff)
- branches/workorder_report_rename/test/functional/asset_permission_controller_test.rb (modified) (21 diffs)
- branches/workorder_report_rename/test/functional/attachment_controller_test.rb (modified) (1 diff)
- branches/workorder_report_rename/test/functional/data_permission_controller_test.rb (modified) (9 diffs)
- branches/workorder_report_rename/test/functional/form_controller_test.rb (modified) (1 diff)
- branches/workorder_report_rename/test/functional/search_controller_test.rb (modified) (2 diffs)
- branches/workorder_report_rename/test/functional/timeline_controller_test.rb (modified) (3 diffs)
- branches/workorder_report_rename/test/functional/user_controller_test.rb (modified) (1 diff)
- branches/workorder_report_rename/test/functional/work_order_controller_test.rb (modified) (8 diffs)
- branches/workorder_report_rename/test/functional/work_order_type_controller_test.rb (modified) (7 diffs)
- branches/workorder_report_rename/test/selenium/timeline_test.rb (modified) (1 diff)
- branches/workorder_report_rename/test/test_helper.rb (modified) (4 diffs)
- branches/workorder_report_rename/test/unit/asset_condition_analysis_test.rb (modified) (8 diffs)
- branches/workorder_report_rename/test/unit/asset_test.rb (modified) (17 diffs)
- branches/workorder_report_rename/test/unit/asset_type_test.rb (modified) (1 diff)
- branches/workorder_report_rename/test/unit/assets_user_group_test.rb (modified) (15 diffs)
- branches/workorder_report_rename/test/unit/cmms_markup_test.rb (modified) (4 diffs)
- branches/workorder_report_rename/test/unit/data_permission_profile_test.rb (modified) (15 diffs)
- branches/workorder_report_rename/test/unit/data_permission_test.rb (modified) (8 diffs)
- branches/workorder_report_rename/test/unit/protected_data_test.rb (modified) (24 diffs)
- branches/workorder_report_rename/test/unit/protected_join_model_test.rb (modified) (5 diffs)
- branches/workorder_report_rename/test/unit/work_order_template_test.rb (modified) (2 diffs)
- branches/workorder_report_rename/test/unit/work_order_test.rb (modified) (8 diffs)
- branches/workorder_report_rename/test/unit/work_order_type_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/workorder_report_rename/app/controllers/application.rb
r464 r469 83 83 protected_page_group :asset_edit, 'asset', ['edit'], 'edit_protector' 84 84 protected_page_group :asset_change_type, 'asset', ['change_type'], 'change_type_protector' 85 protected_page_group : work_order_edit, 'work_order', ['edit'], 'edit_protector'85 protected_page_group :task_edit, 'task', ['edit'], 'edit_protector' 86 86 protected_page_group :form_edit, 'form', ['edit'], 'edit_protector' 87 87 protected_page_group :form_type_wizard, 'form_type', [ 'create_step1', … … 300 300 # Matches for the base of the url 301 301 form_url_match = url_for(:controller => 'form', :action => 'view') 302 work_order_url_match = url_for(:controller => 'work_order', :action => 'view')302 task_url_match = url_for(:controller => 'task', :action => 'view') 303 303 attachment_url_match = url_for(:controller => 'attachment', :action => 'view') 304 304 type_attachment_url_match = url_for(:controller => 'type_attachment', :action => 'view') … … 311 311 output = text.gsub(/#{form_url_match}\/#{params_match}/) { |m| "[#{$~[1]}]" } 312 312 # Work orders 313 output = output.gsub(/#{ work_order_url_match}\/#{params_match}/) { |m| "{#{$~[1]}}" }313 output = output.gsub(/#{task_url_match}\/#{params_match}/) { |m| "{#{$~[1]}}" } 314 314 # Attachments 315 315 output = output.gsub(/#{attachment_url_match}\/#{params_match}/) { |m| "<#{$~[1]}>" } branches/workorder_report_rename/app/controllers/asset_permission_controller.rb
r455 r469 159 159 @form_available_groups = (all_user_groups - @form_permission_profiles.map {|p| p.user_group }).map {|g| [g.name, g.id] } 160 160 @form_permission_profiles << FormPermissionProfile.new(:other => true) if @form_permission_profiles.select { |profile| profile.other }.empty? 161 @ work_order_permission_profiles = @assets_user_group.work_order_permission_profiles.find(:all, :readonly => true)162 @ work_order_available_groups = (all_user_groups - @work_order_permission_profiles.map {|p| p.user_group }).map {|g| [g.name, g.id] }163 @ work_order_permission_profiles << WorkOrderPermissionProfile.new(:other => true) if @work_order_permission_profiles.select { |profile| profile.other }.empty?161 @task_permission_profiles = @assets_user_group.task_permission_profiles.find(:all, :readonly => true) 162 @task_available_groups = (all_user_groups - @task_permission_profiles.map {|p| p.user_group }).map {|g| [g.name, g.id] } 163 @task_permission_profiles << TaskPermissionProfile.new(:other => true) if @task_permission_profiles.select { |profile| profile.other }.empty? 164 164 @attachment_permission_profiles = @assets_user_group.attachment_permission_profiles.find(:all, :readonly => true) 165 165 @attachment_available_groups = (all_user_groups - @attachment_permission_profiles.map {|p| p.user_group }).map {|g| [g.name, g.id] } … … 207 207 return unless authorized_to_edit_assets_permissions(asset) 208 208 209 assets_user_group.update_permission_profiles(params[:profile], params[:form], params[: work_order], params[:attachment])209 assets_user_group.update_permission_profiles(params[:profile], params[:form], params[:task], params[:attachment]) 210 210 211 211 flash[:notice] = msg_changes_saved branches/workorder_report_rename/app/controllers/asset_tree_controller.rb
r464 r469 113 113 # redirect to the appropriate list page. 114 114 return redirect_to(:controller => 'form', :action=> 'list') if request.env['HTTP_REFERER'] =~ /form\/.*$/x 115 return redirect_to(:controller => ' work_order', :action=> 'list') if request.env['HTTP_REFERER'] =~ /work_order\/.*$/x115 return redirect_to(:controller => 'task', :action=> 'list') if request.env['HTTP_REFERER'] =~ /task\/.*$/x 116 116 return redirect_to(:controller => 'attachment', :action=> 'list') if request.env['HTTP_REFERER'] =~ /attachment\/.*$/x 117 117 branches/workorder_report_rename/app/controllers/data_permission_controller.rb
r455 r469 46 46 redirect_with_error_message(msg_unauthorized_operation(_('read'), _('[%d]', @object.id)), 47 47 :controller => 'form', :action => 'index') 48 when ' WorkOrder'48 when 'Task' 49 49 redirect_with_error_message(msg_unauthorized_operation(_('read'), _('{%d}', @object.id)), 50 :controller => ' work_order', :action => 'list')50 :controller => 'task', :action => 'list') 51 51 when 'Attachment' 52 52 redirect_with_error_message(msg_unauthorized_operation(_('read'), _('<%d>', @object.id)), … … 67 67 68 68 case params[:datatype] 69 when 'Attachment', 'Form', ' WorkOrder'69 when 'Attachment', 'Form', 'Task' 70 70 protector = Asset.find params[:id] 71 71 when 'TypeAttachment' … … 116 116 117 117 def find_object(datatype, id) 118 raise "Invalid datatype" unless ['Form', ' WorkOrder', 'Attachment', 'TypeAttachment'].include?(datatype)118 raise "Invalid datatype" unless ['Form', 'Task', 'Attachment', 'TypeAttachment'].include?(datatype) 119 119 @object = Object.const_get(datatype).find(id) 120 120 end branches/workorder_report_rename/app/controllers/form_controller.rb
r452 r469 50 50 end 51 51 52 redirect_to(:action => 'create', :id => params[:form_type][:id], :cause_ work_order_id => params[:cause_work_order_id]) and return if request.post?52 redirect_to(:action => 'create', :id => params[:form_type][:id], :cause_task_id => params[:cause_task_id]) and return if request.post? 53 53 54 54 @title = _('Select form type to create') … … 59 59 redirect_with_message(_('No form types defined.'), :back) and return if form_types.empty? 60 60 61 @hidden_fields = [ ['cause_ work_order_id', params[:cause_work_order_id].to_i] ] if params[:cause_work_order_id]61 @hidden_fields = [ ['cause_task_id', params[:cause_task_id].to_i] ] if params[:cause_task_id] 62 62 @fields = [ [_('Form type'), 'form_type', 'id', form_types.collect { |type| [type.name, type.id] }] ] 63 63 render(:partial => 'shared/select', :layout => 'mainlevel', … … 76 76 @form = @form_type.create_empty_form(@selected_asset) 77 77 @form.creator = session[:user] 78 @cause_ work_order_id = params[:cause_work_order_id] if params[:cause_work_order_id]78 @cause_task_id = params[:cause_task_id] if params[:cause_task_id] 79 79 # Form cookies are used to match image field values in the session 80 80 # to specific form creation / edit form. … … 97 97 end 98 98 99 @form.cause_ work_order_id = @cause_work_order_id if @cause_work_order_id99 @form.cause_task_id = @cause_task_id if @cause_task_id 100 100 101 101 if @form.validate_fields and @form.valid? branches/workorder_report_rename/app/controllers/overview_controller.rb
r464 r469 26 26 when 'forms_by_type' 27 27 image = generate_forms_by_type_chart 28 when ' work_orders_by_status'29 image = generate_ work_orders_by_status_chart28 when 'tasks_by_status' 29 image = generate_tasks_by_status_chart 30 30 when 'resource_usage' 31 31 image = generate_resource_usage_graph 32 when 'time_spent_on_ work_orders'33 image = generate_time_spent_on_ work_orders_chart32 when 'time_spent_on_tasks' 33 image = generate_time_spent_on_tasks_chart 34 34 else 35 35 image = pie(300, 200, [1, 1], ['Empty', 'Empty']) … … 51 51 end 52 52 53 def generate_ work_orders_by_status_chart53 def generate_tasks_by_status_chart 54 54 find_selected_assets 55 work_order_counts = [WorkOrder.NEW, WorkOrder.ASSIGNED, WorkOrder.ACCEPTED].collect { |state|56 WorkOrder.count_authorized_to(:read, [@selected_assets_condition[0] + ' AND state = ?'] + [@selected_assets_condition[1], state])55 task_counts = [Task.NEW, Task.ASSIGNED, Task.ACCEPTED].collect { |state| 56 Task.count_authorized_to(:read, [@selected_assets_condition[0] + ' AND state = ?'] + [@selected_assets_condition[1], state]) 57 57 } 58 58 59 return pie(300, 200, work_order_counts, [_('New'), _('Assigned'), _('Accepted')])59 return pie(300, 200, task_counts, [_('New'), _('Assigned'), _('Accepted')]) 60 60 end 61 61 62 def generate_time_spent_on_ work_orders_chart62 def generate_time_spent_on_tasks_chart 63 63 find_selected_assets 64 times = WorkOrder.average_times_from_open_state(@selected_assets_condition)64 times = Task.average_times_from_open_state(@selected_assets_condition) 65 65 return bar(300, 200, times, [_('Assigned'), _('Accepted'), _('Closed')]) 66 66 end … … 68 68 def generate_resource_usage_graph 69 69 find_selected_assets 70 resource_usage = WorkOrder.calculate_resource_usage(@selected_assets_condition, 2.days, 30.minutes)70 resource_usage = Task.calculate_resource_usage(@selected_assets_condition, 2.days, 30.minutes) 71 71 return line(300, 200, [resource_usage], [_('Resource usage')]) 72 72 end branches/workorder_report_rename/app/controllers/search_controller.rb
r455 r469 33 33 search_string.scan(/\{([[:digit:]]+)/) { |id| 34 34 id = id.first.to_i 35 unless WorkOrder.find_in_authorized_assets(:all, :conditions => ['id = ?', id], :readonly => true).empty?36 redirect_to :controller => ' work_order', :action => 'view', :id => id35 unless Task.find_in_authorized_assets(:all, :conditions => ['id = ?', id], :readonly => true).empty? 36 redirect_to :controller => 'task', :action => 'view', :id => id 37 37 return 38 38 else branches/workorder_report_rename/app/controllers/timeline_controller.rb
r464 r469 43 43 id_conditions = [] 44 44 45 for klass in [Form, WorkOrder, Attachment]45 for klass in [Form, Task, Attachment] 46 46 ids = klass.find_authorized_to_read(:all, :select => select, :conditions => @selected_assets_condition).collect { |r| r.id } 47 47 next if ids.empty? branches/workorder_report_rename/app/controllers/user_controller.rb
r464 r469 132 132 def remove 133 133 common_remove(User, 'login', :action => 'list') { |instance| 134 unless instance. work_orders.empty?135 _('Unable to remove user %s, because there are work_orders assigned to this user.', instance.login)134 unless instance.tasks.empty? 135 _('Unable to remove user %s, because there are tasks assigned to this user.', instance.login) 136 136 end 137 137 } branches/workorder_report_rename/app/helpers/application_helper.rb
r464 r469 431 431 end 432 432 433 # Function: link_to_ work_order433 # Function: link_to_task 434 434 # ============================ 435 435 # … … 438 438 # Parameters: 439 439 # ----------- 440 # work_order- Work order to link to440 # task - Work order to link to 441 441 # link_only - If true, the 'Work order' text is not displayed. 442 442 # show_type - If true, the work order's type will be displayed 443 def link_to_ work_order(work_order, link_only = false, show_type = true)444 return '' unless work_order445 446 link_text = work_order.to_s447 link_text += " (#{ work_order.work_order_type.name})" if show_type448 449 link = link_to(h(link_text), {:controller => ' work_order', :action => 'view', :id => work_order.id}, :class => 'work_order')450 #link_title = h("#{ work_order.to_s} (#{work_order.work_order_type.name})")451 #link = "<a href=\"/ work_order/view/#{work_order.id}\" class=\"work_order\">#{link_title}</a>"443 def link_to_task(task, link_only = false, show_type = true) 444 return '' unless task 445 446 link_text = task.to_s 447 link_text += " (#{task.task_type.name})" if show_type 448 449 link = link_to(h(link_text), {:controller => 'task', :action => 'view', :id => task.id}, :class => 'task') 450 #link_title = h("#{task.to_s} (#{task.task_type.name})") 451 #link = "<a href=\"/task/view/#{task.id}\" class=\"task\">#{link_title}</a>" 452 452 return link if link_only 453 453 return _('Work order') + ' ' + link … … 549 549 def from_markup(src) 550 550 asset_url_prefix = url_for(:controller=>'/asset', :action=>'view', :full_code=>'') 551 work_order_url_prefix = url_for(:controller=>'work_order', :action=>'view', :id=>'')551 task_url_prefix = url_for(:controller=>'task', :action=>'view', :id=>'') 552 552 form_url_prefix = url_for(:controller=>'form', :action=>'view', :id=>'') 553 553 attachment_url_prefix = url_for(:controller=>'attachment', :action=>'view', :id=>'') 554 554 type_attachment_url_prefix = url_for(:controller=>'type_attachment', :action=>'view', :id=>'') 555 return CMMSMarkup.new(src, asset_url_prefix, work_order_url_prefix, form_url_prefix, attachment_url_prefix, type_attachment_url_prefix).to_html555 return CMMSMarkup.new(src, asset_url_prefix, task_url_prefix, form_url_prefix, attachment_url_prefix, type_attachment_url_prefix).to_html 556 556 end 557 557 branches/workorder_report_rename/app/helpers/asset_helper.rb
r454 r469 64 64 when 'Form' 65 65 link_to_form(item, true) 66 when ' WorkOrder'67 link_to_ work_order(item, true)66 when 'Task' 67 link_to_task(item, true) 68 68 when 'Attachment' 69 69 link_to_attachment(item, true) branches/workorder_report_rename/app/models/asset.rb
r464 r469 25 25 belongs_to :asset_type 26 26 has_many :forms 27 has_many : work_orders27 has_many :tasks 28 28 has_many :attachments 29 29 has_many :assets_user_groups, :dependent => :destroy, :order => 'user_group_id' … … 104 104 # ----------- 105 105 # operation - Symbol defining which permission is checked. Possible operations 106 # are :edit, :create_form, :create_ work_order, :attach_file,106 # are :edit, :create_form, :create_task, :attach_file, 107 107 # :create_subasset, :edit_permissions, :remove. 108 108 # … … 116 116 when :read 117 117 where_sql = sanitize_sql(['user_group_id IN (?)', group_ids]) 118 when :edit, :create_subasset, :edit_permissions, :remove, :create_form, :create_ work_order, :attach_file118 when :edit, :create_subasset, :edit_permissions, :remove, :create_form, :create_task, :attach_file 119 119 where_sql = sanitize_sql(["user_group_id IN (?) AND #{operation} = ?", group_ids, true]) 120 120 else … … 266 266 end 267 267 268 # Function: authorized_to_create_ work_order?268 # Function: authorized_to_create_task? 269 269 # ========================================== 270 270 # 271 # Returns true if the user is authorized to create work_orders to this asset272 def authorized_to_create_ work_order?273 authorized_to(:create_ work_order)271 # Returns true if the user is authorized to create tasks to this asset 272 def authorized_to_create_task? 273 authorized_to(:create_task) 274 274 end 275 275 … … 351 351 when 'Form' 352 352 return authorized_to_create_form? 353 when ' WorkOrder'354 return authorized_to_create_ work_order?353 when 'Task' 354 return authorized_to_create_task? 355 355 when 'Attachment' 356 356 return authorized_to_attach_file? … … 461 461 create_permission = 'create_form' 462 462 permission_profiles = :form_permission_profiles 463 when ' WorkOrder'464 create_permission = 'create_ work_order'465 permission_profiles = : work_order_permission_profiles463 when 'Task' 464 create_permission = 'create_task' 465 permission_profiles = :task_permission_profiles 466 466 when 'Attachment' 467 467 create_permission = 'attach_file' … … 567 567 # ----------- 568 568 # operation - Symbol defining which permission is checked. Possible operations 569 # are :edit, :create_form, :create_ work_order, :attach_file,569 # are :edit, :create_form, :create_task, :attach_file, 570 570 # :create_subasset, :edit_permissions, :remove. 571 571 def authorized_to(operation) … … 584 584 # ----------- 585 585 # operation - Symbol defining which permission is checked. Possible operations 586 # are :edit, :create_form, :create_ work_order, :attach_file,586 # are :edit, :create_form, :create_task, :attach_file, 587 587 # :create_subasset, :edit_permissions, :remove. 588 588 def branch_authorized_to(operation) branches/workorder_report_rename/app/models/asset_condition_analysis.rb
r454 r469 9 9 def analyse_service_request_chain 10 10 result = {} 11 cause_form_tag, work_order_tag, effect_form_tag = DataTypeTag.find DataTypeTag::CHAIN['Service request']11 cause_form_tag, task_tag, effect_form_tag = DataTypeTag.find DataTypeTag::CHAIN['Service request'] 12 12 cause_form_type_ids = cause_form_tag.form_types.map {|t| t.id } 13 work_order_type_ids = work_order_tag.work_order_types.map {|t| t.id }13 task_type_ids = task_tag.task_types.map {|t| t.id } 14 14 effect_form_type_ids = effect_form_tag.form_types.map {|t| t.id } 15 15 16 unless work_order_type_ids.empty?16 unless task_type_ids.empty? 17 17 # Find "Service request" forms which haven't led to work orders. 18 18 unless cause_form_type_ids.empty? 19 19 # First find ids of forms which have led to work orders. 20 cause_form_ids = WorkOrder.find(:all, :select => 'cause_form_id,' + WorkOrder.minimal_select, :conditions => ['asset_id = ? AND work_order_type_id IN (?) AND cause_form_id IS NOT NULL', self.id, work_order_type_ids]).map {|w| w.cause_form_id }20 cause_form_ids = Task.find(:all, :select => 'cause_form_id,' + Task.minimal_select, :conditions => ['asset_id = ? AND task_type_id IN (?) AND cause_form_id IS NOT NULL', self.id, task_type_ids]).map {|w| w.cause_form_id } 21 21 conditions = ['asset_id = ? AND form_type_id IN (?)', self.id, cause_form_type_ids] 22 22 unless cause_form_ids.empty? … … 29 29 30 30 # Find new "Service" work orders. 31 found = WorkOrder.find_authorized_to_read(:all, :conditions => ['asset_id = ? AND work_order_type_id IN (?) AND state = ?', self.id, work_order_type_ids, WorkOrder.NEW], :readonly => true)32 result[:new_works] = [ work_order_tag.name, found] unless found.empty?31 found = Task.find_authorized_to_read(:all, :conditions => ['asset_id = ? AND task_type_id IN (?) AND state = ?', self.id, task_type_ids, Task.NEW], :readonly => true) 32 result[:new_works] = [task_tag.name, found] unless found.empty? 33 33 34 34 # Find "Service" work orders which have been assigned or accepted. 35 found = WorkOrder.find_authorized_to_read(:all, :conditions => ['asset_id = ? AND work_order_type_id IN (?) AND state IN (?)', self.id, work_order_type_ids, [WorkOrder.ASSIGNED, WorkOrder.ACCEPTED]], :readonly => true)36 result[:assigned_works] = [ work_order_tag.name, found] unless found.empty?35 found = Task.find_authorized_to_read(:all, :conditions => ['asset_id = ? AND task_type_id IN (?) AND state IN (?)', self.id, task_type_ids, [Task.ASSIGNED, Task.ACCEPTED]], :readonly => true) 36 result[:assigned_works] = [task_tag.name, found] unless found.empty? 37 37 38 38 # Find closed "Service" work orders, which haven't led to "Condition" forms. 39 39 unless effect_form_type_ids.empty? 40 40 # First find ids of work orders which have led to forms. 41 cause_ work_order_ids = Form.find(:all, :select => 'cause_work_order_id,' + Form.minimal_select, :conditions => ['asset_id = ? AND form_type_id IN (?) AND cause_work_order_id IS NOT NULL', self.id, effect_form_type_ids]).map {|w| w.cause_work_order_id }42 conditions = ['asset_id = ? AND work_order_type_id IN (?) AND work_orders.state = ?', self.id, work_order_type_ids, WorkOrder.CLOSED]43 unless cause_ work_order_ids.empty?44 conditions[0] += ' AND work_orders.id NOT IN (?)'45 conditions.push cause_ work_order_ids46 end 47 found = WorkOrder.find_authorized_to_read(:all, :conditions => conditions, :readonly => true)48 result[:unknown_condition] = [[ work_order_tag.name, effect_form_tag.name], found] unless found.empty?41 cause_task_ids = Form.find(:all, :select => 'cause_task_id,' + Form.minimal_select, :conditions => ['asset_id = ? AND form_type_id IN (?) AND cause_task_id IS NOT NULL', self.id, effect_form_type_ids]).map {|w| w.cause_task_id } 42 conditions = ['asset_id = ? AND task_type_id IN (?) AND tasks.state = ?', self.id, task_type_ids, Task.CLOSED] 43 unless cause_task_ids.empty? 44 conditions[0] += ' AND tasks.id NOT IN (?)' 45 conditions.push cause_task_ids 46 end 47 found = Task.find_authorized_to_read(:all, :conditions => conditions, :readonly => true) 48 result[:unknown_condition] = [[task_tag.name, effect_form_tag.name], found] unless found.empty? 49 49 end 50 50 end … … 63 63 def analyse_maintenance_chain 64 64 result = {} 65 cause_ work_order_tag, effect_form_tag = DataTypeTag.find DataTypeTag::CHAIN['Maintenance']66 cause_ work_order_type_ids = cause_work_order_tag.work_order_types.map {|t| t.id }65 cause_task_tag, effect_form_tag = DataTypeTag.find DataTypeTag::CHAIN['Maintenance'] 66 cause_task_type_ids = cause_task_tag.task_types.map {|t| t.id } 67 67 effect_form_type_ids = effect_form_tag.form_types.map {|t| t.id } 68 68 69 unless cause_ work_order_type_ids.empty?69 unless cause_task_type_ids.empty? 70 70 # Find new "Maintenance" work orders 71 found = WorkOrder.find_authorized_to_read(:all, :conditions => ['asset_id = ? AND work_order_type_id IN (?) AND state = ?', self.id, cause_work_order_type_ids, WorkOrder.NEW])72 result[:new_works] = [cause_ work_order_tag.name, found] unless found.empty?71 found = Task.find_authorized_to_read(:all, :conditions => ['asset_id = ? AND task_type_id IN (?) AND state = ?', self.id, cause_task_type_ids, Task.NEW]) 72 result[:new_works] = [cause_task_tag.name, found] unless found.empty? 73 73 74 74 # Find "Maintenance" work orders which have been assigned or accepted. 75 found = WorkOrder.find_authorized_to_read(:all, :conditions => ['asset_id = ? AND work_order_type_id IN (?) AND state IN (?)', self.id, cause_work_order_type_ids, [WorkOrder.ASSIGNED, WorkOrder.ACCEPTED]])76 result[:assigned_works] = [cause_ work_order_tag.name, found] unless found.empty?75 found = Task.find_authorized_to_read(:all, :conditions => ['asset_id = ? AND task_type_id IN (?) AND state IN (?)', self.id, cause_task_type_ids, [Task.ASSIGNED, Task.ACCEPTED]]) 76 result[:assigned_works] = [cause_task_tag.name, found] unless found.empty? 77 77 78 78 # Find closed "Maintenance" work orders, which haven't led to "Maintenance" forms. 79 79 unless effect_form_type_ids.empty? 80 80 # First find ids of work orders which have led to forms. 81 cause_ work_order_ids = Form.find(:all, :select => 'cause_work_order_id,' + Form.minimal_select, :conditions => ['asset_id = ? AND form_type_id IN (?) AND cause_work_order_id IS NOT NULL', self.id, effect_form_type_ids]).map {|w| w.cause_work_order_id }82 conditions = ['asset_id = ? AND work_order_type_id IN (?) AND work_orders.state = ?', self.id, cause_work_order_type_ids, WorkOrder.CLOSED]83 unless cause_ work_order_ids.empty?84 conditions[0] += ' AND work_orders.id NOT IN (?)'85 conditions.push cause_ work_order_ids86 end 87 found = WorkOrder.find_authorized_to_read(:all, :conditions => conditions, :readonly => true)88 result[:unknown_condition] = [[cause_ work_order_tag.name, effect_form_tag.name], found] unless found.empty?81 cause_task_ids = Form.find(:all, :select => 'cause_task_id,' + Form.minimal_select, :conditions => ['asset_id = ? AND form_type_id IN (?) AND cause_task_id IS NOT NULL', self.id, effect_form_type_ids]).map {|w| w.cause_task_id } 82 conditions = ['asset_id = ? AND task_type_id IN (?) AND tasks.state = ?', self.id, cause_task_type_ids, Task.CLOSED] 83 unless cause_task_ids.empty? 84 conditions[0] += ' AND tasks.id NOT IN (?)' 85 conditions.push cause_task_ids 86 end 87 found = Task.find_authorized_to_read(:all, :conditions => conditions, :readonly => true) 88 result[:unknown_condition] = [[cause_task_tag.name, effect_form_tag.name], found] unless found.empty? 89 89 end 90 90 end branches/workorder_report_rename/app/models/assets_user_group.rb
r441 r469 28 28 has_many :data_permission_profiles, :dependent => :delete_all 29 29 has_many :form_permission_profiles, :order => 'other', :dependent => :delete_all 30 has_many : work_order_permission_profiles, :order => 'other', :dependent => :delete_all30 has_many :task_permission_profiles, :order => 'other', :dependent => :delete_all 31 31 has_many :attachment_permission_profiles, :order => 'other', :dependent => :delete_all 32 32 … … 43 43 return true if self.attributes == original_attributes 44 44 45 original_create_form, original_create_ work_order, original_attach_file = original_attributes.values_at('create_form', 'create_work_order', 'attach_file')45 original_create_form, original_create_task, original_attach_file = original_attributes.values_at('create_form', 'create_task', 'attach_file') 46 46 47 47 begin … … 57 57 end 58 58 # For Work orders 59 if original_create_ work_order == false and self.create_work_order== true60 self. work_order_permission_profiles.create(:user_group_id => self.user_group_id, :group_read => true)61 elsif original_create_ work_order == true and self.create_work_order== false62 self. work_order_permission_profiles.clear59 if original_create_task == false and self.create_task == true 60 self.task_permission_profiles.create(:user_group_id => self.user_group_id, :group_read => true) 61 elsif original_create_task == true and self.create_task == false 62 self.task_permission_profiles.clear 63 63 end 64 64 # For Attachments … … 83 83 # If needed update attributes 84 84 if self.create_form != object.create_form or 85 self.create_ work_order != object.create_work_orderor85 self.create_task != object.create_task or 86 86 self.attach_file != object.attach_file 87 87 88 88 self.attributes = { 89 89 :create_form => object.create_form, 90 :create_ work_order => object.create_work_order,90 :create_task => object.create_task, 91 91 :attach_file => object.attach_file 92 92 } … … 152 152 # are given, then new other permission profile(s) will be created with 153 153 # attributes given in hashes +new_*_other_profile+. 154 def update_permission_profiles(profiles, new_form_other_profile = nil, new_ work_order_other_profile = nil, new_attachment_other_profile = nil)154 def update_permission_profiles(profiles, new_form_other_profile = nil, new_task_other_profile = nil, new_attachment_other_profile = nil) 155 155 raise("Unauthorized to edit asset #{self.asset.full_code}'s permissions") unless authorized_to_edit? 156 156 … … 170 170 171 171 # Create new other profiles if needed. Only use group_* attributes from new_*_other_profile. 172 [new_form_other_profile, new_ work_order_other_profile, new_attachment_other_profile].each { |attrs|172 [new_form_other_profile, new_task_other_profile, new_attachment_other_profile].each { |attrs| 173 173 next if attrs.nil? 174 174 tmp_attrs = attrs.symbolize_keys … … 180 180 } 181 181 FormPermissionProfile.create(new_form_other_profile) if new_form_other_profile 182 WorkOrderPermissionProfile.create(new_work_order_other_profile) if new_work_order_other_profile182 TaskPermissionProfile.create(new_task_other_profile) if new_task_other_profile 183 183 AttachmentPermissionProfile.create(new_attachment_other_profile) if new_attachment_other_profile 184 184 end … … 190 190 # Returns true if none of the permission profiles for data +data+ has permission to +operation+ true. 191 191 # +operation+:: defines which permission is checked. Choices are :read, :change_state and :edit. 192 # +data+:: defines data type of profiles. Choices are :forms, : work_orders and :attachments.192 # +data+:: defines data type of profiles. Choices are :forms, :tasks and :attachments. 193 193 # 194 194 # Example: object.none_can(:read, :forms) … … 213 213 end 214 214 } 215 when : work_orders216 self. work_order_permission_profiles.each { |p|215 when :tasks 216 self.task_permission_profiles.each { |p| 217 217 if p.send(attribute) 218 218 return false … … 299 299 if childs_group.update_attributes(:edit => self.edit, 300 300 :create_form => self.create_form, 301 :create_ work_order => self.create_work_order,301 :create_task => self.create_task, 302 302 :attach_file => self.attach_file, 303 303 :create_subasset => self.create_subasset, branches/workorder_report_rename/app/models/form.rb
r452 r469 10 10 # Associations 11 11 belongs_to :form_type 12 belongs_to :cause_ work_order, :class_name => 'WorkOrder', :foreign_key => 'cause_work_order_id' # work order which caused this form13 has_one :effect_ work_order, :class_name => 'WorkOrder', :foreign_key => 'cause_form_id' # work order which was caused by this form12 belongs_to :cause_task, :class_name => 'Task', :foreign_key => 'cause_task_id' # work order which caused this form 13 has_one :effect_task, :class_name => 'Task', :foreign_key => 'cause_form_id' # work order which was caused by this form 14 14 has_many :form_field_values, :dependent => :delete_all 15 15 has_many :form_events, :dependent => :delete_all branches/workorder_report_rename/app/models/form_tag.rb
r452 r469 7 7 # Callbacks 8 8 # Associations 9 belongs_to :cause_ work_order_tag, :class_name => 'WorkOrderTag', :foreign_key => 'cause_tag_id'10 has_one :effect_ work_order_tag, :class_name => 'WorkOrderTag', :foreign_key => 'cause_tag_id'9 belongs_to :cause_task_tag, :class_name => 'TaskTag', :foreign_key => 'cause_tag_id' 10 has_one :effect_task_tag, :class_name => 'TaskTag', :foreign_key => 'cause_tag_id' 11 11 has_many :form_categories 12 12 has_many :form_types, :through => :form_categories branches/workorder_report_rename/app/models/user.rb
r464 r469 29 29 has_and_belongs_to_many :keyrings, :uniq => true, :order => 'name' 30 30 has_and_belongs_to_many :user_groups, :uniq => true, :order => 'name' 31 has_and_belongs_to_many : work_orders31 has_and_belongs_to_many :tasks 32 32 has_many :received_messages, :foreign_key => 'receiver_user_id', :order => 'created_at', :class_name => 'Message', :dependent => :delete_all 33 33 has_many :sent_messages, :foreign_key => 'sender_user_id', :order => 'created_at', :class_name => 'Message', :dependent => :delete_all … … 100 100 end 101 101 102 # WorkOrders assigned to the user103 def work_orders104 return WorkOrder.find_all_by_responsible_user_id(self.id)102 # Tasks assigned to the user 103 def tasks 104 return Task.find_all_by_responsible_user_id(self.id) 105 105 end 106 106 branches/workorder_report_rename/app/models/user_group.rb
r441 r469 17 17 has_many :form_permissions, :dependent => :delete_all 18 18 # has_many :forms, :through => :form_permissions 19 has_many : work_order_permissions, :dependent => :delete_all20 # has_many : work_orders, :through => :work_order_permissions19 has_many :task_permissions, :dependent => :delete_all 20 # has_many :tasks, :through => :task_permissions 21 21 has_many :attachment_permissions, :dependent => :delete_all 22 22 # has_many :attachments, :through => :attachment_permissions branches/workorder_report_rename/app/views/asset_permission/edit.rhtml
r465 r469 17 17 <tr> 18 18 <th><%= _('Create work orders') %></th> 19 <td><%= check_box(:assets_user_group, :create_ work_order) %></td>19 <td><%= check_box(:assets_user_group, :create_task) %></td> 20 20 </tr> 21 21 <tr> … … 41 41 <%= end_form_tag %> 42 42 43 <% if @assets_user_group.create_form or @assets_user_group.create_ work_orderor @assets_user_group.attach_file -%>43 <% if @assets_user_group.create_form or @assets_user_group.create_task or @assets_user_group.attach_file -%> 44 44 <% if @assets_user_group.create_form -%> 45 45 <h3><%= _('Default permissions for forms created by user group "%s"', h(@user_group.name)) %></h3> … … 51 51 :object_name => 'form'}) %> 52 52 <% end -%> 53 <% if @assets_user_group.create_ work_order-%>53 <% if @assets_user_group.create_task -%> 54 54 <h3><%= _('Default permissions for work orders created by user group "%s"', h(@user_group.name)) %></h3> 55 <%= render(:partial => 'profiles', :object => @ work_order_permission_profiles,56 :locals => {:type => ' WorkOrderPermissionProfile',57 :available_groups => @ work_order_available_groups,55 <%= render(:partial => 'profiles', :object => @task_permission_profiles, 56 :locals => {:type => 'TaskPermissionProfile', 57 :available_groups => @task_available_groups, 58 58 :view_text => _('View work order'), 59 59 :edit_text => _('Edit work order'), 60 60 &