openproject-global_roles 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +15 -0
  2. data/CHANGELOG.md +22 -0
  3. data/README.md +89 -0
  4. data/app/assets/javascripts/global_roles/global_roles.js +91 -0
  5. data/app/assets/javascripts/global_roles/principal_roles.js +51 -0
  6. data/app/assets/stylesheets/global_roles/global_roles.css +18 -0
  7. data/app/controllers/principal_roles_controller.rb +139 -0
  8. data/app/models/global_role.rb +46 -0
  9. data/app/models/principal_role.rb +29 -0
  10. data/app/views/principal_roles/_errors.html.erb +13 -0
  11. data/app/views/principal_roles/_show_table_row.html.erb +28 -0
  12. data/app/views/principal_roles/index.html.erb +47 -0
  13. data/app/views/roles/_form.html.erb +52 -0
  14. data/app/views/roles/_global_attributes.html.erb +12 -0
  15. data/app/views/roles/_global_form.html.erb +12 -0
  16. data/app/views/roles/_member_attributes.html.erb +17 -0
  17. data/app/views/roles/_member_form.html.erb +39 -0
  18. data/app/views/roles/_permissions.html.erb +27 -0
  19. data/app/views/roles/edit.html.erb +20 -0
  20. data/app/views/roles/index.html.erb +57 -0
  21. data/app/views/roles/new.html.erb +18 -0
  22. data/app/views/shared/_global_roles_header.html.erb +16 -0
  23. data/app/views/users/_available_global_role.html.erb +14 -0
  24. data/app/views/users/_available_global_roles.html.erb +32 -0
  25. data/app/views/users/_global_roles.html.erb +33 -0
  26. data/config/locales/de.yml +11 -0
  27. data/config/locales/en.yml +11 -0
  28. data/config/routes.rb +14 -0
  29. data/db/migrate/001_sti_for_roles.rb +34 -0
  30. data/doc/COPYRIGHT.rdoc +16 -0
  31. data/doc/GPL.txt +674 -0
  32. data/lib/open_project/global_roles.rb +16 -0
  33. data/lib/open_project/global_roles/engine.rb +89 -0
  34. data/lib/open_project/global_roles/patches.rb +13 -0
  35. data/lib/open_project/global_roles/patches/access_control_patch.rb +41 -0
  36. data/lib/open_project/global_roles/patches/permission_patch.rb +49 -0
  37. data/lib/open_project/global_roles/patches/principal_patch.rb +24 -0
  38. data/lib/open_project/global_roles/patches/role_patch.rb +47 -0
  39. data/lib/open_project/global_roles/patches/roles_controller_patch.rb +62 -0
  40. data/lib/open_project/global_roles/patches/roles_helper_patch.rb +27 -0
  41. data/lib/open_project/global_roles/patches/user_patch.rb +24 -0
  42. data/lib/open_project/global_roles/patches/users_controller_patch.rb +34 -0
  43. data/lib/open_project/global_roles/patches/users_helper_patch.rb +39 -0
  44. data/lib/open_project/global_roles/principal_allowance_evaluator/global.rb +24 -0
  45. data/lib/open_project/global_roles/version.rb +16 -0
  46. data/lib/openproject-global_roles.rb +12 -0
  47. data/spec/controllers/principal_roles_controller_spec.rb +163 -0
  48. data/spec/controllers/roles_controller_spec.rb +315 -0
  49. data/spec/controllers/users_controller_spec.rb +57 -0
  50. data/spec/factories/global_role_factory.rb +16 -0
  51. data/spec/factories/principal_role_factory.rb +17 -0
  52. data/spec/lib/access_control_spec.rb +56 -0
  53. data/spec/lib/global_roles/principal_allowance_evaluator/global_spec.rb +84 -0
  54. data/spec/lib/loader_spec.rb +40 -0
  55. data/spec/lib/permission_spec.rb +41 -0
  56. data/spec/models/global_role_spec.rb +175 -0
  57. data/spec/models/principal_role_spec.rb +48 -0
  58. data/spec/models/principal_spec.rb +38 -0
  59. data/spec/models/role_spec.rb +43 -0
  60. data/spec/models/user_spec.rb +20 -0
  61. data/spec/plugin_spec_helper.rb +152 -0
  62. data/spec/spec_helper.rb +15 -0
  63. metadata +152 -0
