diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index dfaad7fa3..a1706e601 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -17,13 +17,23 @@ class MembersController < ApplicationController layout 'base' - before_filter :find_project, :authorize + before_filter :find_member, :except => :new + before_filter :find_project, :only => :new + before_filter :authorize + def new + @project.members << Member.new(params[:member]) if request.post? + respond_to do |format| + format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project } + format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} } + end + end + def edit if request.post? and @member.update_attributes(params[:member]) respond_to do |format| format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project } - format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/members'} } + format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} } end end end @@ -32,12 +42,18 @@ class MembersController < ApplicationController @member.destroy respond_to do |format| format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project } - format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/members'} } + format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} } end end private def find_project + @project = Project.find(params[:id]) + rescue ActiveRecord::RecordNotFound + render_404 + end + + def find_member @member = Member.find(params[:id]) @project = @member.project rescue ActiveRecord::RecordNotFound diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 0acd64009..148d54d48 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -73,16 +73,9 @@ class ProjectsController < ApplicationController else @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) } - @project.custom_values = @custom_values - if params[:repository_enabled] && params[:repository_enabled] == "1" - @project.repository = Repository.factory(params[:repository_scm]) - @project.repository.attributes = params[:repository] - end - if "1" == params[:wiki_enabled] - @project.wiki = Wiki.new - @project.wiki.attributes = params[:wiki] - end + @project.custom_values = @custom_values if @project.save + @project.enabled_module_names = params[:enabled_modules] flash[:notice] = l(:notice_successful_create) redirect_to :controller => 'admin', :action => 'projects' end @@ -107,6 +100,8 @@ class ProjectsController < ApplicationController @issue_category ||= IssueCategory.new @member ||= @project.members.new @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } + @repository ||= @project.repository + @wiki ||= @project.wiki end # Edit @project @@ -117,24 +112,6 @@ class ProjectsController < ApplicationController @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } @project.custom_values = @custom_values end - if params[:repository_enabled] - case params[:repository_enabled] - when "0" - @project.repository = nil - when "1" - @project.repository ||= Repository.factory(params[:repository_scm]) - @project.repository.update_attributes params[:repository] if @project.repository - end - end - if params[:wiki_enabled] - case params[:wiki_enabled] - when "0" - @project.wiki.destroy if @project.wiki - when "1" - @project.wiki ||= Wiki.new - @project.wiki.update_attributes params[:wiki] - end - end @project.attributes = params[:project] if @project.save flash[:notice] = l(:notice_successful_update) @@ -145,6 +122,11 @@ class ProjectsController < ApplicationController end end end + + def modules + @project.enabled_module_names = params[:enabled_modules] + redirect_to :action => 'settings', :id => @project, :tab => 'modules' + end def archive @project.archive if request.post? && @project.active? @@ -195,25 +177,6 @@ class ProjectsController < ApplicationController end end - # Add a new member to @project - def add_member - @member = @project.members.build(params[:member]) - if request.post? && @member.save - respond_to do |format| - format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project } - format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'members'} } - end - else - settings - render :action => 'settings' - end - end - - # Show members list of @project - def list_members - @members = @project.members.find(:all) - end - # Add a new document to @project def add_document @categories = Enumeration::get_values('DCAT') diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index f99ea0b35..12439cfab 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -21,10 +21,29 @@ require 'digest/sha1' class RepositoriesController < ApplicationController layout 'base' - before_filter :find_project, :except => [:update_form] - before_filter :authorize, :except => [:update_form] + before_filter :find_repository, :except => :edit + before_filter :find_project, :only => :edit + before_filter :authorize accept_key_auth :revisions + def edit + @repository = @project.repository + if !@repository + @repository = Repository.factory(params[:repository_scm]) + @repository.project = @project + end + if request.post? + @repository.attributes = params[:repository] + @repository.save + end + render(:update) {|page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'} + end + + def destroy + @repository.destroy + redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository' + end + def show # check if new revisions have been committed in the repository @repository.fetch_changesets if Setting.autofetch_changesets? @@ -113,14 +132,15 @@ class RepositoriesController < ApplicationController end end - def update_form - @repository = Repository.factory(params[:repository_scm]) - render :partial => 'projects/repository', :locals => {:repository => @repository} - end - private def find_project @project = Project.find(params[:id]) + rescue ActiveRecord::RecordNotFound + render_404 + end + + def find_repository + @project = Project.find(params[:id]) @repository = @project.repository render_404 and return false unless @repository @path = params[:path].squeeze('/') if params[:path] diff --git a/app/controllers/wikis_controller.rb b/app/controllers/wikis_controller.rb new file mode 100644 index 000000000..146aaac8a --- /dev/null +++ b/app/controllers/wikis_controller.rb @@ -0,0 +1,44 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class WikisController < ApplicationController + layout 'base' + before_filter :find_project, :authorize + + # Create or update a project's wiki + def edit + @wiki = @project.wiki || Wiki.new(:project => @project) + @wiki.attributes = params[:wiki] + @wiki.save if @request.post? + render(:update) {|page| page.replace_html "tab-content-wiki", :partial => 'projects/settings/wiki'} + end + + # Delete a project's wiki + def destroy + if request.post? && params[:confirm] && @project.wiki + @project.wiki.destroy + redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'wiki' + end + end + +private + def find_project + @project = Project.find(params[:id]) + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 2657c7e0a..5b78db71c 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -26,6 +26,19 @@ module ProjectsHelper }, options end + def project_settings_tabs + tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural}, + {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural}, + {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural}, + {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural}, + {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural}, + {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki}, + {:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository}, + {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural} + ] + tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)} + end + # Generates a gantt image # Only defined if RMagick is avalaible def gantt_image(events, date_from, months, zoom) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 7db748abd..d82e16561 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -29,13 +29,13 @@ module RepositoriesHelper send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) end - def scm_select_tag + def scm_select_tag(repository) container = [[]] REDMINE_SUPPORTED_SCM.each {|scm| container << ["Repository::#{scm}".constantize.scm_name, scm]} select_tag('repository_scm', - options_for_select(container, @project.repository.class.name.demodulize), - :disabled => (@project.repository && !@project.repository.new_record?), - :onchange => remote_function(:update => "repository_fields", :url => { :controller => 'repositories', :action => 'update_form', :id => @project }, :with => "Form.serialize(this.form)") + options_for_select(container, repository.class.name.demodulize), + :disabled => (repository && !repository.new_record?), + :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)") ) end diff --git a/app/models/enabled_module.rb b/app/models/enabled_module.rb new file mode 100644 index 000000000..3c05c76c1 --- /dev/null +++ b/app/models/enabled_module.rb @@ -0,0 +1,23 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class EnabledModule < ActiveRecord::Base + belongs_to :project + + validates_presence_of :name + validates_uniqueness_of :name, :scope => :project_id +end diff --git a/app/models/project.rb b/app/models/project.rb index fa975c435..fb5c63fe2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -23,6 +23,7 @@ class Project < ActiveRecord::Base has_many :members, :dependent => :delete_all, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}" has_many :users, :through => :members has_many :custom_values, :dependent => :delete_all, :as => :customized + has_many :enabled_modules, :dependent => :delete_all has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker] has_many :issue_changes, :through => :issues, :source => :journals has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC" @@ -38,7 +39,7 @@ class Project < ActiveRecord::Base has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id' acts_as_tree :order => "name", :counter_cache => true - attr_protected :status + attr_protected :status, :enabled_module_names validates_presence_of :name, :description, :identifier validates_uniqueness_of :name, :identifier @@ -121,10 +122,43 @@ class Project < ActiveRecord::Base def <=>(project) name <=> project.name end + + def allows_to?(action) + if action.is_a? Hash + allowed_actions.include? "#{action[:controller]}/#{action[:action]}" + else + allowed_permissions.include? action + end + end + + def module_enabled?(module_name) + module_name = module_name.to_s + enabled_modules.detect {|m| m.name == module_name} + end + + def enabled_module_names=(module_names) + enabled_modules.clear + module_names = [] unless module_names && module_names.is_a?(Array) + module_names.each do |name| + enabled_modules << EnabledModule.new(:name => name.to_s) + end + end protected def validate errors.add(parent_id, " must be a root project") if parent and parent.parent errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0 end + +private + def allowed_permissions + @allowed_permissions ||= begin + module_names = enabled_modules.collect {|m| m.name} + Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name} + end + end + + def allowed_actions + @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten + end end diff --git a/app/models/user.rb b/app/models/user.rb index 4cb8da1f9..e4c397a51 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -178,8 +178,13 @@ class User < ActiveRecord::Base # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit') # * a permission Symbol (eg. :edit_project) def allowed_to?(action, project) + # No action allowed on archived projects return false unless project.active? + # No action allowed on disabled modules + return false unless project.allows_to?(action) + # Admin users are authorized for anything else return true if admin? + role = role_for_project(project) return false unless role role.allowed_to?(action) && (project.is_public? || role.member?) diff --git a/app/views/issue_categories/edit.rhtml b/app/views/issue_categories/edit.rhtml index 54a1f0c66..bc627797b 100644 --- a/app/views/issue_categories/edit.rhtml +++ b/app/views/issue_categories/edit.rhtml @@ -2,5 +2,5 @@ <% labelled_tabular_form_for :category, @category, :url => { :action => 'edit', :id => @category } do |f| %> <%= render :partial => 'issue_categories/form', :locals => { :f => f } %> -<%= submit_tag l(:button_create) %> +<%= submit_tag l(:button_save) %> <% end %> diff --git a/app/views/layouts/base.rhtml b/app/views/layouts/base.rhtml index eae5cf570..1371d784d 100644 --- a/app/views/layouts/base.rhtml +++ b/app/views/layouts/base.rhtml @@ -71,7 +71,7 @@ <% if @project && !@project.new_record? %>

