external_person.rb
2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# A pseudo profile is a person from a remote network
class ExternalPerson < ActiveRecord::Base
include Human
include ProfileEntity
validates_uniqueness_of :identifier, scope: :source
validates_presence_of :source, :email, :created_at
attr_accessible :source, :email, :created_at
def self.get_or_create(webfinger)
user = ExternalPerson.find_by(identifier: webfinger.identifier, source: webfinger.domain)
if user.nil?
user = ExternalPerson.create!(identifier: webfinger.identifier,
name: webfinger.name,
source: webfinger.domain,
email: webfinger.email,
created_at: webfinger.created_at
)
end
user
end
def url
"http://#{self.source}/#{self.identifier}"
end
alias :public_profile_url :url
def avatar
"http://#{self.source}/profile/#{self.identifier}/icon/"
end
def admin_url
"http://#{self.source}/myprofile/#{self.identifier}"
end
def profile_custom_icon(gravatar_default=nil)
self.avatar
end
def preferred_login_redirection
environment.redirection_after_login
end
def person?
true
end
def is_admin?(environment = nil)
false
end
def lat
nil
end
def lng
nil
end
def role_assignments
RoleAssignment.none
end
def favorite_enterprises
Enterprise.none
end
def memberships
Profile.none
end
def friendships
Profile.none
end
def tasks
Task.none
end
def suggested_profiles
ProfileSuggestion.none
end
def suggested_people
ProfileSuggestion.none
end
def suggested_communities
ProfileSuggestion.none
end
def add_friend(friend, group = nil)
false
end
def follows?(profile)
false
end
def is_a_friend?(person)
false
end
def already_request_friendship?(person)
false
end
class ExternalPerson::Image
def initialize(path)
@path = path
end
def public_filename(size = nil)
URI.join(@path, size.to_s)
end
def content_type
# This is not really going to be used anywhere that matters
# so we are hardcodding it here.
'image/png'
end
end
def image
ExternalPerson::Image.new(avatar)
end
def is_template?
false
end
def enterprises
[]
end
def friends
[]
end
def data_hash(gravatar_default = nil)
friends_list = {}
{
'login' => self.identifier,
'name' => self.name,
'email' => self.email,
'avatar' => self.profile_custom_icon(gravatar_default),
'is_admin' => self.is_admin?,
'since_month' => self.created_at.month,
'since_year' => self.created_at.year,
'email_domain' => self.source,
'friends_list' => friends_list,
'enterprises' => [],
'amount_of_friends' => friends_list.count,
'chat_enabled' => false
}
end
end