@@ -0,0 +1,16 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ module OpenProject
13
+ module GlobalRoles
14
+ require "open_project/global_roles/engine"
15
+ end
16
+ end
@@ -0,0 +1,89 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ module OpenProject::GlobalRoles
13
+ class Engine < ::Rails::Engine
14
+ engine_name :openproject_global_roles
15
+
16
+ config.autoload_paths += Dir["#{config.root}/lib/"]
17
+
18
+ spec = Bundler.environment.specs['openproject-global_roles'][0]
19
+ initializer 'global_roles.register_plugin' do
20
+ require_dependency 'open_project/global_roles/patches/permission_patch'
21
+
22
+ Redmine::Plugin.register :openproject_global_roles do
23
+ name 'OpenProject Global Roles'
24
+ author ((spec.authors.kind_of? Array) ? spec.authors[0] : spec.authors)
25
+ author_url "http://finn.de"
26
+ description spec.description
27
+ version spec.version
28
+ url spec.homepage
29
+
30
+ requires_openproject ">= 3.0.0pre13"
31
+
32
+ Redmine::AccessControl.permission(:add_project).global = true
33
+ end
34
+ end
35
+
36
+ initializer 'global_roles.precompile_assets' do
37
+ Rails.application.config.assets.precompile += %w(global_roles.css global_roles.js)
38
+ end
39
+
40
+ # adds our factories to factory girl's load path
41
+ initializer "global_roles.register_factories", :after => "factory_girl.set_factory_paths" do |app|
42
+ FactoryGirl.definition_file_paths << File.expand_path(self.root.to_s + '/spec/factories') if defined?(FactoryGirl)
43
+ end
44
+
45
+ initializer 'global_roles.register_test_paths' do |app|
46
+ app.config.plugins_to_test_paths << self.root
47
+ end
48
+
49
+ config.before_configuration do |app|
50
+ # This is required for the routes to be loaded first
51
+ # as the routes should be prepended so they take precedence over the core.
52
+ app.config.paths['config/routes'].unshift File.join(File.dirname(__FILE__), "..", "..", "..", "config", "routes.rb")
53
+ end
54
+
55
+ initializer "global_roles.remove_duplicate_routes", :after => "add_routing_paths" do |app|
56
+ # removes duplicate entry from app.routes_reloader
57
+ # As we prepend the plugin's routes to the load_path up front and rails
58
+ # adds all engines' config/routes.rb later, we have double loaded the routes
59
+ # This is not harmful as such but leads to duplicate routes which decreases performance
60
+ app.routes_reloader.paths.uniq!
61
+ end
62
+
63
+
64
+ config.to_prepare do
65
+ require_dependency 'open_project/global_roles/patches'
66
+
67
+ # lib patches
68
+ require_dependency 'open_project/global_roles/patches/access_control_patch'
69
+ require_dependency 'open_project/global_roles/patches/permission_patch'
70
+
71
+ # Model Patches
72
+ require_dependency 'open_project/global_roles/patches/principal_patch'
73
+ require_dependency 'open_project/global_roles/patches/role_patch'
74
+ require_dependency 'open_project/global_roles/patches/user_patch'
75
+
76
+ # Controller Patches
77
+ require_dependency 'open_project/global_roles/patches/roles_controller_patch'
78
+ require_dependency 'open_project/global_roles/patches/users_controller_patch'
79
+
80
+ # Helper Patches
81
+ require_dependency 'open_project/global_roles/patches/roles_helper_patch'
82
+ require_dependency 'open_project/global_roles/patches/users_helper_patch'
83
+
84
+ User.register_allowance_evaluator OpenProject::GlobalRoles::PrincipalAllowanceEvaluator::Global
85
+ end
86
+ end
87
+ end
88
+
89
+
@@ -0,0 +1,13 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ module OpenProject::GlobalRoles::Patches
13
+ end
@@ -0,0 +1,41 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ module OpenProject::GlobalRoles::Patches
13
+ module AccessControlPatch
14
+ def self.included(base)
15
+ base.send(:extend, ClassMethods)
16
+
17
+ base.class_eval do
18
+ class << self
19
+ alias_method :available_project_modules_without_no_global, :available_project_modules unless method_defined?(:available_project_modules_without_no_global)
20
+ alias_method :available_project_modules, :available_project_modules_with_no_global
21
+ end
22
+ end
23
+ end
24
+
25
+ module ClassMethods
26
+ def available_project_modules_with_no_global
27
+ @available_project_modules = (
28
+ @permissions.reject{|p| p.global? }.collect(&:project_module) +
29
+ @project_modules_without_permissions
30
+ ).uniq.compact
31
+ available_project_modules_without_no_global
32
+ end
33
+
34
+ def global_permissions
35
+ @permissions.select {|p| p.global?}
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ Redmine::AccessControl.send(:include, OpenProject::GlobalRoles::Patches::AccessControlPatch)
@@ -0,0 +1,49 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ require_dependency 'redmine/access_control'
13
+
14
+ module OpenProject::GlobalRoles::Patches
15
+ module PermissionPatch
16
+ def self.included(base)
17
+ base.send(:include, InstanceMethods)
18
+
19
+ base.class_eval do
20
+ unloadable
21
+
22
+ alias_method_chain :initialize, :global_option
23
+ end
24
+ end
25
+
26
+ module InstanceMethods
27
+ def initialize_with_global_option(name, hash, options)
28
+ @global = options[:global] || false
29
+ initialize_without_global_option(name, hash, options)
30
+ end
31
+
32
+ def global?
33
+ @global || global_require
34
+ end
35
+
36
+ def global=(bool)
37
+ @global = bool
38
+ end
39
+
40
+ private
41
+
42
+ def global_require
43
+ @require && @require == :global
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ Redmine::AccessControl::Permission.send(:include, OpenProject::GlobalRoles::Patches::PermissionPatch)
@@ -0,0 +1,24 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ module OpenProject::GlobalRoles::Patches
13
+ module PrincipalPatch
14
+ def self.included(base)
15
+ base.class_eval do
16
+
17
+ has_many :principal_roles, :dependent => :destroy
18
+ has_many :global_roles, :through => :principal_roles, :source => :role
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ Principal.send(:include, OpenProject::GlobalRoles::Patches::PrincipalPatch)
@@ -0,0 +1,47 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ module OpenProject::GlobalRoles::Patches
13
+ module RolePatch
14
+ def self.included(base)
15
+ base.send(:include, InstanceMethods)
16
+ base.send(:extend, ClassMethods)
17
+
18
+
19
+ base.class_eval do
20
+ scope :givable, where(:builtin => 0, :type => 'Role').order('position')
21
+
22
+ class << self
23
+ alias_method :find_all_givable_without_no_global_roles, :find_all_givable unless method_defined?(:find_all_givable_without_no_global_roles)
24
+ alias_method :find_all_givable, :find_all_givable_with_no_global_roles
25
+ end
26
+
27
+ alias_method_chain :setable_permissions, :no_global_roles
28
+ end
29
+ end
30
+
31
+ module ClassMethods
32
+ def find_all_givable_with_no_global_roles
33
+ givable.all
34
+ end
35
+ end
36
+
37
+ module InstanceMethods
38
+ def setable_permissions_with_no_global_roles
39
+ setable_permissions = setable_permissions_without_no_global_roles
40
+ setable_permissions -= Redmine::AccessControl.global_permissions
41
+ setable_permissions
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ Role.send(:include, OpenProject::GlobalRoles::Patches::RolePatch)
@@ -0,0 +1,62 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ module OpenProject::GlobalRoles::Patches
13
+ module RolesControllerPatch
14
+ def self.included(base)
15
+ base.send(:include, InstanceMethods)
16
+
17
+ base.class_eval do
18
+ alias_method_chain :create, :global_roles
19
+ alias_method_chain :new, :global_roles
20
+ end
21
+ end
22
+
23
+ module InstanceMethods
24
+
25
+ def new_with_global_roles
26
+ new_without_global_roles
27
+
28
+ @member_permissions = (@role.setable_permissions || @permissions)
29
+ @global_permissions = GlobalRole.setable_permissions
30
+ end
31
+
32
+ def create_with_global_roles
33
+ if params['global_role']
34
+ create_global_role
35
+ else
36
+ #we have to duplicate unpatched behaviour here in order to set the parameters for the overwritten views
37
+ @role = Role.new(params[:role] || { :permissions => Role.non_member.permissions })
38
+ @member_permissions = (@role.setable_permissions || @permissions)
39
+ @global_permissions = GlobalRole.setable_permissions
40
+ create_without_global_roles
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def create_global_role
47
+ @role = GlobalRole.new params[:role]
48
+ if @role.save
49
+ flash[:notice] = l(:notice_successful_create)
50
+ redirect_to :action => 'index'
51
+ else
52
+ @roles = Role.all :order => 'builtin, position'
53
+ @member_permissions = Role.new.setable_permissions
54
+ @global_permissions = GlobalRole.setable_permissions
55
+ render :template => 'roles/new'
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ RolesController.send(:include, OpenProject::GlobalRoles::Patches::RolesControllerPatch)
@@ -0,0 +1,27 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ require_dependency "roles_helper"
13
+
14
+ module OpenProject::GlobalRoles::Patches
15
+ module RolesHelperPatch
16
+ def self.included(base)
17
+ base.class_eval do
18
+
19
+ def permissions_id permissions
20
+ "permissions_" + permissions[0].hash.to_s
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ RolesHelper.send(:include, OpenProject::GlobalRoles::Patches::RolesHelperPatch)
@@ -0,0 +1,24 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ module OpenProject::GlobalRoles::Patches
13
+ module UserPatch
14
+ def self.included(base)
15
+ base.class_eval do
16
+
17
+ has_many :principal_roles, :dependent => :destroy, :foreign_key => 'principal_id'
18
+ has_many :global_roles, :through => :principal_roles, :source => :role
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ User.send(:include, OpenProject::GlobalRoles::Patches::UserPatch)
@@ -0,0 +1,34 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ require_dependency "users_controller"
13
+
14
+ module OpenProject::GlobalRoles::Patches
15
+ module UsersControllerPatch
16
+ def self.included(base)
17
+ base.send(:include, InstanceMethods)
18
+
19
+ base.class_eval do
20
+
21
+ before_filter :add_global_roles, :only => [:edit]
22
+ end
23
+ end
24
+
25
+ module InstanceMethods
26
+ private
27
+ def add_global_roles
28
+ @global_roles = GlobalRole.all
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ UsersController.send(:include, OpenProject::GlobalRoles::Patches::UsersControllerPatch)
@@ -0,0 +1,39 @@
1
+ #-- copyright
2
+ # OpenProject is a project management system.
3
+ #
4
+ # Copyright (C) 2010-2013 the OpenProject Team
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License version 3.
8
+ #
9
+ # See doc/COPYRIGHT.rdoc for more details.
10
+ #++
11
+
12
+ require_dependency 'users_helper'
13
+
14
+ module OpenProject::GlobalRoles::Patches
15
+ module UsersHelperPatch
16
+ def self.included(base)
17
+ base.send(:include, InstanceMethods)
18
+
19
+ base.class_eval do
20
+
21
+ alias_method_chain :user_settings_tabs, :global_roles
22
+ end
23
+ end
24
+
25
+ module InstanceMethods
26
+
27
+ def user_settings_tabs_with_global_roles
28
+ tabs = user_settings_tabs_without_global_roles
29
+ @global_roles ||= GlobalRole.all
30
+ tabs << {:name => 'global_roles', :partial => 'users/global_roles', :label => "global_roles"}
31
+ tabs
32
+ end
33
+
34
+
35
+ end
36
+ end
37
+ end
38
+
39
+ UsersHelper.send(:include, OpenProject::GlobalRoles::Patches::UsersHelperPatch)