summaryrefslogtreecommitdiffstats
path: root/lib/redmine
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-08-29 16:52:35 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-08-29 16:52:35 +0000
commit603e11d7a5aa62f923e7b013cac6c66462131232 (patch)
treefbbb204d2b92b5a87b787d56fe3f9c62cc3f259b /lib/redmine
parent8da5bad29516be6cbe1bc52e78837ac1ec292026 (diff)
downloadredmine-603e11d7a5aa62f923e7b013cac6c66462131232.tar.gz
redmine-603e11d7a5aa62f923e7b013cac6c66462131232.zip
Merged 0.6 branch into trunk.
Permissions management was rewritten. Some permissions can now be specifically defined for non member and anonymous users. This migration: * is irreversible (please, don't forget to *backup* your database before upgrading) * resets role's permissions (go to "Admin -> Roles & Permissions" to set them after upgrading) git-svn-id: http://redmine.rubyforge.org/svn/trunk@674 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine')
-rw-r--r--lib/redmine/access_control.rb92
-rw-r--r--lib/redmine/acts_as_event/init.rb2
-rw-r--r--lib/redmine/acts_as_event/lib/acts_as_event.rb68
-rw-r--r--lib/redmine/menu_manager.rb61
-rw-r--r--lib/redmine/version.rb7
5 files changed, 230 insertions, 0 deletions
diff --git a/lib/redmine/access_control.rb b/lib/redmine/access_control.rb
new file mode 100644
index 000000000..54b344b7e
--- /dev/null
+++ b/lib/redmine/access_control.rb
@@ -0,0 +1,92 @@
+# 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.
+
+module Redmine
+ module AccessControl
+
+ class << self
+ def map
+ mapper = Mapper.new
+ yield mapper
+ @permissions ||= []
+ @permissions += mapper.mapped_permissions
+ end
+
+ def permissions
+ @permissions
+ end
+
+ def allowed_actions(permission_name)
+ perm = @permissions.detect {|p| p.name == permission_name}
+ perm ? perm.actions : []
+ end
+
+ def public_permissions
+ @public_permissions ||= @permissions.select {|p| p.public?}
+ end
+
+ def members_only_permissions
+ @members_only_permissions ||= @permissions.select {|p| p.require_member?}
+ end
+
+ def loggedin_only_permissions
+ @loggedin_only_permissions ||= @permissions.select {|p| p.require_loggedin?}
+ end
+ end
+
+ class Mapper
+ def permission(name, hash, options={})
+ @permissions ||= []
+ @permissions << Permission.new(name, hash, options)
+ end
+
+ def mapped_permissions
+ @permissions
+ end
+ end
+
+ class Permission
+ attr_reader :name, :actions
+
+ def initialize(name, hash, options)
+ @name = name
+ @actions = []
+ @public = options[:public] || false
+ @require = options[:require]
+ hash.each do |controller, actions|
+ if actions.is_a? Array
+ @actions << actions.collect {|action| "#{controller}/#{action}"}
+ else
+ @actions << "#{controller}/#{actions}"
+ end
+ end
+ end
+
+ def public?
+ @public
+ end
+
+ def require_member?
+ @require && @require == :member
+ end
+
+ def require_loggedin?
+ @require && (@require == :member || @require == :loggedin)
+ end
+ end
+ end
+end
diff --git a/lib/redmine/acts_as_event/init.rb b/lib/redmine/acts_as_event/init.rb
new file mode 100644
index 000000000..91051510a
--- /dev/null
+++ b/lib/redmine/acts_as_event/init.rb
@@ -0,0 +1,2 @@
+require File.dirname(__FILE__) + '/lib/acts_as_event'
+ActiveRecord::Base.send(:include, Redmine::Acts::Event)
diff --git a/lib/redmine/acts_as_event/lib/acts_as_event.rb b/lib/redmine/acts_as_event/lib/acts_as_event.rb
new file mode 100644
index 000000000..a0d1822ad
--- /dev/null
+++ b/lib/redmine/acts_as_event/lib/acts_as_event.rb
@@ -0,0 +1,68 @@
+# 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.
+
+module Redmine
+ module Acts
+ module Event
+ def self.included(base)
+ base.extend ClassMethods
+ end
+
+ module ClassMethods
+ def acts_as_event(options = {})
+ return if self.included_modules.include?(Redmine::Acts::Event::InstanceMethods)
+ options[:datetime] ||= 'created_on'
+ options[:title] ||= 'title'
+ options[:description] ||= 'description'
+ options[:author] ||= 'author'
+ options[:url] ||= {:controller => 'welcome'}
+ cattr_accessor :event_options
+ self.event_options = options
+ send :include, Redmine::Acts::Event::InstanceMethods
+ end
+ end
+
+ module InstanceMethods
+ def self.included(base)
+ base.extend ClassMethods
+ end
+
+ %w(datetime title description author).each do |attr|
+ src = <<-END_SRC
+ def event_#{attr}
+ option = event_options[:#{attr}]
+ option.is_a?(Proc) ? option.call(self) : send(option)
+ end
+ END_SRC
+ class_eval src, __FILE__, __LINE__
+ end
+
+ def event_date
+ event_datetime.to_date
+ end
+
+ def event_url(options = {})
+ option = event_options[:url]
+ (option.is_a?(Proc) ? option.call(self) : send(option)).merge(options)
+ end
+
+ module ClassMethods
+ end
+ end
+ end
+ end
+end
diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb
new file mode 100644
index 000000000..afb7699b0
--- /dev/null
+++ b/lib/redmine/menu_manager.rb
@@ -0,0 +1,61 @@
+# 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.
+
+module Redmine
+ module MenuManager
+
+ class << self
+ def map(menu_name)
+ mapper = Mapper.new
+ yield mapper
+ @items ||= {}
+ @items[menu_name.to_sym] ||= []
+ @items[menu_name.to_sym] += mapper.items
+ end
+
+ def items(menu_name)
+ @items[menu_name.to_sym] || []
+ end
+
+ def allowed_items(menu_name, role)
+ items(menu_name).select {|item| role && role.allowed_to?(item.url)}
+ end
+ end
+
+ class Mapper
+ def push(name, url, options={})
+ @items ||= []
+ @items << MenuItem.new(name, url, options)
+ end
+
+ def items
+ @items
+ end
+ end
+
+ class MenuItem
+ attr_reader :name, :url, :param, :condition
+
+ def initialize(name, url, options)
+ @name = name
+ @url = url
+ @condition = options[:if]
+ @param = options[:param] || :id
+ end
+ end
+ end
+end
diff --git a/lib/redmine/version.rb b/lib/redmine/version.rb
index 5934af03e..494bb2de2 100644
--- a/lib/redmine/version.rb
+++ b/lib/redmine/version.rb
@@ -8,4 +8,11 @@ module Redmine
def self.to_s; STRING end
end
+
+ module Info
+ class << self
+ def name; 'Redmine' end
+ def url; 'http://www.redmine.org/' end
+ end
+ end
end