Initial support for #2677
This commit is contained in:
@@ -59,7 +59,7 @@ class DmailsController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
def check_privilege(dmail)
|
def check_privilege(dmail)
|
||||||
if !dmail.visible_to?(CurrentUser.user)
|
if !dmail.visible_to?(CurrentUser.user, params[:key])
|
||||||
raise User::PrivilegeError
|
raise User::PrivilegeError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
require 'digest/sha1'
|
||||||
|
|
||||||
class Dmail < ActiveRecord::Base
|
class Dmail < ActiveRecord::Base
|
||||||
validates_presence_of :to_id
|
validates_presence_of :to_id
|
||||||
validates_presence_of :from_id
|
validates_presence_of :from_id
|
||||||
@@ -78,6 +80,32 @@ class Dmail < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module ApiMethods
|
||||||
|
def hidden_attributes
|
||||||
|
super + [:message_index]
|
||||||
|
end
|
||||||
|
|
||||||
|
def method_attributes
|
||||||
|
list = [:hash]
|
||||||
|
list
|
||||||
|
end
|
||||||
|
|
||||||
|
def serializable_hash(options = {})
|
||||||
|
options ||= {}
|
||||||
|
options[:methods] ||= []
|
||||||
|
options[:methods] += method_attributes
|
||||||
|
super(options)
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_xml(options = {}, &block)
|
||||||
|
# to_xml ignores the serializable_hash method
|
||||||
|
options ||= {}
|
||||||
|
options[:methods] ||= []
|
||||||
|
options[:methods] += method_attributes
|
||||||
|
super(options, &block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def for(user)
|
def for(user)
|
||||||
where("owner_id = ?", user)
|
where("owner_id = ?", user)
|
||||||
@@ -164,6 +192,7 @@ class Dmail < ActiveRecord::Base
|
|||||||
|
|
||||||
include AddressMethods
|
include AddressMethods
|
||||||
include FactoryMethods
|
include FactoryMethods
|
||||||
|
include ApiMethods
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
|
|
||||||
def validate_sender_is_not_banned
|
def validate_sender_is_not_banned
|
||||||
@@ -208,12 +237,13 @@ class Dmail < ActiveRecord::Base
|
|||||||
to.update_attribute(:has_mail, true)
|
to.update_attribute(:has_mail, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible_to?(user)
|
def hash
|
||||||
user.is_moderator? || owner_id == user.id
|
Digest::SHA1.hexdigest("#{title} #{body}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def visible_to?(user, key)
|
||||||
|
owner_id == user.id || (user.is_moderator? && key == self.hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
def hidden_attributes
|
|
||||||
super + [:message_index]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user