views
This commit is contained in:
@@ -3,6 +3,7 @@ class Dmail < ActiveRecord::Base
|
||||
validates_presence_of :from_id
|
||||
validates_format_of :title, :with => /\S/
|
||||
validates_format_of :body, :with => /\S/
|
||||
before_validation :initialize_from_id, :on => :create
|
||||
belongs_to :owner, :class_name => "User"
|
||||
belongs_to :to, :class_name => "User"
|
||||
belongs_to :from, :class_name => "User"
|
||||
@@ -30,29 +31,33 @@ class Dmail < ActiveRecord::Base
|
||||
return if user.nil?
|
||||
self.to_id = user.id
|
||||
end
|
||||
|
||||
def from_name=(name)
|
||||
user = User.find_by_name(name)
|
||||
return if user.nil?
|
||||
self.from_id = user.id
|
||||
|
||||
def initialize_from_id
|
||||
self.from_id = CurrentUser.id
|
||||
end
|
||||
end
|
||||
|
||||
module FactoryMethods
|
||||
module ClassMethods
|
||||
def create_new(dmail)
|
||||
copy = dmail.clone
|
||||
copy.owner_id = dmail.to_id
|
||||
copy.save
|
||||
|
||||
copy = dmail.clone
|
||||
copy.owner_id = dmail.from_id
|
||||
copy.save
|
||||
end
|
||||
end
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def self.included(m)
|
||||
m.extend(ClassMethods)
|
||||
module ClassMethods
|
||||
def create_split(params)
|
||||
Dmail.transaction do
|
||||
copy = Dmail.new(params)
|
||||
copy.owner_id = copy.to_id
|
||||
copy.save
|
||||
|
||||
copy = Dmail.new(params)
|
||||
copy.owner_id = CurrentUser.id
|
||||
copy.save
|
||||
end
|
||||
end
|
||||
|
||||
def new_blank
|
||||
Dmail.new do |dmail|
|
||||
dmail.from_id = CurrentUser.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def build_response
|
||||
@@ -64,7 +69,7 @@ class Dmail < ActiveRecord::Base
|
||||
dmail.from_id = to_id
|
||||
dmail.parent_id = id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include AddressMethods
|
||||
@@ -91,4 +96,8 @@ class Dmail < ActiveRecord::Base
|
||||
def update_recipient
|
||||
to.update_attribute(:has_mail, true)
|
||||
end
|
||||
|
||||
def visible_to?(user)
|
||||
user.is_moderator? || owner_id == user.id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,7 @@ require 'digest/sha1'
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
class Error < Exception ; end
|
||||
class PrivilegeError < Exception ; end
|
||||
|
||||
attr_accessor :password, :old_password, :ip_addr
|
||||
attr_accessible :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr
|
||||
@@ -40,6 +41,8 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
module NameMethods
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
def name_to_id(name)
|
||||
Cache.get("uni:#{Cache.sanitize(name)}") do
|
||||
@@ -62,10 +65,6 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def self.included(m)
|
||||
m.extend(ClassMethods)
|
||||
end
|
||||
|
||||
def pretty_name
|
||||
name.tr("_", " ")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user