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 MongoMapper::Document
|
||||||
include Diaspora::Webhooks
|
include Diaspora::Webhooks
|
||||||
include ROXML
|
include ROXML
|
||||||
|
include Encryptable
|
||||||
|
|
||||||
xml_accessor :_id
|
xml_accessor :_id
|
||||||
xml_accessor :person, :as => Person
|
xml_accessor :person, :as => Person
|
||||||
|
|
@ -38,7 +39,26 @@ class Request
|
||||||
p.save
|
p.save
|
||||||
end
|
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
|
protected
|
||||||
|
|
||||||
def clean_link
|
def clean_link
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
class Retraction
|
class Retraction
|
||||||
include ROXML
|
include ROXML
|
||||||
include Diaspora::Webhooks
|
include Diaspora::Webhooks
|
||||||
|
include Encryptable
|
||||||
|
|
||||||
def self.for(object)
|
def self.for(object)
|
||||||
retraction = self.new
|
retraction = self.new
|
||||||
retraction.post_id= object.id
|
retraction.post_id= object.id
|
||||||
retraction.person_id = person_id_from(object)
|
retraction.person_id = person_id_from(object)
|
||||||
retraction.type = self.type_name(object)
|
retraction.type = object.class.to_s
|
||||||
retraction
|
retraction
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -19,7 +20,13 @@ class Retraction
|
||||||
attr_accessor :type
|
attr_accessor :type
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
self.type.constantize.destroy(self.post_id)
|
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
|
end
|
||||||
|
|
||||||
def self.person_id_from(object)
|
def self.person_id_from(object)
|
||||||
|
|
@ -30,15 +37,28 @@ class Retraction
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#ENCRYPTION
|
||||||
def self.type_name(object)
|
xml_reader :creator_signature
|
||||||
if object.is_a? Post
|
|
||||||
object.class
|
def creator_signature
|
||||||
elsif object.is_a? Person
|
@creator_signature ||= sign if person_id == User.owner.id
|
||||||
'Person'
|
|
||||||
else
|
|
||||||
'Clowntown'
|
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
end
|
end
|
||||||
|
|
||||||
def sign_with_key(key)
|
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,
|
GPGME::sign(signable_string,nil,
|
||||||
{:armor=> true, :mode => GPGME::SIG_MODE_DETACH, :signers => [key]})
|
{:armor=> true, :mode => GPGME::SIG_MODE_DETACH, :signers => [key]})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -206,11 +206,12 @@ ul.comment_set {
|
||||||
padding: 0.6em;
|
padding: 0.6em;
|
||||||
border-bottom: 1px solid #cccccc; }
|
border-bottom: 1px solid #cccccc; }
|
||||||
ul.comment_set li.comment .from {
|
ul.comment_set li.comment .from {
|
||||||
color: #666666;
|
|
||||||
font-weight: normal; }
|
font-weight: normal; }
|
||||||
ul.comment_set li.comment .from a {
|
ul.comment_set li.comment .from a {
|
||||||
color: #333333;
|
|
||||||
font-weight: bold; }
|
font-weight: bold; }
|
||||||
|
ul.comment_set li.comment div.time {
|
||||||
|
color: #666666;
|
||||||
|
font-size: 70%; }
|
||||||
ul.comment_set li.comment form {
|
ul.comment_set li.comment form {
|
||||||
margin-top: -5px; }
|
margin-top: -5px; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -249,13 +249,15 @@ ul.comment_set
|
||||||
:bottom 1px solid #ccc
|
:bottom 1px solid #ccc
|
||||||
|
|
||||||
.from
|
.from
|
||||||
:color #666
|
|
||||||
:font
|
:font
|
||||||
:weight normal
|
:weight normal
|
||||||
a
|
a
|
||||||
:color #333
|
|
||||||
:font
|
:font
|
||||||
:weight bold
|
:weight bold
|
||||||
|
|
||||||
|
div.time
|
||||||
|
:color #666
|
||||||
|
:font-size 70%
|
||||||
|
|
||||||
form
|
form
|
||||||
:margin
|
:margin
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue