##// END OF EJS Templates
Ability to allow non-admin users to create projects (#1007)....
Jean-Philippe Lang -
r2651:8141110eb269
parent child
Show More
@@ -114,10 +114,15 class ApplicationController < ActionController::Base
114 end
114 end
115
115
116 # Authorize the user for the requested action
116 # Authorize the user for the requested action
117 def authorize(ctrl = params[:controller], action = params[:action])
117 def authorize(ctrl = params[:controller], action = params[:action], global = false)
118 allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project)
118 allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project, :global => global)
119 allowed ? true : deny_access
119 allowed ? true : deny_access
120 end
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 # make sure that the user is a member of the project (or admin) if project is private
127 # make sure that the user is a member of the project (or admin) if project is private
123 # used as a before_filter for actions that do not require any particular permission on the project
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 before_filter :find_project, :except => [ :index, :list, :add, :copy, :activity ]
26 before_filter :find_project, :except => [ :index, :list, :add, :copy, :activity ]
27 before_filter :find_optional_project, :only => :activity
27 before_filter :find_optional_project, :only => :activity
28 before_filter :authorize, :except => [ :index, :list, :add, :copy, :archive, :unarchive, :destroy, :activity ]
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 accept_key_auth :activity
31 accept_key_auth :activity
31
32
32 after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller|
33 after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller|
@@ -75,9 +76,14 class ProjectsController < ApplicationController
75 @project.enabled_module_names = params[:enabled_modules]
76 @project.enabled_module_names = params[:enabled_modules]
76 if @project.save
77 if @project.save
77 @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
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 flash[:notice] = l(:notice_successful_create)
84 flash[:notice] = l(:notice_successful_create)
79 redirect_to :controller => 'admin', :action => 'projects'
85 redirect_to :controller => 'projects', :action => 'settings', :id => @project
80 end
86 end
81 end
87 end
82 end
88 end
83
89
@@ -277,6 +277,9 class User < ActiveRecord::Base
277 roles.detect {|role| (project.is_public? || role.member?) && role.allowed_to?(action)}
277 roles.detect {|role| (project.is_public? || role.member?) && role.allowed_to?(action)}
278
278
279 elsif options[:global]
279 elsif options[:global]
280 # Admin users are always authorized
281 return true if admin?
282
280 # authorize if user has at least one role that has this permission
283 # authorize if user has at least one role that has this permission
281 roles = memberships.collect {|m| m.roles}.flatten.uniq
284 roles = memberships.collect {|m| m.roles}.flatten.uniq
282 roles.detect {|r| r.allowed_to?(action)} || (self.logged? ? Role.non_member.allowed_to?(action) : Role.anonymous.allowed_to?(action))
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 <div class="contextual">
1 <div class="contextual">
2 <%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'add'}, :class => 'icon icon-add') + ' |' if User.current.admin? %>
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 <%= link_to l(:label_issue_view_all), { :controller => 'issues' } %> |
3 <%= link_to l(:label_issue_view_all), { :controller => 'issues' } %> |
4 <%= link_to l(:label_overall_activity), { :controller => 'projects', :action => 'activity' }%>
4 <%= link_to l(:label_overall_activity), { :controller => 'projects', :action => 'activity' }%>
5 </div>
5 </div>
@@ -796,3 +796,4 bg:
796 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
796 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
797 label_wiki_content_updated: Wiki page updated
797 label_wiki_content_updated: Wiki page updated
798 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
829 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
830 label_wiki_content_updated: Wiki page updated
830 label_wiki_content_updated: Wiki page updated
831 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
799 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
800 label_wiki_content_updated: Wiki page updated
800 label_wiki_content_updated: Wiki page updated
801 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
802 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
803 label_wiki_content_updated: Wiki page updated
803 label_wiki_content_updated: Wiki page updated
804 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
829 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
830 label_wiki_content_updated: Wiki page updated
830 label_wiki_content_updated: Wiki page updated
831 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
828 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
829 label_wiki_content_updated: Wiki page updated
829 label_wiki_content_updated: Wiki page updated
830 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 setting_openid: Allow OpenID login and registration
292 setting_openid: Allow OpenID login and registration
293 setting_password_min_length: Minimum password length
293 setting_password_min_length: Minimum password length
294
294
295 permission_add_project: Create project
295 permission_edit_project: Edit project
296 permission_edit_project: Edit project
296 permission_select_project_modules: Select project modules
297 permission_select_project_modules: Select project modules
297 permission_manage_members: Manage members
298 permission_manage_members: Manage members
@@ -849,3 +849,4 es:
849 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
849 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
850 label_wiki_content_updated: Wiki page updated
850 label_wiki_content_updated: Wiki page updated
851 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
839 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
840 label_wiki_content_updated: Wiki page updated
840 label_wiki_content_updated: Wiki page updated
841 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 setting_openid: "Autoriser l'authentification et l'enregistrement OpenID"
324 setting_openid: "Autoriser l'authentification et l'enregistrement OpenID"
325 setting_password_min_length: Longueur minimum des mots de passe
325 setting_password_min_length: Longueur minimum des mots de passe
326
326
327 permission_add_project: CrΓ©er un projet
327 permission_edit_project: Modifier le projet
328 permission_edit_project: Modifier le projet
328 permission_select_project_modules: Choisir les modules
329 permission_select_project_modules: Choisir les modules
329 permission_manage_members: GΓ©rer les members
330 permission_manage_members: GΓ©rer les members
@@ -828,3 +828,4 gl:
828 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
828 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
829 label_wiki_content_updated: Wiki page updated
829 label_wiki_content_updated: Wiki page updated
830 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
811 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
812 label_wiki_content_updated: Wiki page updated
812 label_wiki_content_updated: Wiki page updated
813 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
834 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
835 label_wiki_content_updated: Wiki page updated
835 label_wiki_content_updated: Wiki page updated
836 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
814 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
815 label_wiki_content_updated: Wiki page updated
815 label_wiki_content_updated: Wiki page updated
816 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
827 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
828 label_wiki_content_updated: Wiki page updated
828 label_wiki_content_updated: Wiki page updated
829 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
858 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
859 label_wiki_content_updated: Wiki page updated
859 label_wiki_content_updated: Wiki page updated
860 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
839 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
840 label_wiki_content_updated: Wiki page updated
840 label_wiki_content_updated: Wiki page updated
841 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
784 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
785 label_wiki_content_updated: Wiki page updated
785 label_wiki_content_updated: Wiki page updated
786 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
801 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
802 label_wiki_content_updated: Wiki page updated
802 label_wiki_content_updated: Wiki page updated
803 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
832 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
833 label_wiki_content_updated: Wiki page updated
833 label_wiki_content_updated: Wiki page updated
834 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
834 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
835 label_wiki_content_updated: Wiki page updated
835 label_wiki_content_updated: Wiki page updated
836 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
820 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
821 label_wiki_content_updated: Wiki page updated
821 label_wiki_content_updated: Wiki page updated
822 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
799 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
800 label_wiki_content_updated: Wiki page updated
800 label_wiki_content_updated: Wiki page updated
801 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
926 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
927 label_wiki_content_updated: Wiki page updated
927 label_wiki_content_updated: Wiki page updated
928 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
800 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
801 label_wiki_content_updated: Wiki page updated
801 label_wiki_content_updated: Wiki page updated
802 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
798 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
799 label_wiki_content_updated: Wiki page updated
799 label_wiki_content_updated: Wiki page updated
800 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
822 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
823 label_wiki_content_updated: Wiki page updated
823 label_wiki_content_updated: Wiki page updated
824 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
856 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
857 label_wiki_content_updated: Wiki page updated
857 label_wiki_content_updated: Wiki page updated
858 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
799 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
800 label_wiki_content_updated: Wiki page updated
800 label_wiki_content_updated: Wiki page updated
801 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
835 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
836 label_wiki_content_updated: Wiki page updated
836 label_wiki_content_updated: Wiki page updated
837 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
798 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
799 label_wiki_content_updated: Wiki page updated
799 label_wiki_content_updated: Wiki page updated
800 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
868 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
869 label_wiki_content_updated: Wiki page updated
869 label_wiki_content_updated: Wiki page updated
870 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
906 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
907 label_wiki_content_updated: Wiki page updated
907 label_wiki_content_updated: Wiki page updated
908 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
831 mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
832 label_wiki_content_updated: Wiki page updated
832 label_wiki_content_updated: Wiki page updated
833 mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
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 Redmine::AccessControl.map do |map|
20 Redmine::AccessControl.map do |map|
21 map.permission :view_project, {:projects => [:show, :activity]}, :public => true
21 map.permission :view_project, {:projects => [:show, :activity]}, :public => true
22 map.permission :search_project, {:search => :index}, :public => true
22 map.permission :search_project, {:search => :index}, :public => true
23 map.permission :add_project, {:projects => :add}, :require => :loggedin
23 map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member
24 map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member
24 map.permission :select_project_modules, {:projects => :modules}, :require => :member
25 map.permission :select_project_modules, {:projects => :modules}, :require => :member
25 map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member_login]}, :require => :member
26 map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member_login]}, :require => :member
@@ -5,6 +5,7 roles_001:
5 builtin: 0
5 builtin: 0
6 permissions: |
6 permissions: |
7 ---
7 ---
8 - :add_project
8 - :edit_project
9 - :edit_project
9 - :manage_members
10 - :manage_members
10 - :manage_versions
11 - :manage_versions
@@ -89,6 +89,56 class ProjectsControllerTest < Test::Unit::TestCase
89 )
89 )
90 end
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 def test_show_routing
142 def test_show_routing
93 assert_routing(
143 assert_routing(
94 {:method => :get, :path => '/projects/test'},
144 {:method => :get, :path => '/projects/test'},
@@ -39,28 +39,4 class AdminTest < ActionController::IntegrationTest
39 locked_user = User.try_to_login("psmith", "psmith09")
39 locked_user = User.try_to_login("psmith", "psmith09")
40 assert_equal nil, locked_user
40 assert_equal nil, locked_user
41 end
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 end
42 end
General Comments 0
You need to be logged in to leave comments. Login now