diff app/models/project.rb @ 510:1afe06d9ba94 cannam_integration

Merge from branch "cannam"
author Chris Cannam
date Thu, 14 Jul 2011 10:42:41 +0100
parents 851510f1b535
children 65abc6b39292
line wrap: on
line diff
--- a/app/models/project.rb	Mon Jul 11 16:35:45 2011 +0100
+++ b/app/models/project.rb	Thu Jul 14 10:42:41 2011 +0100
@@ -119,6 +119,11 @@
     visible(user).find(:all, :limit => count, :order => "created_on DESC")	
   end	
 
+  # Returns true if the project is visible to +user+ or to the current user.
+  def visible?(user=User.current)
+    user.allowed_to?(:view_project, self)
+  end
+  
   def self.visible_by(user=nil)
     ActiveSupport::Deprecation.warn "Project.visible_by is deprecated and will be removed in Redmine 1.3.0. Use Project.visible_condition instead."
     visible_condition(user || User.current)
@@ -563,7 +568,27 @@
   def enabled_module_names
     enabled_modules.collect(&:name)
   end
-  
+
+  # Enable a specific module
+  #
+  # Examples:
+  #   project.enable_module!(:issue_tracking)
+  #   project.enable_module!("issue_tracking")
+  def enable_module!(name)
+    enabled_modules << EnabledModule.new(:name => name.to_s) unless module_enabled?(name)
+  end
+
+  # Disable a module if it exists
+  #
+  # Examples:
+  #   project.disable_module!(:issue_tracking)
+  #   project.disable_module!("issue_tracking")
+  #   project.disable_module!(project.enabled_modules.first)
+  def disable_module!(target)
+    target = enabled_modules.detect{|mod| target.to_s == mod.name} unless enabled_modules.include?(target)
+    target.destroy unless target.blank?
+  end
+
   safe_attributes 'name',
     'description',
     'homepage',