Merge branch 'master' of github.com:diaspora/diaspora_rails into friend-refactor
This commit is contained in:
commit
7a556e1b3c
5 changed files with 59 additions and 16 deletions
|
|
@ -3,6 +3,7 @@ class Request
|
|||
include MongoMapper::Document
|
||||
include Diaspora::Webhooks
|
||||
include ROXML
|
||||
include Encryptable
|
||||
|
||||
xml_accessor :_id
|
||||
xml_accessor :person, :as => Person
|
||||
|
|
@ -38,6 +39,25 @@ class Request
|
|||
p.save
|
||||
end
|
||||
|
||||
#ENCRYPTION
|
||||
before_validation :sign_if_mine
|
||||
validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature}
|
||||
|
||||
xml_accessor :creator_signature
|
||||
key :creator_signature, String
|
||||
|
||||
def signable_accessors
|
||||
accessors = self.class.roxml_attrs.collect{|definition|
|
||||
definition.accessor}
|
||||
accessors.delete 'person'
|
||||
accessors.delete 'creator_signature'
|
||||
accessors
|
||||
end
|
||||
|
||||
def signable_string
|
||||
signable_accessors.collect{|accessor|
|
||||
(self.send accessor.to_sym).to_s}.join ';'
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
class Retraction
|
||||
include ROXML
|
||||
include Diaspora::Webhooks
|
||||
include Encryptable
|
||||
|
||||
def self.for(object)
|
||||
retraction = self.new
|
||||
retraction.post_id= object.id
|
||||
retraction.person_id = person_id_from(object)
|
||||
retraction.type = self.type_name(object)
|
||||
retraction.type = object.class.to_s
|
||||
retraction
|
||||
end
|
||||
|
||||
|
|
@ -19,7 +20,13 @@ class Retraction
|
|||
attr_accessor :type
|
||||
|
||||
def perform
|
||||
return unless verify_signature(@creator_signature, Post.first(:id => post_id).person)
|
||||
|
||||
begin
|
||||
self.type.constantize.destroy(self.post_id)
|
||||
rescue NameError
|
||||
Rails.logger.info("Retraction for unknown type recieved.")
|
||||
end
|
||||
end
|
||||
|
||||
def self.person_id_from(object)
|
||||
|
|
@ -30,15 +37,28 @@ class Retraction
|
|||
end
|
||||
end
|
||||
|
||||
#ENCRYPTION
|
||||
xml_reader :creator_signature
|
||||
|
||||
def self.type_name(object)
|
||||
if object.is_a? Post
|
||||
object.class
|
||||
elsif object.is_a? Person
|
||||
'Person'
|
||||
else
|
||||
'Clowntown'
|
||||
def creator_signature
|
||||
@creator_signature ||= sign if person_id == User.owner.id
|
||||
end
|
||||
|
||||
def creator_signature= input
|
||||
@creator_signature = input
|
||||
end
|
||||
|
||||
def signable_accessors
|
||||
accessors = self.class.roxml_attrs.collect{|definition|
|
||||
definition.accessor}
|
||||
accessors.delete 'person'
|
||||
accessors.delete 'creator_signature'
|
||||
accessors
|
||||
end
|
||||
|
||||
def signable_string
|
||||
signable_accessors.collect{|accessor|
|
||||
(self.send accessor.to_sym).to_s}.join ';'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
end
|
||||
|
||||
def sign_with_key(key)
|
||||
Rails.logger.info("Signing #{signable_string} with key for person #{self.person.real_name}")
|
||||
Rails.logger.info("Signing #{signable_string}")
|
||||
GPGME::sign(signable_string,nil,
|
||||
{:armor=> true, :mode => GPGME::SIG_MODE_DETACH, :signers => [key]})
|
||||
end
|
||||
|
|
|
|||
|
|
@ -206,11 +206,12 @@ ul.comment_set {
|
|||
padding: 0.6em;
|
||||
border-bottom: 1px solid #cccccc; }
|
||||
ul.comment_set li.comment .from {
|
||||
color: #666666;
|
||||
font-weight: normal; }
|
||||
ul.comment_set li.comment .from a {
|
||||
color: #333333;
|
||||
font-weight: bold; }
|
||||
ul.comment_set li.comment div.time {
|
||||
color: #666666;
|
||||
font-size: 70%; }
|
||||
ul.comment_set li.comment form {
|
||||
margin-top: -5px; }
|
||||
|
||||
|
|
|
|||
|
|
@ -249,14 +249,16 @@ ul.comment_set
|
|||
:bottom 1px solid #ccc
|
||||
|
||||
.from
|
||||
:color #666
|
||||
:font
|
||||
:weight normal
|
||||
a
|
||||
:color #333
|
||||
:font
|
||||
:weight bold
|
||||
|
||||
div.time
|
||||
:color #666
|
||||
:font-size 70%
|
||||
|
||||
form
|
||||
:margin
|
||||
:top -5px
|
||||
|
|
|
|||
Loading…
Reference in a new issue