<%= @project.name %>

+ <% if User.current.allowed_to?(:view_issues, @project) %>
<% if authorize_for('projects', 'add_issue') %><%= l(:label_issue_new) %>: <%= new_issue_selector %><% end %>

<%=l(:label_issue_tracking)%>

@@ -33,6 +34,7 @@

<%= link_to l(:label_issue_view_all), :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1 %>

+ <% end %>
diff --git a/app/views/roles/_form.rhtml b/app/views/roles/_form.rhtml index 62e25e337..6213aa2fb 100644 --- a/app/views/roles/_form.rhtml +++ b/app/views/roles/_form.rhtml @@ -2,19 +2,23 @@

<%= f.text_field :name, :required => true, :disabled => @role.builtin? %>

-

<%= f.check_box :assignable %>

-
+
-
<%=l(:label_permissions)%> -<% @permissions.each do |permission| %> -
- <%= check_box_tag 'role[permissions][]', permission.name, (@role.permissions.include? permission.name) %> - <%= permission.name.to_s.humanize %> -
+
+

<%= l(:label_permissions) %>

+ +<% perms_by_module = @permissions.group_by {|p| p.project_module.to_s} %> +<% perms_by_module.keys.sort.each do |mod| %> +
<%= mod.blank? ? l(:label_project) : mod.humanize %> + <% perms_by_module[mod].each do |permission| %> +
+ <%= check_box_tag 'role[permissions][]', permission.name, (@role.permissions.include? permission.name) %> + <%= permission.name.to_s.humanize %> +
+ <% end %> +
<% end %> +
<%= check_all_links 'role_form' %> <%= hidden_field_tag 'role[permissions][]', '' %> -
-
-<%= check_all_links 'role_form' %> -
+ diff --git a/app/views/roles/report.rhtml b/app/views/roles/report.rhtml index ca2f9d798..3d2ecc1e3 100644 --- a/app/views/roles/report.rhtml +++ b/app/views/roles/report.rhtml @@ -12,17 +12,23 @@ -<% @permissions.each do |permission| %> - - <%= permission.name.to_s.humanize %> - <% @roles.each do |role| %> - - <% if role.setable_permissions.include? permission %> - <%= check_box_tag "permissions[#{role.id}][]", permission.name, (role.permissions.include? permission.name) %> +<% perms_by_module = @permissions.group_by {|p| p.project_module.to_s} %> +<% perms_by_module.keys.sort.each do |mod| %> + <% unless mod.blank? %> + <%= content_tag('th', mod.humanize, :colspan => (@roles.size + 1)) %> <% end %> - + <% perms_by_module[mod].each do |permission| %> + + <%= permission.name.to_s.humanize %> + <% @roles.each do |role| %> + + <% if role.setable_permissions.include? permission %> + <%= check_box_tag "permissions[#{role.id}][]", permission.name, (role.permissions.include? permission.name) %> + <% end %> + + <% end %> + <% end %> - <% end %> diff --git a/app/views/wikis/destroy.rhtml b/app/views/wikis/destroy.rhtml new file mode 100644 index 000000000..b5b1de114 --- /dev/null +++ b/app/views/wikis/destroy.rhtml @@ -0,0 +1,10 @@ +

