Changeset 721

Show
Ignore:
Timestamp:
11/08/07 13:08:10 (1 year ago)
Author:
markku
Message:

User permission disabling setting. Closes #480

Files:

Legend:

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

    r715 r721  
    2121  layout 'mainlevel' 
    2222  before_filter :set_current_user, :set_selected_asset, :prepare_tree_view, :protect_page_groups, :handle_cancel_submit, :set_host, :check_new_service_requests 
     23  prepend_before_filter :load_settings 
    2324  after_filter :reset_timedout_session, :process_model_events 
    2425 
     
    690691    @service_request_id = Task.find_authorized_to_read(:first, :conditions => conditions).id if @service_request_count == 1 
    691692  end 
     693 
     694  # Function: load_settings 
     695  # ======================= 
     696  # Loads the system settings from the database. 
     697  # 
     698  def load_settings 
     699    Setting.load_settings 
     700    @enable_user_permissions = Setting.enable_user_permissions 
     701    return true 
     702  end 
    692703end 
  • trunk/app/controllers/asset_permission_controller.rb

    r707 r721  
    1414class AssetPermissionController < ApplicationController 
    1515  prepend_before_filter :login_required 
    16   append_before_filter :lock_asset, :enter_page_group 
     16  append_before_filter :check_settings, :lock_asset, :enter_page_group 
    1717  LOCK_DURATION = 1.hour 
    1818 
     
    318318    return true 
    319319  end 
     320 
     321  # Method: check_settings 
     322  # ====================== 
     323  # Makes sure that this controller can be accessed only if the user 
     324  # permission system is enabled. 
     325  def check_settings 
     326    invalid_request unless Setting.enable_user_permissions 
     327  end 
    320328end 
  • trunk/app/controllers/data_permission_controller.rb

    r651 r721  
    1313class DataPermissionController < ApplicationController 
    1414  prepend_before_filter :login_required 
     15  append_before_filter :check_settings 
    1516 
    1617  # Function: edit 
     
    121122    @object = Object.const_get(datatype).find(id) 
    122123  end 
     124 
     125  # Method: check_settings 
     126  # ====================== 
     127  # Makes sure that this controller can be accessed only if the user 
     128  # permission system is enabled. 
     129  def check_settings 
     130    invalid_request unless Setting.enable_user_permissions 
     131  end 
    123132end 
  • trunk/app/helpers/application_helper.rb

    r710 r721  
    703703  end 
    704704 
     705  # Method: find_asset_tree_nodes 
     706  # ============================= 
     707  # Finds nodes for the asset tree. Each node level is a ul-tag and 
     708  # each node (i.e. asset) is a li-tag. If user is authorized to read an asset, 
     709  # the corresponding node is link to the asset. 
     710  # 
    705711  def find_asset_tree_nodes(group_ids, parent_id = nil, open_parent = true, branch_depth = nil) 
    706712    asset_code_and_name_sql = ActiveRecord::Base.connection.sql_concat(:code, ' (', :name, ')') 
     
    754760  end 
    755761 
     762  # Method: find_all_asset_tree_nodes 
     763  # ================================= 
     764  # Finds nodes for the asset tree without any permission checking. 
     765  # 
     766  # See also: 
     767  # --------- 
     768  # Documentation for the <find_asset_tree_nodes> method. 
     769  # 
     770  def find_all_asset_tree_nodes(parent_id = nil, open_parent = true, branch_depth = nil) 
     771    asset_code_and_name_sql = ActiveRecord::Base.connection.sql_concat(:code, ' (', :name, ')') 
     772    parent_condition = parent_id ? "parent_id = #{parent_id}" : 'parent_id IS NULL' 
     773    nodes = Asset.connection.execute("SELECT id, #{asset_code_and_name_sql}, asset_type_id, (SELECT COUNT(*) FROM assets T1 WHERE T1.parent_id = assets.id) AS child_count FROM assets WHERE #{parent_condition} ORDER BY code") 
     774 
     775    results = [] 
     776    nodes.each do |node| 
     777      is_open = parent_id.nil? ? true : (open_parent and @open_node_list and @open_node_list.include?(node[0].to_i)) 
     778      depth = @selected_asset.id == node[0].to_i ? 0 : branch_depth 
     779 
     780      # Recurse if node has children 
     781      children = node[3] == '0' ? '' : find_all_asset_tree_nodes(node[0], is_open, depth ? depth + 1 : nil) 
     782 
     783      is_leaf = (children == '') 
     784      link_text = '<span class="' + (node[2] ? 'asset_type_' + node[2] : 'asset_type_0') + '">' + node[1] + '</span>' 
     785      tree_symbol = is_open ? image_tag('16x16/folder_min.gif') : image_tag('16x16/folder_plu.gif') 
     786 
     787      result = '<li class="' + (is_leaf ? 'tree_leaf' : 'tree') + '">' 
     788      result += '<a name="asset_' + node[0].to_s + '"/>' 
     789      result += '<a href="/asset_tree/toggle_tree_node_open?node_id=' + node[0] + '" class="tree_open_close">' + tree_symbol + '</a>' unless is_leaf or parent_id == nil 
     790      case session[:asset_tree_mode] 
     791        when 'move' 
     792        result += radio_button_tag('new_parent_id', node[0], false, :disabled => (@selected_asset.id == node[0].to_i or (branch_depth and branch_depth > 0) or Asset.connection.select_values("SELECT code FROM assets WHERE parent_id = #{node[0]}").include?(@selected_asset.code))) 
     793        result += '<span class="' + link_class_for_asset_tree_node(node[0].to_i, node[2].to_i, branch_depth) + '">' + link_text + '</span>' 
     794        when 'clone' 
     795          result += radio_button_tag('clone_parent_id', node[0], false, :disabled => (@selected_asset.parent_id == node[0].to_i or Asset.connection.select_values("SELECT code FROM assets WHERE parent_id = #{node[0]}").include?(@selected_asset.code))) 
     796        result += '<span class="' + link_class_for_asset_tree_node(node[0].to_i, node[2].to_i, branch_depth) + '">' + link_text + '</span>' 
     797        else 
     798          result += '<a href="/asset_tree/select/' + node[0] + '" class="' + link_class_for_asset_tree_node(node[0].to_i, node[2].to_i, branch_depth) + '">' + link_text + '</a>' 
     799      end 
     800      result += '<ul class="tree">' + children + '</ul>' if is_open and not is_leaf 
     801      result += '</li>' 
     802      results.push(result) 
     803    end 
     804    return results.join 
     805  end 
     806 
    756807  # Select tag that support option collections. The collection is converted 
    757808  # to option tags with options_for_select. 
  • trunk/app/models/asset.rb

    r710 r721  
    9797  # Overwrite the implementation in the parent class 
    9898  def Asset.find_authorized_to_read(*args) 
    99     return super unless UserAccount.current_user.class == Customer 
     99    return super unless UserAccount.current_user.instance_of?(Customer) 
    100100 
    101101    args = add_conditions_to_find_arguments(args, "#{self.table_name}.customer_id = ?", [UserAccount.current_user.id]) 
     
    115115  # 
    116116  def Asset.find_authorized_to(operation, args) 
    117     return records_not_found(args) unless UserAccount.current_user and UserAccount.current_user.class == User 
     117    return records_not_found(args) unless UserAccount.current_user.instance_of?(User) 
     118 
     119    return self.find(*args) unless Setting.enable_user_permissions 
    118120 
    119121    group_ids = UserAccount.current_user.user_groups.map {|g| g.id } 
     
    175177  end 
    176178 
     179  # Method: Asset.update_permission_hierarchy 
     180  # ========================================= 
     181  # Updates the use_parents_permissions hierarchy. Used when the 
     182  # Setting.enable_user_permissions setting is toggled to true. 
     183  # 
     184  def Asset.update_permission_hierarchy 
     185    # Do nothing if the asset permissions are enabled 
     186    return false if Setting.enable_user_permissions 
     187 
     188    # Find all assets which have their own permissions. 
     189    Asset.find(:all, :conditions => ['use_parents_permissions = ?', false]).each { |asset| 
     190      return false unless asset.copy_permissions_to_empty_subassets 
     191    } 
     192    return true 
     193  end 
     194 
    177195  # Function: full_code 
    178196  # =================== 
     
    264282 
    265283    # Customer is authorized to read his assets. 
    266     return (self.customer == UserAccount.current_user) if UserAccount.current_user.class == Customer 
     284    return (self.customer == UserAccount.current_user) if UserAccount.current_user.instance_of?(Customer) 
     285 
     286    return true unless Setting.enable_user_permissions 
    267287 
    268288    return !((UserAccount.current_user.user_groups & self.user_groups).empty?) 
     
    283303  def authorized_to_create_task? 
    284304    # Customer is authorized to create tasks to his assets 
    285     return (self.customer == UserAccount.current_user) if UserAccount.current_user.class == Customer 
     305    return (self.customer == UserAccount.current_user) if UserAccount.current_user.instance_of?(Customer) 
    286306 
    287307    return authorized_to(:create_task) 
     
    597617  #             :create_subasset, :edit_permissions, :remove. 
    598618  def authorized_to(operation) 
    599     return false unless UserAccount.current_user.class == User 
     619    return false unless UserAccount.current_user.instance_of?(User) 
     620 
     621    return true unless Setting.enable_user_permissions 
    600622 
    601623    authorized_user_groups = self.assets_user_groups.select { |aug| aug.send(operation) }.collect { |aug| aug.user_group } 
     
    755777  # Cloning permission requires the reading permission to this asset and 
    756778  # permission to create a sub-asset to some asset, other than the parent asset 
    757   # of this asset. 
     779  # of this asset or another parent with the same code 
     780  #. 
    758781  def authorized_to_clone? 
    759782    return false unless authorized_to_read? 
    760     count_args = [:create_subasset] 
    761783    # Find ids of assets that have a child with the same code as this asset 
    762784    exclude_parent_ids = Asset.find_all_by_code(self.code).map {|a| a.parent_id }.compact 
    763     count_args.push ['asset_id NOT IN (?)', exclude_parent_ids] unless exclude_parent_ids.empty? 
    764     return true if Asset.count_authorized_to(*count_args) > 0 
     785    if Setting.enable_user_permissions 
     786      count_args = [:create_subasset] 
     787      count_args.push ['asset_id NOT IN (?)', exclude_parent_ids] unless exclude_parent_ids.empty? 
     788      return true if Asset.count_authorized_to(*count_args) > 0 
     789    else 
     790      if exclude_parent_ids.empty? 
     791        return true if Asset.count > 0 
     792      else 
     793        return true if Asset.count(:conditions => ['id NOT IN (?)', exclude_parent_ids]) > 0 
     794      end 
     795    end 
    765796    return false 
    766797  end 
     
    774805  # to this asset and the permission to create a sub-asset to some asset(s) 
    775806  # which this asset can be moved to. 
     807  # 
    776808  def authorized_to_move? 
    777809    return false unless not(is_root?) and authorized_to_edit? and authorized_to_edit_permissions? 
     
    779811    exclude_parent_ids = Asset.find_all_by_code(self.code).map {|a| a.parent_id }.compact 
    780812    exclude_parent_ids += self.id_and_subasset_ids 
    781     return true if Asset.count_authorized_to(:create_subasset,  ['asset_id NOT IN (?)', exclude_parent_ids.uniq]) > 0 
     813    exclude_parent_ids.uniq! 
     814 
     815    if Setting.enable_user_permissions 
     816      return true if Asset.count_authorized_to(:create_subasset,  ['asset_id NOT IN (?)', exclude_parent_ids]) > 0 
     817    else 
     818      return true  if Asset.count(:conditions => ['id NOT IN (?)', exclude_parent_ids]) > 0 
     819    end 
    782820    return false 
     821  end 
     822 
     823  # Method: copy_permissions_to_empty_subassets 
     824  # ======================================== 
     825  # Updates the use_parents_permissions hierarchy starting from this asset 
     826  # all the way down to the assets with use_parents_permissions false 
     827  # by copying the asset permissions to subassets which have no permissions 
     828  # (i.e. to those assets created while permission system was disabled). 
     829  # 
     830  def copy_permissions_to_empty_subassets 
     831    self.children.each { |asset| 
     832      next unless asset.use_parents_permissions 
     833      if asset.user_groups.empty? 
     834        asset.copy_permissions(self.assets_user_groups) 
     835        # Recursion is not needed here because the permissions propagate 
     836        # automatically to sub-assets which don't have any permissions. 
     837      else 
     838        asset.copy_permissions_to_empty_subassets 
     839      end 
     840    } 
     841    return true 
    783842  end 
    784843 
     
    807866 
    808867    raise(ActiveRecord::ActiveRecordError, "Asset #{self.full_code} doesn't have parent!") if self.parent.nil? 
     868 
     869    unless Setting.enable_user_permissions 
     870      _info("Creating sub-asset to asset #{self.parent.full_code}") 
     871      return true 
     872    end 
    809873 
    810874    if self.parent.authorized_to_create_subasset? 
     
    829893    end 
    830894 
    831     unauthorized = false 
     895    unless Setting.enable_user_permissions 
     896      _info("Saving #{self.class}(id=#{self.id})") 
     897      return true 
     898    end 
    832899 
    833900    if locking_information_changed? and not (authorized_to_edit? or authorized_to_edit_permissions?) 
     
    874941    if self.parent.nil? 
    875942      self.use_parents_permissions = false 
    876     elsif self.use_parents_permissions and (self.new_record? or @original_use_parents_permissions == false) 
     943    elsif Setting.enable_user_permissions and self.use_parents_permissions and (self.new_record? or @original_use_parents_permissions == false) 
    877944      self.copy_permissions(self.parent.assets_user_groups) 
    878945    end 
     
    10181085  #                    have to fulfill. 
    10191086  def Asset.count_authorized_to(operation, extra_conditions = nil) 
     1087    raise 'User permissions have to be enabled' unless Setting.enable_user_permissions 
     1088 
    10201089    return false unless UserAccount.current_user 
    10211090    user_group_ids = UserAccount.current_user.user_groups.map {|g| g.id } 
    10221091    return false if user_group_ids.empty? 
     1092 
    10231093    case operation 
    10241094      when :read 
  • trunk/app/models/asset_type.rb

    r648 r721  
    2929  # Returns true if the user is authorized to read this asset type 
    3030  def authorized_to_read? 
     31    return true unless Setting.enable_user_permissions 
     32 
    3133    self.assets.each { |asset| 
    3234      return true if asset.authorized_to_read? 
     
    3739  # Returns true if the user is authorized to create new instances of +datatype+ to this asset type 
    3840  def authorized_to_create?(datatype) 
     41    return true unless Setting.enable_user_permissions 
     42 
    3943    datatype = datatype.to_s.gsub(/^Type/, '') 
    4044 
  • trunk/app/models/protected_asset_data.rb

    r707 r721  
    5555  # Version of find that only retuns objects the user is authorized to perform +operation+ to. 
    5656  def ProtectedAssetData.find_authorized_to(operation, args) 
    57     self.common_find_authorized_to(AssetsUserGroup, @@asset_model_id_sql, operation, args) 
     57    return self.common_find_authorized_to(AssetsUserGroup, @@asset_model_id_sql, operation, args) 
    5858  end 
    5959 
     
    6262    return records_not_found(args) unless user = UserAccount.current_user 
    6363 
    64     group_ids = user.user_groups.map {|g| g.id } 
    65     return records_not_found(args) if group_ids.empty? 
    66     asset_ids = AssetsUserGroup.connection.select_values("SELECT asset_id FROM assets_user_groups WHERE #{sanitize_sql(['user_group_id IN (?)', group_ids])}") 
    67     return records_not_found(args) if asset_ids.empty? 
    68  
    69     args = add_conditions_to_find_arguments(args, 'asset_id IN (?) AND ready = ?', [asset_ids, ready]) 
     64    if Setting.enable_user_permissions 
     65      group_ids = user.user_groups.map {|g| g.id } 
     66      return records_not_found(args) if group_ids.empty? 
     67      asset_ids = AssetsUserGroup.connection.select_values("SELECT asset_id FROM assets_user_groups WHERE #{sanitize_sql(['user_group_id IN (?)', group_ids])}") 
     68      return records_not_found(args) if asset_ids.empty? 
     69      args = add_conditions_to_find_arguments(args, 'asset_id IN (?) AND ready = ?', [asset_ids, ready]) 
     70    else 
     71      args = add_conditions_to_find_arguments(args, 'ready = ?', [ready]) 
     72    end 
    7073 
    7174    return self.find(*args) 
  • trunk/app/models/protected_data.rb

    r720 r721  
    131131  # See sub-classes for examples how this method can be used. 
    132132  def ProtectedData.common_find_authorized_to(connection_model, asset_model_id_sql, operation, args) 
     133    return self.find(*args) unless Setting.enable_user_permissions 
     134 
    133135    return records_not_found(args) unless user = UserAccount.current_user 
    134136 
     
    150152  # See sub-classes for examples how this method can be used. 
    151153  def ProtectedData.common_count_authorized_to(connection_model, asset_model_id_sql, operation, conditions = nil) 
     154    return self.count(conditions) unless Setting.enable_user_permissions 
     155 
    152156    return 0 unless user = UserAccount.current_user 
    153157 
     
    258262    end 
    259263 
     264    return true unless Setting.enable_user_permissions 
     265 
    260266    case operation 
    261267    when :read 
     
    332338  end 
    333339 
    334   # Creates data permissions and sets other_* permissions for the created data, 
    335   # according to user's permission profiles for the asset to which the data is created. 
     340  # Method: create_data_permissions_from_users_permission_profiles 
     341  # ============================================================= 
     342  # If the permission system is enabled creates data permissions and 
     343  # sets other_* permissions for the created data, according to user's 
     344  # permission profiles for the asset to which the data is created. 
     345  # When a customer is creating data, all other_* permissions are 
     346  # set to true - i.e. everyone can handle data created by customers. 
     347  # 
     348  # If the permission system is disabled sets other_* permissions true. 
     349  # This ensures that data will be propelly available if the permission 
     350  # system is enabled later. 
     351  # 
    336352  def create_data_permissions_from_users_permission_profiles 
     353    unless Setting.enable_user_permissions 
     354      self.other_read = true 
     355      self.other_change_state = true if has_change_state_permission? 
     356      self.other_edit = true 
     357      return true 
     358    end 
     359 
    337360    case UserAccount.current_user.class.to_s 
    338361      when 'User' 
     
    340363        _info("Creating permissions for a #{self.class} succeeded") if self.create_data_permissions_from_profiles(profiles) 
    341364      when 'Customer' 
    342         # Everyone can read and edit data created by customers 
     365        # 
    343366        self.other_read = true 
    344367        self.other_change_state = true if has_change_state_permission? 
     
    371394 
    372395      raise(ActiveRecord::ActiveRecordError, "Tried to change protected field of #{self.class}(id=#{self.id})! Possibly a failed attack!") 
     396    end 
     397 
     398    unless Setting.enable_user_permissions 
     399      _info("Saving #{self.class}(id=#{self.id})") 
     400      return true 
    373401    end 
    374402 
  • trunk/app/models/protector_model.rb

    r707 r721  
    4646  # Redefine this method in sub-classes - by default users are unauthorized to operate on all data. 
    4747  def ProtectorModel.find_authorized_to(operation, args) 
    48     records_not_found(args) 
     48    return self.find(*args) unless Setting.enable_user_permissions 
     49    return records_not_found(args) 
    4950  end 
    5051 
     
    5253  # Redefine this method in sub-classes - by default users are unauthorized to operate on all data. 
    5354  def authorized_to(operation) 
     55    return true unless Setting.enable_user_permissions 
    5456    return false 
    5557  end 
     
    6870      _error("Have to be logged in to remove #{self.class}") 
    6971      return false 
     72    end 
     73 
     74    unless Setting.enable_user_permissions 
     75      _info("Removing #{self.class}(id=#{self.id})") 
     76      return true 
    7077    end 
    7178 
  • trunk/app/models/task.rb

    r712 r721  
    309309  # 
    310310  def set_asset_if_customer 
    311     return true unless UserAccount.current_user.is_a?(Customer) 
     311    return true unless UserAccount.current_user.instance_of?(Customer) 
    312312    return true if self.asset 
    313313    asset = UserAccount.current_user.assets.find(:first, :order => 'id') 
     
    325325  # 
    326326  def set_task_type_if_customer 
    327     return true unless UserAccount.current_user.is_a?(Customer) 
     327    return true unless UserAccount.current_user.instance_of?(Customer) 
    328328    self.task_type = TaskType.get_service_request_type 
    329329    return true 
  • trunk/app/models/user_account.rb

    r713 r721  
    1010# 
    1111# This model expects a certain database layout and its based on the name/login pattern. 
     12# 
     13# Inherits: 
     14# --------- 
     15# <CmmsBase> 
    1216# 
    1317class UserAccount < CmmsBase 
  • trunk/app/views/asset_tree/_asset_tree.rhtml

    r636 r721  
    6363  <ul class="root_tree"> 
    6464  <%= 
    65     group_ids = User.current_user.user_groups.collect { |g| g.id } 
    66     find_asset_tree_nodes(group_ids) 
     65    if @enable_user_permissions 
     66      group_ids = User.current_user.user_groups.collect { |g| g.id } 
     67      find_asset_tree_nodes(group_ids) 
     68    else 
     69      find_all_asset_tree_nodes() 
     70    end 
    6771  %> 
    6872  </ul> 
  • trunk/app/views/attachment/attach.rhtml

    r511 r721  
    1818</form> 
    1919 
    20 <%= link_to(_('Permissions'), { :controller => 'data_permission', :action => 'preview', :id => (@asset_type ? @asset_type.id : @selected_asset.id), 
    21     :datatype => @file.class.to_s }, :popup => true) %><br/> 
     20<% if @enable_user_permissions -%> 
     21  <%= link_to(_('Permissions'), { :controller => 'data_permission', :action => 'preview', 
     22              :id => (@asset_type ? @asset_type.id : @selected_asset.id), 
     23              :datatype => @file.class.to_s }, :popup => true) %><br/> 
     24<% end -%> 
  • trunk/app/views/attachment/view.rhtml

    r542 r721  
    3535  <tr> 
    3636    <td colspan="2" class="actions"> 
    37       <%= link_to(image_tag('16x16/permissions.gif') + _('Permissions'), {:controller => 'data_permission', :action => 'edit', :datatype => @file.class.to_s, :id => @file.id}) %> 
     37      <% if @enable_user_permissions -%> 
     38        <%= link_to(image_tag('16x16/permissions.gif') + _('Permissions'), {:controller => 'data_permission', :action => 'edit', :datatype => @file.class.to_s, :id => @file.id}) %> 
     39      <% end -%> 
    3840      <%= link_to(image_tag('16x16/download.png') + _('Download'), { :action => 'download', :id => @file.id }) %> 
    3941    </td> 
  • trunk/app/views/form/_creation_form.rhtml

    r709 r721  
    5050  <% if action == 'create' -%> 
    5151    <%= buttons_table(_('Done'), {:action => 'list'}) %> 
    52     <%= link_to(_('Permissions'), { :controller => 'data_permission', :action => 'preview', :id => @selected_asset.id, :datatype => 'Form', :groups => @preview_permissions }, :popup => true) %><br/> 
     52    <% if @enable_user_permissions -%> 
     53      <%= link_to(_('Permissions'), { :controller => 'data_permission', :action => 'preview', :id => @selected_asset.id, :datatype => 'Form', :groups => @preview_permissions }, :popup => true) %><br/> 
     54    <% end -%> 
    5355  <% elsif not preview -%> 
    5456    <%= buttons_table(_('Save changes'), {:action => 'view', :id => form.id}) %> 
  • trunk/app/views/form/view.rhtml

    r649 r721  
    3636      <td><%= link_to(image_tag('16x16/create.gif') + _('Create associated task'), { :controller => 'task', :action => 'create', :form_id => @form.id }) %></td> 
    3737    <% end -%> 
    38     <td><%= link_to(image_tag('16x16/permissions.gif') + _('Permissions'), 
    39                     {:controller => 'data_permission', :action => 'edit', 
    40                      :datatype => 'Form', :id => @form.id}) %></td> 
     38    <% if @enable_user_permissions -%> 
     39      <td><%= link_to(image_tag('16x16/permissions.gif') + _('Permissions'), 
     40                      {:controller => 'data_permission', :action => 'edit', 
     41                       :datatype => 'Form', :id => @form.id}) %></td> 
     42    <% end -%> 
    4143    <td><%= link_to(image_tag('16x16/download.png') + _('Download'), 
    4244                    {:action => 'download', :id => @form.id}) %></td> 
  • trunk/app/views/layouts/mainlevel.rhtml

    r719 r721  
    1010  top_menus = [] 
    1111  actions = [] 
     12end 
     13 
     14# If user permissions are disabled remove some menu items 
     15unless @enable_user_permissions 
     16  actions = actions.reject { |item| item.controller == 'asset_permission' } 
    1217end 
    1318-%> 
  • trunk/app/views/task/create.rhtml

    r592 r721  
    4646</form> 
    4747 
    48 <%= link_to(_('Permissions'), { :controller => 'data_permission', :action => 'preview', :id => @selected_asset.id, :datatype => 'Task' }, :popup => true) %><br/> 
     48<% if @enable_user_permissions -%> 
     49  <%= link_to(_('Permissions'), { :controller => 'data_permission', :action => 'preview', :id => @selected_asset.id, :datatype => 'Task' }, :popup => true) %><br/> 
     50<% end -%> 
    4951 
    5052<script type="text/javascript"> 
  • trunk/app/views/task/view.rhtml

    r592 r721  
    4444        <%= radio_button_tag('task_action', 'leave', true) %><%= _('Leave as closed') %><br/> 
    4545        <%= radio_button_tag('task_action', 'reopen') %><%= _('Reopen task') %><br/> 
    46     <% end -%>     
     46    <% end -%> 
    4747 
    4848    <h4><%= _('Comments') %></h4> 
     
    7575    <td><%= link_to(image_tag('16x16/move_selected.gif') + _('Move'), 
    7676                    {:action=>'move', :id => @task.id}) %></td> 
    77     <td><%= link_to(image_tag('16x16/permissions.gif') + _('Permissions'), 
    78                     {:controller => 'data_permission', :action => 'edit', 
    79                      :datatype => 'Task', :id => @task.id}) %></td> 
     77    <% if @enable_user_permissions -%> 
     78      <td><%= link_to(image_tag('16x16/permissions.gif') + _('Permissions'), 
     79                      {:controller => 'data_permission', :action => 'edit', 
     80                      :datatype => 'Task', :id => @task.id}) %></td> 
     81    <% end -%> 
    8082    <td><%= link_to(image_tag('16x16/download.png') + _('Download'), 
    8183                    {:action => 'download', :id => @task.id}) %></td> 
  • trunk/config/menu.rb

    r715 r721  
    9494                      Page.new('user_group', 'users') 
    9595                    ), 
     96                    MenuButton.new(_('Settings'), '22x22/settings.gif', 
     97                      MenuItem.new(_('Edit'), 'setting', 'access_control', '16x16/edit.gif') 
     98                    ), 
    9699                    MenuButton.new(_('Keyrings'), '22x22/menu_permission.gif', 
    97100                      MenuItem.new(_('List'), 'keyring', 'list', '16x16/list.gif'), 
  • trunk/doc/manual/latex/tex/configuration_section.tex

    r713 r721  
    204204\subsection{Access control} 
    205205\label{subsec:access_control} 
    206 Access control menu groups together the menus needed in configuring access control. These menus are: Keys, Keyrings, User groups and User accounts. 
     206Access control menu groups together the menus needed in configuring access control. These menus are: Keys, Keyrings, Settings, User groups and User accounts. 
    207207 
    208208\subsection{Keys} 
     
    237237\paragraph{Create} 
    238238You can create a new keyring by using the Create function. Enter information for the keyring to the creation form and submit it by selecting the 'Create' button. You can copy keys from an existing keyring to the created keyring by choosing the 'Copy keys from an existing keyring' option and by selecting a keyring from the selection before pushing the 'Create' button. In many cases this can ease the keyring creation, since adding keys to the created keyring one-by-one can be a laborious task. 
     239 
     240\subsection{Settings} 
     241\label{subsec:settings} 
     242In the Settings menu you can edit access control settings. 
     243 
     244The 'Enable the user permission system for assets' setting enables you to choose whether you want to use the user permission system or not. By default the user permission system is disabled. If the level of access control provided by the keys and keyrings is sufficient for you, we recommend you to leave the user permission system disabled. If you need user specific user rights for assets and their data, you  can enable the user permission system. In this case see the sub-section~\ref{subsec:user_groups} for more information. 
    239245 
    240246\subsection{User groups} 
     
    295301Each asset in NorfelloCMMS OS can be associated with a customer. Usually a customer is a company or an organization or a person to whom you provide maintenance services. You can manage your customers in the 'Customers' menu. 
    296302 
    297 A customer also works as a user account for the 'Customer Interface' included in NorfelloCMMS OS. You can read more about the 'Customer Interface' in the chapter~\ref{ch:customer_interface}. So customers are also a bit like user accounts which we explained above. However customers can never access the user interface we have described above, so your confidential data can be kept safe. 
     303A customer also works as a user account for the 'Customer Interface' included in NorfelloCMMS OS. You can read more about the 'Customer Interface' in the section~\ref{sec:customer_interface}. So customers are also a bit like user accounts which we explained above. However customers can never access the user interface we have described above, so your confidential data can be kept safe. 
    298304 
    299305Each customer has the following fields where information is stored 
  • trunk/doc/manual/latex/tex/customer_interface.tex

    r712 r721  
    11\section{Customer interface} 
     2\label{sec:customer_interface} 
    23The sole purpose of the Customer interface is to help you to serve your customers better.  In the Customer interface your customers can: 
    34\begin{itemize} 
  • trunk/test/functional/asset_controller_test.rb

    r718 r721  
    1111    @request    = ActionController::TestRequest.new 
    1212    @response   = ActionController::TestResponse.new 
     13 
     14    setup_settings 
    1315 
    1416    @ref_url = 'http://test.host/redirect/back' 
  • trunk/test/functional/asset_field_controller_test.rb

    r707 r721  
    1010    @request    = ActionController::TestRequest.new 
    1111    @response   = ActionController::TestResponse.new 
     12 
     13    setup_settings 
    1214 
    1315    @user_group = create_user_group('Admins') 
  • trunk/test/functional/asset_permission_controller_test.rb

    r718 r721  
    1010    @request    = ActionController::TestRequest.new 
    1111    @response   = ActionController::TestResponse.new 
     12 
     13    setup_settings 
    1214 
    1315    # The service request task type 
  • trunk/test/functional/search_controller_test.rb

    r718 r721  
    1414    @ref_url = 'http://test.host/redirect/back' 
    1515    @request.env['HTTP_REFERER'] = @ref_url 
     16 
     17    setup_settings 
    1618 
    1719    # The service request task type 
  • trunk/test/test_helper.rb

    r718 r721  
    4040 
    4141  # Add more helper methods to be used by all tests here... 
     42 
     43  # Method: setup_settings 
     44  # ====================== 
     45  # Sets up "hardcoded" system settings 
     46  # 
     47  def setup_settings(enable_user_permissions = true) 
     48    Setting.set('enable_user_permissions', enable_user_permissions) 
     49    Setting.load_settings 
     50  end 
    4251 
    4352  # Creates an asset, a user, a user group and a keyring. 
     
    4857    @ref_url = 'http://test.host/redirect/back' 
    4958    @request.env['HTTP_REFERER'] = @ref_url 
     59 
     60    setup_settings 
    5061 
    5162    # The service request task type 
  • trunk/test/unit/asset_test.rb

    r710 r721  
    44 
    55  def setup 
     6    setup_settings 
     7 
    68    @user_group = create_user_group('Admins') 
    79    @user = create_user('admin') 
     
    11651167  end 
    11661168 
     1169  # Method: test_permissions_disabled 
     1170  # ================================= 
     1171  # Check that the asset permissions can be disabled with the setting. 
     1172  # 
     1173  def test_permissions_disabled 
     1174    # Disable the user permission system. 
     1175    setup_settings(false) 
     1176 
     1177    # User without any permissions 
     1178    UserAccount.current_user = create_user('test') 
     1179 
     1180    # All permission quering methods have to return true. 
     1181    # 
     1182    # It might seem odd to grant the edit_permissions permission. However, 
     1183    # it's needed when the use_parents_permissions hierarchy is updated - 
     1184    # This happens when the permission system is enabled. 
     1185    # 
     1186    assert_equal true, @root.authorized_to_read? 
     1187    assert_equal true, @root.authorized_to_edit? 
     1188    assert_equal true, @root.authorized_to_edit_permissions? 
     1189    assert_equal true, @root.authorized_to_remove? 
     1190    assert_equal true, @root.authorized_to_create_subasset? 
     1191    assert_equal true, @root.authorized_to_create_task? 
     1192    assert_equal true, @root.authorized_to_create_form? 
     1193    assert_equal true, @root.authorized_to_attach_file? 
     1194    assert_equal true, @root.authorized_to_edit_branch? 
     1195    assert_equal true, @root.authorized_to_remove_branch? 
     1196    assert_equal true, @root.authorized_to_clone? 
     1197    assert_equal true, @unauthorized.authorized_to_clone? 
     1198    assert_equal false, @root.authorized_to_move? 
     1199    assert_equal true, @unauthorized.authorized_to_move? 
     1200 
     1201    # All finder methods have to return all assets 
     1202    all_assets = Asset.find(:all, :order => 'id') 
     1203    assert_equal all_assets, Asset.find_authorized_to_read(:all, :order => 'id') 
     1204    assert_equal all_assets, Asset.find_authorized_to_edit(:all, :order => 'id') 
     1205    assert_equal all_assets, Asset.find_authorized_to(:edit_permissions, [:all, {:order => 'id'}]) 
     1206    assert_equal all_assets, Asset.find_authorized_to(:edit_permissions, [:all, {:order => 'id'}]) 
     1207    assert_equal all_assets, Asset.find_authorized_to(:remove, [:all, {:order => 'id'}]) 
     1208    assert_equal all_assets, Asset.find_authorized_to(:create_subasset, [:all, {:order => 'id'}]) 
     1209    assert_equal all_assets, Asset.find_authorized_to(:create_task, [:all, {:order => 'id'}]) 
     1210    assert_equal all_assets, Asset.find_authorized_to(:create_form, [:all, {:order => 'id'}]) 
     1211    assert_equal all_assets, Asset.find_authorized_to(:attach_file, [:all, {:order => 'id'}]) 
     1212 
     1213    # Check callbacks work. 
     1214    # 
     1215    # Create an asset 
     1216    asset = Asset.new(:code => 'NEW', :name => 'New asset') 
     1217    asset.parent = @root 
     1218    assert_equal true, asset.save 
     1219    assert_equal false, asset.new_record? 
     1220    assert_equal true, asset.errors.empty? 
     1221    assert_equal true, asset.use_parents_permissions 
     1222    assert_equal true, asset.user_groups.empty? 
     1223    # 
     1224    # Update asset 
     1225    asset.name += ' - Edited' 
     1226    assert_equal true, asset.save