summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-11-20 15:40:16 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-11-20 15:40:16 +0000
commit987a5aa22114ec2e931464782351431e4dfec97c (patch)
tree57af15078250c620d494306c251ad66af779bc0b /app/models
parent99f9aea80a2bc43cdfc2933728f0ab72d7bf99d5 (diff)
downloadredmine-987a5aa22114ec2e931464782351431e4dfec97c.tar.gz
redmine-987a5aa22114ec2e931464782351431e4dfec97c.zip
Anonymous users can now be allowed to create, edit, comment issues, comment news and post messages in the forums.
These permissions need to be explicitly given to the Anonymous role (Admin -> Roles & Permissions -> Anonymous). git-svn-id: http://redmine.rubyforge.org/svn/trunk@919 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r--app/models/attachment.rb7
-rw-r--r--app/models/query.rb7
-rw-r--r--app/models/user.rb38
3 files changed, 26 insertions, 26 deletions
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index d2bcab33f..7262498c4 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -21,7 +21,7 @@ class Attachment < ActiveRecord::Base
belongs_to :container, :polymorphic => true
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
- validates_presence_of :container, :filename
+ validates_presence_of :container, :filename, :author
validates_length_of :filename, :maximum => 255
validates_length_of :disk_filename, :maximum => 255
@@ -82,11 +82,6 @@ class Attachment < ActiveRecord::Base
def increment_download
increment!(:downloads)
end
-
- # returns last created projects
- def self.most_downloaded
- find(:all, :limit => 5, :order => "downloads DESC")
- end
def project
container.is_a?(Project) ? container : container.project
diff --git a/app/models/query.rb b/app/models/query.rb
index 30df55b96..f869f648b 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -112,11 +112,8 @@ class Query < ActiveRecord::Base
def initialize(attributes = nil)
super attributes
self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
- end
-
- def executed_by=(user)
- @executed_by = user
- set_language_if_valid(user.language) if user
+ @executed_by = User.current.logged? ? User.current : nil
+ set_language_if_valid(executed_by.language) if executed_by
end
def validate
diff --git a/app/models/user.rb b/app/models/user.rb
index 2543bed19..93b73dd7a 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -19,6 +19,7 @@ require "digest/sha1"
class User < ActiveRecord::Base
# Account statuses
+ STATUS_ANONYMOUS = 0
STATUS_ACTIVE = 1
STATUS_REGISTERED = 2
STATUS_LOCKED = 3
@@ -36,15 +37,15 @@ class User < ActiveRecord::Base
# Prevents unauthorized assignments
attr_protected :login, :admin, :password, :password_confirmation, :hashed_password
- validates_presence_of :login, :firstname, :lastname, :mail
+ validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }
validates_uniqueness_of :login, :mail
# Login must contain lettres, numbers, underscores only
- validates_format_of :login, :with => /^[a-z0-9_\-@\.]+$/i
+ validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i
validates_length_of :login, :maximum => 30
validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i
validates_length_of :firstname, :lastname, :maximum => 30
- validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
- validates_length_of :mail, :maximum => 60
+ validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true
+ validates_length_of :mail, :maximum => 60, :allow_nil => true
# Password length between 4 and 12
validates_length_of :password, :in => 4..12, :allow_nil => true
validates_confirmation_of :password, :allow_nil => true
@@ -216,11 +217,17 @@ class User < ActiveRecord::Base
end
def self.current
- @current_user ||= AnonymousUser.new
+ @current_user ||= User.anonymous
end
def self.anonymous
- AnonymousUser.new
+ return @anonymous_user if @anonymous_user
+ anonymous_user = AnonymousUser.find(:first)
+ if anonymous_user.nil?
+ anonymous_user = AnonymousUser.create(:lastname => 'Anonymous', :firstname => '', :mail => '', :login => '', :status => 0)
+ raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
+ end
+ @anonymous_user = anonymous_user
end
private
@@ -231,16 +238,17 @@ private
end
class AnonymousUser < User
- def logged?
- false
- end
- def time_zone
- nil
+ def validate_on_create
+ # There should be only one AnonymousUser in the database
+ errors.add_to_base 'An anonymous user already exists.' if AnonymousUser.find(:first)
end
- # Anonymous user has no RSS key
- def rss_key
- nil
- end
+ # Overrides a few properties
+ def logged?; false end
+ def admin; false end
+ def name; 'Anonymous' end
+ def mail; nil end
+ def time_zone; nil end
+ def rss_key; nil end
end