Changeset 721
- Timestamp:
- 11/08/07 13:08:10 (1 year ago)
- Files:
-
- trunk/app/controllers/application.rb (modified) (2 diffs)
- trunk/app/controllers/asset_permission_controller.rb (modified) (2 diffs)
- trunk/app/controllers/data_permission_controller.rb (modified) (2 diffs)
- trunk/app/controllers/setting_controller.rb (added)
- trunk/app/helpers/application_helper.rb (modified) (2 diffs)
- trunk/app/helpers/setting_helper.rb (added)
- trunk/app/models/asset.rb (modified) (13 diffs)
- trunk/app/models/asset_type.rb (modified) (2 diffs)
- trunk/app/models/protected_asset_data.rb (modified) (2 diffs)
- trunk/app/models/protected_data.rb (modified) (6 diffs)
- trunk/app/models/protector_model.rb (modified) (3 diffs)
- trunk/app/models/setting.rb (added)
- trunk/app/models/task.rb (modified) (2 diffs)
- trunk/app/models/user_account.rb (modified) (1 diff)
- trunk/app/views/asset_tree/_asset_tree.rhtml (modified) (1 diff)
- trunk/app/views/attachment/attach.rhtml (modified) (1 diff)
- trunk/app/views/attachment/view.rhtml (modified) (1 diff)
- trunk/app/views/form/_creation_form.rhtml (modified) (1 diff)
- trunk/app/views/form/view.rhtml (modified) (1 diff)
- trunk/app/views/layouts/mainlevel.rhtml (modified) (1 diff)
- trunk/app/views/setting (added)
- trunk/app/views/setting/access_control.rhtml (added)
- trunk/app/views/task/create.rhtml (modified) (1 diff)
- trunk/app/views/task/view.rhtml (modified) (2 diffs)
- trunk/config/menu.rb (modified) (1 diff)
- trunk/db/migrate/011_create_settings.rb (added)
- trunk/doc/manual/latex/tex/configuration_section.tex (modified) (3 diffs)
- trunk/doc/manual/latex/tex/customer_interface.tex (modified) (1 diff)
- trunk/public/images/22x22/settings.gif (added)
- trunk/test/functional/asset_controller_test.rb (modified) (1 diff)
- trunk/test/functional/asset_field_controller_test.rb (modified) (1 diff)
- trunk/test/functional/asset_permission_controller_test.rb (modified) (1 diff)
- trunk/test/functional/search_controller_test.rb (modified) (1 diff)
- trunk/test/functional/setting_controller_test.rb (added)
- trunk/test/test_helper.rb (modified) (2 diffs)
- trunk/test/unit/asset_test.rb (modified) (2 diffs)
- trunk/test/unit/asset_type_test.rb (modified) (1 diff)
- trunk/test/unit/assets_user_group_test.rb (modified) (1 diff)
- trunk/test/unit/attachment_test.rb (modified) (1 diff)
- trunk/test/unit/customer_test.rb (modified) (1 diff)
- trunk/test/unit/data_permission_profile_test.rb (modified) (1 diff)
- trunk/test/unit/data_permission_test.rb (modified) (1 diff)
- trunk/test/unit/form_template_test.rb (modified) (1 diff)
- trunk/test/unit/form_test.rb (modified) (1 diff)
- trunk/test/unit/form_type_test.rb (modified) (2 diffs)
- trunk/test/unit/notification_mailer_test.rb (modified) (1 diff)
- trunk/test/unit/protected_asset_data_test.rb (modified) (1 diff)
- trunk/test/unit/protected_asset_type_data_test.rb (modified) (1 diff)
- trunk/test/unit/protected_data_test.rb (modified) (2 diffs)
- trunk/test/unit/setting_test.rb (added)
- trunk/test/unit/task_template_test.rb (modified) (2 diffs)
- trunk/test/unit/task_test.rb (modified) (1 diff)
- trunk/test/unit/type_attachment_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/application.rb
r715 r721 21 21 layout 'mainlevel' 22 22 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 23 24 after_filter :reset_timedout_session, :process_model_events 24 25 … … 690 691 @service_request_id = Task.find_authorized_to_read(:first, :conditions => conditions).id if @service_request_count == 1 691 692 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 692 703 end trunk/app/controllers/asset_permission_controller.rb
r707 r721 14 14 class AssetPermissionController < ApplicationController 15 15 prepend_before_filter :login_required 16 append_before_filter : lock_asset, :enter_page_group16 append_before_filter :check_settings, :lock_asset, :enter_page_group 17 17 LOCK_DURATION = 1.hour 18 18 … … 318 318 return true 319 319 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 320 328 end trunk/app/controllers/data_permission_controller.rb
r651 r721 13 13 class DataPermissionController < ApplicationController 14 14 prepend_before_filter :login_required 15 append_before_filter :check_settings 15 16 16 17 # Function: edit … … 121 122 @object = Object.const_get(datatype).find(id) 122 123 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 123 132 end trunk/app/helpers/application_helper.rb
r710 r721 703 703 end 704 704 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 # 705 711 def find_asset_tree_nodes(group_ids, parent_id = nil, open_parent = true, branch_depth = nil) 706 712 asset_code_and_name_sql = ActiveRecord::Base.connection.sql_concat(:code, ' (', :name, ')') … … 754 760 end 755 761 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 756 807 # Select tag that support option collections. The collection is converted 757 808 # to option tags with options_for_select. trunk/app/models/asset.rb
r710 r721 97 97 # Overwrite the implementation in the parent class 98 98 def Asset.find_authorized_to_read(*args) 99 return super unless UserAccount.current_user. class == Customer99 return super unless UserAccount.current_user.instance_of?(Customer) 100 100 101 101 args = add_conditions_to_find_arguments(args, "#{self.table_name}.customer_id = ?", [UserAccount.current_user.id]) … … 115 115 # 116 116 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 118 120 119 121 group_ids = UserAccount.current_user.user_groups.map {|g| g.id } … … 175 177 end 176 178 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 177 195 # Function: full_code 178 196 # =================== … … 264 282 265 283 # 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 267 287 268 288 return !((UserAccount.current_user.user_groups & self.user_groups).empty?) … … 283 303 def authorized_to_create_task? 284 304 # Customer is authorized to create tasks to his assets 285 return (self.customer == UserAccount.current_user) if UserAccount.current_user. class == Customer305 return (self.customer == UserAccount.current_user) if UserAccount.current_user.instance_of?(Customer) 286 306 287 307 return authorized_to(:create_task) … … 597 617 # :create_subasset, :edit_permissions, :remove. 598 618 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 600 622 601 623 authorized_user_groups = self.assets_user_groups.select { |aug| aug.send(operation) }.collect { |aug| aug.user_group } … … 755 777 # Cloning permission requires the reading permission to this asset and 756 778 # 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 #. 758 781 def authorized_to_clone? 759 782 return false unless authorized_to_read? 760 count_args = [:create_subasset]761 783 # Find ids of assets that have a child with the same code as this asset 762 784 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 765 796 return false 766 797 end … … 774 805 # to this asset and the permission to create a sub-asset to some asset(s) 775 806 # which this asset can be moved to. 807 # 776 808 def authorized_to_move? 777 809 return false unless not(is_root?) and authorized_to_edit? and authorized_to_edit_permissions? … … 779 811 exclude_parent_ids = Asset.find_all_by_code(self.code).map {|a| a.parent_id }.compact 780 812 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 782 820 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 783 842 end 784 843 … … 807 866 808 867 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 809 873 810 874 if self.parent.authorized_to_create_subasset? … … 829 893 end 830 894 831 unauthorized = false 895 unless Setting.enable_user_permissions 896 _info("Saving #{self.class}(id=#{self.id})") 897 return true 898 end 832 899 833 900 if locking_information_changed? and not (authorized_to_edit? or authorized_to_edit_permissions?) … … 874 941 if self.parent.nil? 875 942 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) 877 944 self.copy_permissions(self.parent.assets_user_groups) 878 945 end … … 1018 1085 # have to fulfill. 1019 1086 def Asset.count_authorized_to(operation, extra_conditions = nil) 1087 raise 'User permissions have to be enabled' unless Setting.enable_user_permissions 1088 1020 1089 return false unless UserAccount.current_user 1021 1090 user_group_ids = UserAccount.current_user.user_groups.map {|g| g.id } 1022 1091 return false if user_group_ids.empty? 1092 1023 1093 case operation 1024 1094 when :read trunk/app/models/asset_type.rb
r648 r721 29 29 # Returns true if the user is authorized to read this asset type 30 30 def authorized_to_read? 31 return true unless Setting.enable_user_permissions 32 31 33 self.assets.each { |asset| 32 34 return true if asset.authorized_to_read? … … 37 39 # Returns true if the user is authorized to create new instances of +datatype+ to this asset type 38 40 def authorized_to_create?(datatype) 41 return true unless Setting.enable_user_permissions 42 39 43 datatype = datatype.to_s.gsub(/^Type/, '') 40 44 trunk/app/models/protected_asset_data.rb
r707 r721 55 55 # Version of find that only retuns objects the user is authorized to perform +operation+ to. 56 56 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) 58 58 end 59 59 … … 62 62 return records_not_found(args) unless user = UserAccount.current_user 63 63 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 70 73 71 74 return self.find(*args) trunk/app/models/protected_data.rb
r720 r721 131 131 # See sub-classes for examples how this method can be used. 132 132 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 133 135 return records_not_found(args) unless user = UserAccount.current_user 134 136 … … 150 152 # See sub-classes for examples how this method can be used. 151 153 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 152 156 return 0 unless user = UserAccount.current_user 153 157 … … 258 262 end 259 263 264 return true unless Setting.enable_user_permissions 265 260 266 case operation 261 267 when :read … … 332 338 end 333 339 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 # 336 352 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 337 360 case UserAccount.current_user.class.to_s 338 361 when 'User' … … 340 363 _info("Creating permissions for a #{self.class} succeeded") if self.create_data_permissions_from_profiles(profiles) 341 364 when 'Customer' 342 # Everyone can read and edit data created by customers365 # 343 366 self.other_read = true 344 367 self.other_change_state = true if has_change_state_permission? … … 371 394 372 395 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 373 401 end 374 402 trunk/app/models/protector_model.rb
r707 r721 46 46 # Redefine this method in sub-classes - by default users are unauthorized to operate on all data. 47 47 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) 49 50 end 50 51 … … 52 53 # Redefine this method in sub-classes - by default users are unauthorized to operate on all data. 53 54 def authorized_to(operation) 55 return true unless Setting.enable_user_permissions 54 56 return false 55 57 end … … 68 70 _error("Have to be logged in to remove #{self.class}") 69 71 return false 72 end 73 74 unless Setting.enable_user_permissions 75 _info("Removing #{self.class}(id=#{self.id})") 76 return true 70 77 end 71 78 trunk/app/models/task.rb
r712 r721 309 309 # 310 310 def set_asset_if_customer 311 return true unless UserAccount.current_user.i s_a?(Customer)311 return true unless UserAccount.current_user.instance_of?(Customer) 312 312 return true if self.asset 313 313 asset = UserAccount.current_user.assets.find(:first, :order => 'id') … … 325 325 # 326 326 def set_task_type_if_customer 327 return true unless UserAccount.current_user.i s_a?(Customer)327 return true unless UserAccount.current_user.instance_of?(Customer) 328 328 self.task_type = TaskType.get_service_request_type 329 329 return true trunk/app/models/user_account.rb
r713 r721 10 10 # 11 11 # This model expects a certain database layout and its based on the name/login pattern. 12 # 13 # Inherits: 14 # --------- 15 # <CmmsBase> 12 16 # 13 17 class UserAccount < CmmsBase trunk/app/views/asset_tree/_asset_tree.rhtml
r636 r721 63 63 <ul class="root_tree"> 64 64 <%= 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 67 71 %> 68 72 </ul> trunk/app/views/attachment/attach.rhtml
r511 r721 18 18 </form> 19 19 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 35 35 <tr> 36 36 <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 -%> 38 40 <%= link_to(image_tag('16x16/download.png') + _('Download'), { :action => 'download', :id => @file.id }) %> 39 41 </td> trunk/app/views/form/_creation_form.rhtml
r709 r721 50 50 <% if action == 'create' -%> 51 51 <%= 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 -%> 53 55 <% elsif not preview -%> 54 56 <%= buttons_table(_('Save changes'), {:action => 'view', :id => form.id}) %> trunk/app/views/form/view.rhtml
r649 r721 36 36 <td><%= link_to(image_tag('16x16/create.gif') + _('Create associated task'), { :controller => 'task', :action => 'create', :form_id => @form.id }) %></td> 37 37 <% 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 -%> 41 43 <td><%= link_to(image_tag('16x16/download.png') + _('Download'), 42 44 {:action => 'download', :id => @form.id}) %></td> trunk/app/views/layouts/mainlevel.rhtml
r719 r721 10 10 top_menus = [] 11 11 actions = [] 12 end 13 14 # If user permissions are disabled remove some menu items 15 unless @enable_user_permissions 16 actions = actions.reject { |item| item.controller == 'asset_permission' } 12 17 end 13 18 -%> trunk/app/views/task/create.rhtml
r592 r721 46 46 </form> 47 47 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 -%> 49 51 50 52 <script type="text/javascript"> trunk/app/views/task/view.rhtml
r592 r721 44 44 <%= radio_button_tag('task_action', 'leave', true) %><%= _('Leave as closed') %><br/> 45 45 <%= radio_button_tag('task_action', 'reopen') %><%= _('Reopen task') %><br/> 46 <% end -%> 46 <% end -%> 47 47 48 48 <h4><%= _('Comments') %></h4> … … 75 75 <td><%= link_to(image_tag('16x16/move_selected.gif') + _('Move'), 76 76 {: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 -%> 80 82 <td><%= link_to(image_tag('16x16/download.png') + _('Download'), 81 83 {:action => 'download', :id => @task.id}) %></td> trunk/config/menu.rb
r715 r721 94 94 Page.new('user_group', 'users') 95 95 ), 96 MenuButton.new(_('Settings'), '22x22/settings.gif', 97 MenuItem.new(_('Edit'), 'setting', 'access_control', '16x16/edit.gif') 98 ), 96 99 MenuButton.new(_('Keyrings'), '22x22/menu_permission.gif', 97 100 MenuItem.new(_('List'), 'keyring', 'list', '16x16/list.gif'), trunk/doc/manual/latex/tex/configuration_section.tex
r713 r721 204 204 \subsection{Access control} 205 205 \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.206 Access control menu groups together the menus needed in configuring access control. These menus are: Keys, Keyrings, Settings, User groups and User accounts. 207 207 208 208 \subsection{Keys} … … 237 237 \paragraph{Create} 238 238 You 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} 242 In the Settings menu you can edit access control settings. 243 244 The '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. 239 245 240 246 \subsection{User groups} … … 295 301 Each 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. 296 302 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.303 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 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. 298 304 299 305 Each customer has the following fields where information is stored trunk/doc/manual/latex/tex/customer_interface.tex
r712 r721 1 1 \section{Customer interface} 2 \label{sec:customer_interface} 2 3 The sole purpose of the Customer interface is to help you to serve your customers better. In the Customer interface your customers can: 3 4 \begin{itemize} trunk/test/functional/asset_controller_test.rb
r718 r721 11 11 @request = ActionController::TestRequest.new 12 12 @response = ActionController::TestResponse.new 13 14 setup_settings 13 15 14 16 @ref_url = 'http://test.host/redirect/back' trunk/test/functional/asset_field_controller_test.rb
r707 r721 10 10 @request = ActionController::TestRequest.new 11 11 @response = ActionController::TestResponse.new 12 13 setup_settings 12 14 13 15 @user_group = create_user_group('Admins') trunk/test/functional/asset_permission_controller_test.rb
r718 r721 10 10 @request = ActionController::TestRequest.new 11 11 @response = ActionController::TestResponse.new 12 13 setup_settings 12 14 13 15 # The service request task type trunk/test/functional/search_controller_test.rb
r718 r721 14 14 @ref_url = 'http://test.host/redirect/back' 15 15 @request.env['HTTP_REFERER'] = @ref_url 16 17 setup_settings 16 18 17 19 # The service request task type trunk/test/test_helper.rb
r718 r721 40 40 41 41 # 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 42 51 43 52 # Creates an asset, a user, a user group and a keyring. … … 48 57 @ref_url = 'http://test.host/redirect/back' 49 58 @request.env['HTTP_REFERER'] = @ref_url 59 60 setup_settings 50 61 51 62 # The service request task type trunk/test/unit/asset_test.rb
r710 r721 4 4 5 5 def setup 6 setup_settings 7 6 8 @user_group = create_user_group('Admins') 7 9 @user = create_user('admin') … … 1165 1167 end 1166 1168 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