@@ -114,10 +114,15 class ApplicationController < ActionController::Base | |||
|
114 | 114 | end |
|
115 | 115 | |
|
116 | 116 | # Authorize the user for the requested action |
|
117 | def authorize(ctrl = params[:controller], action = params[:action]) | |
|
118 | allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project) | |
|
117 | def authorize(ctrl = params[:controller], action = params[:action], global = false) | |
|
118 | allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project, :global => global) | |
|
119 | 119 | allowed ? true : deny_access |
|
120 | 120 | end |
|
121 | ||
|
122 | # Authorize the user for the requested action outside a project | |
|
123 | def authorize_global(ctrl = params[:controller], action = params[:action], global = true) | |
|
124 | authorize(ctrl, action, global) | |
|
125 | end | |
|
121 | 126 | |
|
122 | 127 | # make sure that the user is a member of the project (or admin) if project is private |
|
123 | 128 | # used as a before_filter for actions that do not require any particular permission on the project |
@@ -26,7 +26,8 class ProjectsController < ApplicationController | |||
|
26 | 26 | before_filter :find_project, :except => [ :index, :list, :add, :copy, :activity ] |
|
27 | 27 | before_filter :find_optional_project, :only => :activity |
|
28 | 28 | before_filter :authorize, :except => [ :index, :list, :add, :copy, :archive, :unarchive, :destroy, :activity ] |
|
29 | before_filter :require_admin, :only => [ :add, :copy, :archive, :unarchive, :destroy ] | |
|
29 | before_filter :authorize_global, :only => :add | |
|
30 | before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] | |
|
30 | 31 | accept_key_auth :activity |
|
31 | 32 | |
|
32 | 33 | after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller| |
@@ -75,9 +76,14 class ProjectsController < ApplicationController | |||
|
75 | 76 | @project.enabled_module_names = params[:enabled_modules] |
|
76 | 77 | if @project.save |
|
77 | 78 | @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id') |
|
79 | # Add current user as a project member if he is not admin | |
|
80 | unless User.current.admin? | |
|
81 | m = Member.new(:user => User.current, :roles => Role.builtin(false).find(:all, :order => 'position', :limit => 1)) | |
|
82 | @project.members << m | |
|
83 | end | |
|
78 | 84 | flash[:notice] = l(:notice_successful_create) |
|
79 |
redirect_to :controller => ' |
|
|
80 | end | |
|
85 | redirect_to :controller => 'projects', :action => 'settings', :id => @project | |
|
86 | end | |
|
81 | 87 | end |
|
82 | 88 | end |
|
83 | 89 |
@@ -277,6 +277,9 class User < ActiveRecord::Base | |||
|
277 | 277 | roles.detect {|role| (project.is_public? || role.member?) && role.allowed_to?(action)} |
|
278 | 278 | |
|
279 | 279 | elsif options[:global] |
|
280 | # Admin users are always authorized | |
|
281 | return true if admin? | |
|
282 | ||
|
280 | 283 | # authorize if user has at least one role that has this permission |
|
281 | 284 | roles = memberships.collect {|m| m.roles}.flatten.uniq |
|
282 | 285 | roles.detect {|r| r.allowed_to?(action)} || (self.logged? ? Role.non_member.allowed_to?(action) : Role.anonymous.allowed_to?(action)) |
@@ -1,5 +1,5 | |||
|
1 | 1 | <div class="contextual"> |
|
2 |
<%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'add'}, :class => 'icon icon-add') + ' |' if User.current.a |
|
|
2 | <%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'add'}, :class => 'icon icon-add') + ' |' if User.current.allowed_to?(:add_project, nil, :global => true) %> | |
|
3 | 3 | <%= link_to l(:label_issue_view_all), { :controller => 'issues' } %> | |
|
4 | 4 | <%= link_to l(:label_overall_activity), { :controller => 'projects', :action => 'activity' }%> |
|
5 | 5 | </div> |
@@ -796,3 +796,4 bg: | |||
|
796 | 796 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
797 | 797 | label_wiki_content_updated: Wiki page updated |
|
798 | 798 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
799 | permission_add_project: Create project |
@@ -829,3 +829,4 bs: | |||
|
829 | 829 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
830 | 830 | label_wiki_content_updated: Wiki page updated |
|
831 | 831 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
832 | permission_add_project: Create project |
@@ -799,3 +799,4 ca: | |||
|
799 | 799 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
800 | 800 | label_wiki_content_updated: Wiki page updated |
|
801 | 801 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
802 | permission_add_project: Create project |
@@ -802,3 +802,4 cs: | |||
|
802 | 802 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
803 | 803 | label_wiki_content_updated: Wiki page updated |
|
804 | 804 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
805 | permission_add_project: Create project |
@@ -829,3 +829,4 da: | |||
|
829 | 829 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
830 | 830 | label_wiki_content_updated: Wiki page updated |
|
831 | 831 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
832 | permission_add_project: Create project |
@@ -828,3 +828,4 de: | |||
|
828 | 828 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
829 | 829 | label_wiki_content_updated: Wiki page updated |
|
830 | 830 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
831 | permission_add_project: Create project |
@@ -292,6 +292,7 en: | |||
|
292 | 292 | setting_openid: Allow OpenID login and registration |
|
293 | 293 | setting_password_min_length: Minimum password length |
|
294 | 294 | |
|
295 | permission_add_project: Create project | |
|
295 | 296 | permission_edit_project: Edit project |
|
296 | 297 | permission_select_project_modules: Select project modules |
|
297 | 298 | permission_manage_members: Manage members |
@@ -849,3 +849,4 es: | |||
|
849 | 849 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
850 | 850 | label_wiki_content_updated: Wiki page updated |
|
851 | 851 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
852 | permission_add_project: Create project |
@@ -839,3 +839,4 fi: | |||
|
839 | 839 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
840 | 840 | label_wiki_content_updated: Wiki page updated |
|
841 | 841 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
842 | permission_add_project: Create project |
@@ -324,6 +324,7 fr: | |||
|
324 | 324 | setting_openid: "Autoriser l'authentification et l'enregistrement OpenID" |
|
325 | 325 | setting_password_min_length: Longueur minimum des mots de passe |
|
326 | 326 | |
|
327 | permission_add_project: CrΓ©er un projet | |
|
327 | 328 | permission_edit_project: Modifier le projet |
|
328 | 329 | permission_select_project_modules: Choisir les modules |
|
329 | 330 | permission_manage_members: GΓ©rer les members |
@@ -828,3 +828,4 gl: | |||
|
828 | 828 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
829 | 829 | label_wiki_content_updated: Wiki page updated |
|
830 | 830 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
831 | permission_add_project: Create project |
@@ -811,3 +811,4 he: | |||
|
811 | 811 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
812 | 812 | label_wiki_content_updated: Wiki page updated |
|
813 | 813 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
814 | permission_add_project: Create project |
@@ -834,3 +834,4 | |||
|
834 | 834 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
835 | 835 | label_wiki_content_updated: Wiki page updated |
|
836 | 836 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
837 | permission_add_project: Create project |
@@ -814,3 +814,4 it: | |||
|
814 | 814 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
815 | 815 | label_wiki_content_updated: Wiki page updated |
|
816 | 816 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
817 | permission_add_project: Create project |
@@ -827,3 +827,4 ja: | |||
|
827 | 827 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
828 | 828 | label_wiki_content_updated: Wiki page updated |
|
829 | 829 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
830 | permission_add_project: Create project |
@@ -858,3 +858,4 ko: | |||
|
858 | 858 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
859 | 859 | label_wiki_content_updated: Wiki page updated |
|
860 | 860 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
861 | permission_add_project: Create project |
@@ -839,3 +839,4 lt: | |||
|
839 | 839 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
840 | 840 | label_wiki_content_updated: Wiki page updated |
|
841 | 841 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
842 | permission_add_project: Create project |
@@ -784,3 +784,4 nl: | |||
|
784 | 784 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
785 | 785 | label_wiki_content_updated: Wiki page updated |
|
786 | 786 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
787 | permission_add_project: Create project |
@@ -801,3 +801,4 | |||
|
801 | 801 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
802 | 802 | label_wiki_content_updated: Wiki page updated |
|
803 | 803 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
804 | permission_add_project: Create project |
@@ -832,3 +832,4 pl: | |||
|
832 | 832 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
833 | 833 | label_wiki_content_updated: Wiki page updated |
|
834 | 834 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
835 | permission_add_project: Create project |
@@ -834,3 +834,4 pt-BR: | |||
|
834 | 834 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
835 | 835 | label_wiki_content_updated: Wiki page updated |
|
836 | 836 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
837 | permission_add_project: Create project |
@@ -820,3 +820,4 pt: | |||
|
820 | 820 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
821 | 821 | label_wiki_content_updated: Wiki page updated |
|
822 | 822 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
823 | permission_add_project: Create project |
@@ -799,3 +799,4 ro: | |||
|
799 | 799 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
800 | 800 | label_wiki_content_updated: Wiki page updated |
|
801 | 801 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
802 | permission_add_project: Create project |
@@ -926,3 +926,4 ru: | |||
|
926 | 926 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
927 | 927 | label_wiki_content_updated: Wiki page updated |
|
928 | 928 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
929 | permission_add_project: Create project |
@@ -800,3 +800,4 sk: | |||
|
800 | 800 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
801 | 801 | label_wiki_content_updated: Wiki page updated |
|
802 | 802 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
803 | permission_add_project: Create project |
@@ -798,3 +798,4 sl: | |||
|
798 | 798 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
799 | 799 | label_wiki_content_updated: Wiki page updated |
|
800 | 800 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
801 | permission_add_project: Create project |
@@ -822,3 +822,4 | |||
|
822 | 822 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
823 | 823 | label_wiki_content_updated: Wiki page updated |
|
824 | 824 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
825 | permission_add_project: Create project |
@@ -856,3 +856,4 sv: | |||
|
856 | 856 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
857 | 857 | label_wiki_content_updated: Wiki page updated |
|
858 | 858 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
859 | permission_add_project: Create project |
@@ -799,3 +799,4 th: | |||
|
799 | 799 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
800 | 800 | label_wiki_content_updated: Wiki page updated |
|
801 | 801 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
802 | permission_add_project: Create project |
@@ -835,3 +835,4 tr: | |||
|
835 | 835 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
836 | 836 | label_wiki_content_updated: Wiki page updated |
|
837 | 837 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
838 | permission_add_project: Create project |
@@ -798,3 +798,4 uk: | |||
|
798 | 798 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
799 | 799 | label_wiki_content_updated: Wiki page updated |
|
800 | 800 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
801 | permission_add_project: Create project |
@@ -868,3 +868,4 vi: | |||
|
868 | 868 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
869 | 869 | label_wiki_content_updated: Wiki page updated |
|
870 | 870 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
871 | permission_add_project: Create project |
@@ -906,3 +906,4 | |||
|
906 | 906 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
907 | 907 | label_wiki_content_updated: Wiki page updated |
|
908 | 908 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
909 | permission_add_project: Create project |
@@ -831,3 +831,4 zh: | |||
|
831 | 831 | mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}. |
|
832 | 832 | label_wiki_content_updated: Wiki page updated |
|
833 | 833 | mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}. |
|
834 | permission_add_project: Create project |
@@ -20,6 +20,7 REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs Bazaar Git Filesystem | |||
|
20 | 20 | Redmine::AccessControl.map do |map| |
|
21 | 21 | map.permission :view_project, {:projects => [:show, :activity]}, :public => true |
|
22 | 22 | map.permission :search_project, {:search => :index}, :public => true |
|
23 | map.permission :add_project, {:projects => :add}, :require => :loggedin | |
|
23 | 24 | map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member |
|
24 | 25 | map.permission :select_project_modules, {:projects => :modules}, :require => :member |
|
25 | 26 | map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member_login]}, :require => :member |
@@ -5,6 +5,7 roles_001: | |||
|
5 | 5 | builtin: 0 |
|
6 | 6 | permissions: | |
|
7 | 7 | --- |
|
8 | - :add_project | |
|
8 | 9 | - :edit_project |
|
9 | 10 | - :manage_members |
|
10 | 11 | - :manage_versions |
@@ -89,6 +89,56 class ProjectsControllerTest < Test::Unit::TestCase | |||
|
89 | 89 | ) |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | def test_get_add | |
|
93 | @request.session[:user_id] = 1 | |
|
94 | get :add | |
|
95 | assert_response :success | |
|
96 | assert_template 'add' | |
|
97 | end | |
|
98 | ||
|
99 | def test_get_add_by_non_admin | |
|
100 | @request.session[:user_id] = 2 | |
|
101 | get :add | |
|
102 | assert_response :success | |
|
103 | assert_template 'add' | |
|
104 | end | |
|
105 | ||
|
106 | def test_post_add | |
|
107 | @request.session[:user_id] = 1 | |
|
108 | post :add, :project => { :name => "blog", | |
|
109 | :description => "weblog", | |
|
110 | :identifier => "blog", | |
|
111 | :is_public => 1, | |
|
112 | :custom_field_values => { '3' => 'Beta' } | |
|
113 | } | |
|
114 | assert_redirected_to '/projects/blog/settings' | |
|
115 | ||
|
116 | project = Project.find_by_name('blog') | |
|
117 | assert_kind_of Project, project | |
|
118 | assert_equal 'weblog', project.description | |
|
119 | assert_equal true, project.is_public? | |
|
120 | end | |
|
121 | ||
|
122 | def test_post_add_by_non_admin | |
|
123 | @request.session[:user_id] = 2 | |
|
124 | post :add, :project => { :name => "blog", | |
|
125 | :description => "weblog", | |
|
126 | :identifier => "blog", | |
|
127 | :is_public => 1, | |
|
128 | :custom_field_values => { '3' => 'Beta' } | |
|
129 | } | |
|
130 | assert_redirected_to '/projects/blog/settings' | |
|
131 | ||
|
132 | project = Project.find_by_name('blog') | |
|
133 | assert_kind_of Project, project | |
|
134 | assert_equal 'weblog', project.description | |
|
135 | assert_equal true, project.is_public? | |
|
136 | ||
|
137 | # User should be added as a project member | |
|
138 | assert User.find(2).member_of?(project) | |
|
139 | assert_equal 1, project.members.size | |
|
140 | end | |
|
141 | ||
|
92 | 142 | def test_show_routing |
|
93 | 143 | assert_routing( |
|
94 | 144 | {:method => :get, :path => '/projects/test'}, |
@@ -39,28 +39,4 class AdminTest < ActionController::IntegrationTest | |||
|
39 | 39 | locked_user = User.try_to_login("psmith", "psmith09") |
|
40 | 40 | assert_equal nil, locked_user |
|
41 | 41 | end |
|
42 | ||
|
43 | def test_add_project | |
|
44 | log_user("admin", "admin") | |
|
45 | get "projects/new" | |
|
46 | assert_response :success | |
|
47 | assert_template "projects/add" | |
|
48 | post "projects", :project => { :name => "blog", | |
|
49 | :description => "weblog", | |
|
50 | :identifier => "blog", | |
|
51 | :is_public => 1, | |
|
52 | :custom_field_values => { '3' => 'Beta' } | |
|
53 | } | |
|
54 | assert_redirected_to "admin/projects" | |
|
55 | assert_equal 'Successful creation.', flash[:notice] | |
|
56 | ||
|
57 | project = Project.find_by_name("blog") | |
|
58 | assert_kind_of Project, project | |
|
59 | assert_equal "weblog", project.description | |
|
60 | assert_equal true, project.is_public? | |
|
61 | ||
|
62 | get "admin/projects" | |
|
63 | assert_response :success | |
|
64 | assert_template "admin/projects" | |
|
65 | end | |
|
66 | 42 | end |
General Comments 0
You need to be logged in to leave comments.
Login now