end
# Authorize the user for the requested action
- def authorize(ctrl = params[:controller], action = params[:action])
- allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project)
+ def authorize(ctrl = params[:controller], action = params[:action], global = false)
+ allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project, :global => global)
allowed ? true : deny_access
end
+
+ # Authorize the user for the requested action outside a project
+ def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
+ authorize(ctrl, action, global)
+ end
# make sure that the user is a member of the project (or admin) if project is private
# used as a before_filter for actions that do not require any particular permission on the project
before_filter :find_project, :except => [ :index, :list, :add, :copy, :activity ]
before_filter :find_optional_project, :only => :activity
before_filter :authorize, :except => [ :index, :list, :add, :copy, :archive, :unarchive, :destroy, :activity ]
- before_filter :require_admin, :only => [ :add, :copy, :archive, :unarchive, :destroy ]
+ before_filter :authorize_global, :only => :add
+ before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
accept_key_auth :activity
after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller|
@project.enabled_module_names = params[:enabled_modules]
if @project.save
@project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
+ # Add current user as a project member if he is not admin
+ unless User.current.admin?
+ m = Member.new(:user => User.current, :roles => Role.builtin(false).find(:all, :order => 'position', :limit => 1))
+ @project.members << m
+ end
flash[:notice] = l(:notice_successful_create)
- redirect_to :controller => 'admin', :action => 'projects'
- end
+ redirect_to :controller => 'projects', :action => 'settings', :id => @project
+ end
end
end
roles.detect {|role| (project.is_public? || role.member?) && role.allowed_to?(action)}
elsif options[:global]
+ # Admin users are always authorized
+ return true if admin?
+
# authorize if user has at least one role that has this permission
roles = memberships.collect {|m| m.roles}.flatten.uniq
roles.detect {|r| r.allowed_to?(action)} || (self.logged? ? Role.non_member.allowed_to?(action) : Role.anonymous.allowed_to?(action))
<div class="contextual">
- <%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'add'}, :class => 'icon icon-add') + ' |' if User.current.admin? %>
+ <%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'add'}, :class => 'icon icon-add') + ' |' if User.current.allowed_to?(:add_project, nil, :global => true) %>
<%= link_to l(:label_issue_view_all), { :controller => 'issues' } %> |
<%= link_to l(:label_overall_activity), { :controller => 'projects', :action => 'activity' }%>
</div>
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.\r
label_wiki_content_updated: Wiki page updated\r
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.\r
+ permission_add_project: Create project\r
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
setting_openid: Allow OpenID login and registration
setting_password_min_length: Minimum password length
+ permission_add_project: Create project
permission_edit_project: Edit project
permission_select_project_modules: Select project modules
permission_manage_members: Manage members
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
setting_openid: "Autoriser l'authentification et l'enregistrement OpenID"
setting_password_min_length: Longueur minimum des mots de passe
+ permission_add_project: Créer un projet
permission_edit_project: Modifier le projet
permission_select_project_modules: Choisir les modules
permission_manage_members: Gérer les members
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
mail_body_wiki_content_added: The '{{page}}' wiki page has been added by {{author}}.
label_wiki_content_updated: Wiki page updated
mail_body_wiki_content_updated: The '{{page}}' wiki page has been updated by {{author}}.
+ permission_add_project: Create project
Redmine::AccessControl.map do |map|
map.permission :view_project, {:projects => [:show, :activity]}, :public => true
map.permission :search_project, {:search => :index}, :public => true
+ map.permission :add_project, {:projects => :add}, :require => :loggedin
map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member
map.permission :select_project_modules, {:projects => :modules}, :require => :member
map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member_login]}, :require => :member
builtin: 0\r
permissions: |\r
--- \r
+ - :add_project\r
- :edit_project\r
- :manage_members\r
- :manage_versions\r
)
end
+ def test_get_add
+ @request.session[:user_id] = 1
+ get :add
+ assert_response :success
+ assert_template 'add'
+ end
+
+ def test_get_add_by_non_admin
+ @request.session[:user_id] = 2
+ get :add
+ assert_response :success
+ assert_template 'add'
+ end
+
+ def test_post_add
+ @request.session[:user_id] = 1
+ post :add, :project => { :name => "blog",
+ :description => "weblog",
+ :identifier => "blog",
+ :is_public => 1,
+ :custom_field_values => { '3' => 'Beta' }
+ }
+ assert_redirected_to '/projects/blog/settings'
+
+ project = Project.find_by_name('blog')
+ assert_kind_of Project, project
+ assert_equal 'weblog', project.description
+ assert_equal true, project.is_public?
+ end
+
+ def test_post_add_by_non_admin
+ @request.session[:user_id] = 2
+ post :add, :project => { :name => "blog",
+ :description => "weblog",
+ :identifier => "blog",
+ :is_public => 1,
+ :custom_field_values => { '3' => 'Beta' }
+ }
+ assert_redirected_to '/projects/blog/settings'
+
+ project = Project.find_by_name('blog')
+ assert_kind_of Project, project
+ assert_equal 'weblog', project.description
+ assert_equal true, project.is_public?
+
+ # User should be added as a project member
+ assert User.find(2).member_of?(project)
+ assert_equal 1, project.members.size
+ end
+
def test_show_routing
assert_routing(
{:method => :get, :path => '/projects/test'},
locked_user = User.try_to_login("psmith", "psmith09")
assert_equal nil, locked_user
end
-
- def test_add_project
- log_user("admin", "admin")
- get "projects/new"
- assert_response :success
- assert_template "projects/add"
- post "projects", :project => { :name => "blog",
- :description => "weblog",
- :identifier => "blog",
- :is_public => 1,
- :custom_field_values => { '3' => 'Beta' }
- }
- assert_redirected_to "admin/projects"
- assert_equal 'Successful creation.', flash[:notice]
-
- project = Project.find_by_name("blog")
- assert_kind_of Project, project
- assert_equal "weblog", project.description
- assert_equal true, project.is_public?
-
- get "admin/projects"
- assert_response :success
- assert_template "admin/projects"
- end
end