<%=l(:label_confirmation)%>

+ +
+

<%= @project.name %>
<%=l(:text_wiki_destroy_confirmation)%>

+ +<% form_tag({:controller => 'wikis', :action => 'destroy', :id => @project}) do %> +<%= hidden_field_tag "confirm", 1 %> +<%= submit_tag l(:button_delete) %> +<% end %> +
diff --git a/db/migrate/068_create_enabled_modules.rb b/db/migrate/068_create_enabled_modules.rb new file mode 100644 index 000000000..fd848ef96 --- /dev/null +++ b/db/migrate/068_create_enabled_modules.rb @@ -0,0 +1,18 @@ +class CreateEnabledModules < ActiveRecord::Migration + def self.up + create_table :enabled_modules do |t| + t.column :project_id, :integer + t.column :name, :string, :null => false + end + add_index :enabled_modules, [:project_id], :name => :enabled_modules_project_id + + # Enable all modules for existing projects + Project.find(:all).each do |project| + project.enabled_module_names = Redmine::AccessControl.available_project_modules + end + end + + def self.down + drop_table :enabled_modules + end +end diff --git a/lang/bg.yml b/lang/bg.yml index d2c5d41fa..d3a8e2bd6 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -415,6 +415,7 @@ label_language_based: Language based label_sort_by: Sort by "%s" label_send_test_email: Send a test email label_feeds_access_key_created_on: RSS access key created %s ago +label_module_plural: Modules button_login: Вход button_submit: Изпращане @@ -474,6 +475,7 @@ text_comma_separated: Позволено е изброяване (с разде text_issues_ref_in_commit_messages: Отбелязване и приключване на задачи от commit съобщения text_issue_added: Публикувана е нова задача с номер %s. text_issue_updated: Задача %s е обновена. +text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ? default_role_manager: Мениджър default_role_developper: Разработчик diff --git a/lang/de.yml b/lang/de.yml index 65d44b49b..1bc63f5cd 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -415,6 +415,7 @@ label_language_based: Language based label_sort_by: Sort by "%s" label_send_test_email: Send a test email label_feeds_access_key_created_on: RSS access key created %s ago +label_module_plural: Modules button_login: Einloggen button_submit: OK @@ -474,6 +475,7 @@ text_comma_separated: Multiple values allowed (comma separated). text_issues_ref_in_commit_messages: Referencing and fixing issues in commit messages text_issue_added: Ticket %s wurde erstellt. text_issue_updated: Ticket %s wurde aktualisiert. +text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ? default_role_manager: Manager default_role_developper: Developer diff --git a/lang/en.yml b/lang/en.yml index 30e81aa72..29c371ad4 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -415,6 +415,7 @@ label_language_based: Language based label_sort_by: Sort by "%s" label_send_test_email: Send a test email label_feeds_access_key_created_on: RSS access key created %s ago +label_module_plural: Modules button_login: Login button_submit: Submit @@ -474,6 +475,7 @@ text_comma_separated: Multiple values allowed (comma separated). text_issues_ref_in_commit_messages: Referencing and fixing issues in commit messages text_issue_added: Issue %s has been reported. text_issue_updated: Issue %s has been updated. +text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ? default_role_manager: Manager default_role_developper: Developer diff --git a/lang/es.yml b/lang/es.yml index 36d98d204..5915f4b93 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -415,6 +415,7 @@ label_language_based: Language based label_sort_by: Sort by "%s" label_send_test_email: Send a test email label_feeds_access_key_created_on: RSS access key created %s ago +label_module_plural: Modules button_login: Conexión button_submit: Someter @@ -474,6 +475,7 @@ text_comma_separated: Multiple values allowed (comma separated). text_issues_ref_in_commit_messages: Referencing and fixing issues in commit messages text_issue_added: Issue %s has been reported. text_issue_updated: Issue %s has been updated. +text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ? default_role_manager: Manager default_role_developper: Desarrollador diff --git a/lang/fr.yml b/lang/fr.yml index cbdd4bf86..e92a28bab 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -415,6 +415,7 @@ label_language_based: Basé sur la langue label_sort_by: Trier par "%s" label_send_test_email: Envoyer un email de test label_feeds_access_key_created_on: Clé d'accès RSS créée il y a %s +label_module_plural: Modules button_login: Connexion button_submit: Soumettre @@ -474,6 +475,7 @@ text_comma_separated: Plusieurs valeurs possibles (séparées par des virgules). text_issues_ref_in_commit_messages: Référencement et résolution des demandes dans les commentaires de commits text_issue_added: La demande %s a été soumise. text_issue_updated: La demande %s a été mise à jour. +text_wiki_destroy_confirmation: Etes-vous sûr de vouloir supprimer ce wiki et tout son contenu ? default_role_manager: Manager default_role_developper: Développeur diff --git a/lang/it.yml b/lang/it.yml index 31a5f59ab..212f029ef 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -415,6 +415,7 @@ label_language_based: Language based label_sort_by: Sort by "%s" label_send_test_email: Send a test email label_feeds_access_key_created_on: RSS access key created %s ago +label_module_plural: Modules button_login: Login button_submit: Invia @@ -474,6 +475,7 @@ text_comma_separated: Multiple values allowed (comma separated). text_issues_ref_in_commit_messages: Referencing and fixing issues in commit messages text_issue_added: "E' stata segnalata l'anomalia %s." text_issue_updated: "L'anomalia %s e' stata aggiornata." +text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ? default_role_manager: Manager default_role_developper: Sviluppatore diff --git a/lang/ja.yml b/lang/ja.yml index bd7d3bc82..1bed4b7e5 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -416,6 +416,7 @@ label_language_based: Language based label_sort_by: Sort by "%s" label_send_test_email: Send a test email label_feeds_access_key_created_on: RSS access key created %s ago +label_module_plural: Modules button_login: ログイン button_submit: 変更 @@ -475,6 +476,7 @@ text_comma_separated: (カンマで区切った)複数の値が使えます text_issues_ref_in_commit_messages: コミットメッセージ内で問題の参照/修正 text_issue_added: 問題 %s が報告されました。 text_issue_updated: 問題 %s が更新されました。 +text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ? default_role_manager: 管理者 default_role_developper: 開発者 diff --git a/lang/nl.yml b/lang/nl.yml index 39bd0b1dd..78ca987ea 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -415,6 +415,7 @@ label_language_based: Language based label_sort_by: Sort by "%s" label_send_test_email: Send a test email label_feeds_access_key_created_on: RSS access key created %s ago +label_module_plural: Modules button_login: Inloggen button_submit: Toevoegen @@ -474,6 +475,7 @@ text_coma_separated: Meerdere waarden toegestaan (door komma's gescheiden). text_issues_ref_in_commit_messages: Opzoeken en aanpassen van issues in commit berichten text_issue_added: Issue %s is gerapporteerd. text_issue_updated: Issue %s is gewijzigd. +text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ? default_role_manager: Manager default_role_developper: Ontwikkelaar diff --git a/lang/pt-br.yml b/lang/pt-br.yml index aa6841673..81bbba701 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -415,6 +415,7 @@ label_language_based: Language based label_sort_by: Sort by "%s" label_send_test_email: Send a test email label_feeds_access_key_created_on: RSS access key created %s ago +label_module_plural: Modules button_login: Login button_submit: Enviar @@ -474,6 +475,7 @@ text_comma_separated: Multiple values allowed (comma separated). text_issues_ref_in_commit_messages: Referencing and fixing issues in commit messages text_issue_added: Tarefa %s foi incluída. text_issue_updated: Tarefa %s foi alterada. +text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ? default_role_manager: Analista de Negocio ou Gerente de Projeto default_role_developper: Desenvolvedor diff --git a/lang/pt.yml b/lang/pt.yml index d4d24df85..10153e2b8 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -415,6 +415,7 @@ label_language_based: Language based label_sort_by: Sort by "%s" label_send_test_email: Send a test email label_feeds_access_key_created_on: RSS access key created %s ago +label_module_plural: Modules button_login: Login button_submit: Enviar @@ -474,6 +475,7 @@ text_comma_separated: Permitido múltiplos valores (separados por vírgula). text_issues_ref_in_commit_messages: Referenciando e arrumando tarefas nas mensagens de commit text_issue_added: Tarefa %s foi incluída. text_issue_updated: Tarefa %s foi alterada. +text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ? default_role_manager: Analista de Negócio ou Gerente de Projeto default_role_developper: Desenvolvedor diff --git a/lang/sv.yml b/lang/sv.yml index 25ac78a50..edb9416f7 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -415,6 +415,7 @@ label_language_based: Language based label_sort_by: Sort by "%s" label_send_test_email: Send a test email label_feeds_access_key_created_on: RSS access key created %s ago +label_module_plural: Modules button_login: Logga in button_submit: Skicka @@ -474,6 +475,7 @@ text_comma_separated: Multiple values allowed (comma separated). text_issues_ref_in_commit_messages: Referencing and fixing issues in commit messages text_issue_added: Brist %s har rapporterats. text_issue_updated: Brist %s har uppdaterats. +text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ? default_role_manager: Förvaltare default_role_developper: Utvecklare diff --git a/lang/zh.yml b/lang/zh.yml index fa01f7086..f043436aa 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -417,6 +417,7 @@ label_language_based: Language based label_sort_by: Sort by "%s" label_send_test_email: Send a test email label_feeds_access_key_created_on: RSS access key created %s ago +label_module_plural: Modules button_login: 登录 button_submit: 提交 @@ -476,6 +477,7 @@ text_comma_separated: Multiple values allowed (comma separated). text_issues_ref_in_commit_messages: Referencing and fixing issues in commit messages text_issue_added: %s ѱ text_issue_updated: %s Ѹ +text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ? default_role_manager: 管理员 default_role_developper: 开发人员 diff --git a/lib/redmine.rb b/lib/redmine.rb index a0da981e4..9392558f5 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -14,57 +14,76 @@ REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs ) # Permissions Redmine::AccessControl.map do |map| - # Project - map.permission :view_project, {:projects => [:show, :activity, :changelog, :roadmap, :feeds]}, :public => true + map.permission :view_project, {:projects => [:show, :activity, :feeds]}, :public => true map.permission :search_project, {:search => :index}, :public => true map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member - map.permission :manage_members, {:projects => [:settings, :add_member], :members => [:edit, :destroy]}, :require => :member + map.permission :select_project_modules, {:projects => :modules}, :require => :member + map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy]}, :require => :member map.permission :manage_versions, {:projects => [:settings, :add_version], :versions => [:edit, :destroy]}, :require => :member - map.permission :manage_categories, {:projects => [:settings, :add_issue_category], :issue_categories => [:edit, :destroy]}, :require => :member - # Issues - map.permission :view_issues, {:projects => [:list_issues, :export_issues_csv, :export_issues_pdf], - :issues => [:show, :export_pdf], - :queries => :index, - :reports => :issue_report}, :public => true - map.permission :add_issues, {:projects => :add_issue}, :require => :loggedin - map.permission :edit_issues, {:issues => [:edit, :destroy_attachment]}, :require => :loggedin - map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}, :require => :loggedin - map.permission :add_issue_notes, {:issues => :add_note}, :require => :loggedin - map.permission :change_issue_status, {:issues => :change_status}, :require => :loggedin - map.permission :move_issues, {:projects => :move_issues}, :require => :loggedin - map.permission :delete_issues, {:issues => :destroy}, :require => :member - # Queries - map.permission :manage_pulic_queries, {:queries => [:new, :edit, :destroy]}, :require => :member - map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin - # Gantt & calendar - map.permission :view_gantt, :projects => :gantt - map.permission :view_calendar, :projects => :calendar - # Time tracking - map.permission :log_time, {:timelog => :edit}, :require => :loggedin - map.permission :view_time_entries, :timelog => [:details, :report] - # News - map.permission :view_news, {:projects => :list_news, :news => :show}, :public => true - map.permission :manage_news, {:projects => :add_news, :news => [:edit, :destroy, :destroy_comment]}, :require => :member - map.permission :comment_news, {:news => :add_comment}, :require => :loggedin - # Documents - map.permission :view_documents, :projects => :list_documents, :documents => [:show, :download] - map.permission :manage_documents, {:projects => :add_document, :documents => [:edit, :destroy, :add_attachment, :destroy_attachment]}, :require => :loggedin - # Wiki - map.permission :view_wiki_pages, :wiki => [:index, :history, :diff, :special] - map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment, :destroy_attachment] - map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member - map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member - # Message boards - map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true - map.permission :add_messages, {:messages => [:new, :reply]}, :require => :loggedin - map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member - # Files - map.permission :view_files, :projects => :list_files, :versions => :download - map.permission :manage_files, {:projects => :add_file, :versions => :destroy_file}, :require => :loggedin - # Repository - map.permission :browse_repository, :repositories => [:show, :browse, :entry, :changes, :diff, :stats, :graph] - map.permission :view_changesets, :repositories => [:show, :revisions, :revision] + map.project_module :issue_tracking do |map| + # Issue categories + map.permission :manage_categories, {:projects => [:settings, :add_issue_category], :issue_categories => [:edit, :destroy]}, :require => :member + # Issues + map.permission :view_issues, {:projects => [:list_issues, :export_issues_csv, :export_issues_pdf, :changelog, :roadmap], + :issues => [:show, :export_pdf], + :queries => :index, + :reports => :issue_report}, :public => true + map.permission :add_issues, {:projects => :add_issue}, :require => :loggedin + map.permission :edit_issues, {:issues => [:edit, :destroy_attachment]}, :require => :loggedin + map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}, :require => :loggedin + map.permission :add_issue_notes, {:issues => :add_note}, :require => :loggedin + map.permission :change_issue_status, {:issues => :change_status}, :require => :loggedin + map.permission :move_issues, {:projects => :move_issues}, :require => :loggedin + map.permission :delete_issues, {:issues => :destroy}, :require => :member + # Queries + map.permission :manage_pulic_queries, {:queries => [:new, :edit, :destroy]}, :require => :member + map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin + # Gantt & calendar + map.permission :view_gantt, :projects => :gantt + map.permission :view_calendar, :projects => :calendar + end + + map.project_module :time_tracking do |map| + map.permission :log_time, {:timelog => :edit}, :require => :loggedin + map.permission :view_time_entries, :timelog => [:details, :report] + end + + map.project_module :news do |map| + map.permission :manage_news, {:projects => :add_news, :news => [:edit, :destroy, :destroy_comment]}, :require => :member + map.permission :view_news, {:projects => :list_news, :news => :show}, :public => true + map.permission :comment_news, {:news => :add_comment}, :require => :loggedin + end + + map.project_module :documents do |map| + map.permission :manage_documents, {:projects => :add_document, :documents => [:edit, :destroy, :add_attachment, :destroy_attachment]}, :require => :loggedin + map.permission :view_documents, :projects => :list_documents, :documents => [:show, :download] + end + + map.project_module :files do |map| + map.permission :manage_files, {:projects => :add_file, :versions => :destroy_file}, :require => :loggedin + map.permission :view_files, :projects => :list_files, :versions => :download + end + + map.project_module :wiki do |map| + map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member + map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member + map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member + map.permission :view_wiki_pages, :wiki => [:index, :history, :diff, :special] + map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment, :destroy_attachment] + end + + map.project_module :repository do |map| + map.permission :manage_repository, :repositories => [:edit, :destroy] + map.permission :browse_repository, :repositories => [:show, :browse, :entry, :changes, :diff, :stats, :graph] + map.permission :view_changesets, :repositories => [:show, :revisions, :revision] + end + + map.project_module :boards do |map| + map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member + map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true + map.permission :add_messages, {:messages => [:new, :reply]}, :require => :loggedin + end end # Project menu configuration diff --git a/lib/redmine/access_control.rb b/lib/redmine/access_control.rb index 54b344b7e..f5b25f277 100644 --- a/lib/redmine/access_control.rb +++ b/lib/redmine/access_control.rb @@ -46,27 +46,47 @@ module Redmine def loggedin_only_permissions @loggedin_only_permissions ||= @permissions.select {|p| p.require_loggedin?} end + + def available_project_modules + @available_project_modules ||= @permissions.collect(&:project_module).uniq.compact + end + + def modules_permissions(modules) + @permissions.select {|p| p.project_module.nil? || modules.include?(p.project_module.to_s)} + end end class Mapper + def initialize + @project_module = nil + end + def permission(name, hash, options={}) @permissions ||= [] + options.merge!(:project_module => @project_module) @permissions << Permission.new(name, hash, options) end + def project_module(name, options={}) + @project_module = name + yield self + @project_module = nil + end + def mapped_permissions @permissions end end class Permission - attr_reader :name, :actions + attr_reader :name, :actions, :project_module def initialize(name, hash, options) @name = name @actions = [] @public = options[:public] || false @require = options[:require] + @project_module = options[:project_module] hash.each do |controller, actions| if actions.is_a? Array @actions << actions.collect {|action| "#{controller}/#{action}"} diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb index afb7699b0..d4a46b3e1 100644 --- a/lib/redmine/menu_manager.rb +++ b/lib/redmine/menu_manager.rb @@ -31,8 +31,8 @@ module Redmine @items[menu_name.to_sym] || [] end - def allowed_items(menu_name, role) - items(menu_name).select {|item| role && role.allowed_to?(item.url)} + def allowed_items(menu_name, user, project) + items(menu_name).select {|item| user && user.allowed_to?(item.url, project)} end end diff --git a/test/fixtures/enabled_modules.yml b/test/fixtures/enabled_modules.yml new file mode 100644 index 000000000..1f05cd9a7 --- /dev/null +++ b/test/fixtures/enabled_modules.yml @@ -0,0 +1,33 @@ +--- +enabled_modules_001: + name: issue_tracking + project_id: 1 + id: 1 +enabled_modules_002: + name: time_tracking + project_id: 1 + id: 2 +enabled_modules_003: + name: news + project_id: 1 + id: 3 +enabled_modules_004: + name: documents + project_id: 1 + id: 4 +enabled_modules_005: + name: files + project_id: 1 + id: 5 +enabled_modules_006: + name: wiki + project_id: 1 + id: 6 +enabled_modules_007: + name: repository + project_id: 1 + id: 7 +enabled_modules_008: + name: boards + project_id: 1 + id: 8 diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index def7b7579..6f8ae1d7d 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -22,7 +22,7 @@ require 'projects_controller' class ProjectsController; def rescue_action(e) raise e end; end class ProjectsControllerTest < Test::Unit::TestCase - fixtures :projects, :users, :roles + fixtures :projects, :users, :roles, :enabled_modules def setup @controller = ProjectsController.new diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 833506a16..d0fc68de8 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -18,7 +18,7 @@ require File.dirname(__FILE__) + '/../test_helper' class MailHandlerTest < Test::Unit::TestCase - fixtures :users, :projects, :roles, :members, :issues, :trackers, :enumerations + fixtures :users, :projects, :enabled_modules, :roles, :members, :issues, :trackers, :enumerations FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures' CHARSET = "utf-8" diff --git a/test/unit/watcher_test.rb b/test/unit/watcher_test.rb index b8a095426..9566e6a7c 100644 --- a/test/unit/watcher_test.rb +++ b/test/unit/watcher_test.rb @@ -58,7 +58,7 @@ class WatcherTest < Test::Unit::TestCase @user.mail_notification = false @user.save @issue.reload - assert !@issue.watcher_recipients.include?(@user.mail) + assert @issue.watcher_recipients.include?(@user.mail) end def test_unwatch