Commit da3ae0ed838beabe4045886ccdcb20a7a191671e
Committed by
Larissa Reis
1 parent
57ac8d09
Exists in
federation-webfinger
Ticket #194: Get person or external person
Showing
3 changed files
with
14 additions
and
0 deletions
Show diff stats
app/models/concerns/external_user.rb
... | ... | @@ -11,6 +11,10 @@ module ExternalUser |
11 | 11 | ExternalPerson.where(id: self.external_person_id).first |
12 | 12 | end |
13 | 13 | |
14 | + def person_with_external | |
15 | + self.external_person || self.person_without_external | |
16 | + end | |
17 | + | |
14 | 18 | module ClassMethods |
15 | 19 | def webfinger_lookup(login, domain, environment) |
16 | 20 | if login && domain && environment.has_federated_network?(domain) | ... | ... |
app/models/user.rb
... | ... | @@ -108,6 +108,8 @@ class User < ApplicationRecord |
108 | 108 | has_one :person, dependent: :destroy, autosave: false |
109 | 109 | belongs_to :environment |
110 | 110 | |
111 | + alias_method_chain :person, :external | |
112 | + | |
111 | 113 | has_many :sessions, dependent: :destroy |
112 | 114 | # holds the current session, see lib/authenticated_system.rb |
113 | 115 | attr_accessor :session | ... | ... |
test/unit/user_test.rb
... | ... | @@ -759,6 +759,14 @@ class UserTest < ActiveSupport::TestCase |
759 | 759 | end |
760 | 760 | end |
761 | 761 | |
762 | + should 'get person or external person' do | |
763 | + user = create_user('new_user') | |
764 | + assert_kind_of Person, user.person | |
765 | + user.external_person_id = ExternalPerson.create!(identifier: 'new_user', name: 'New User').id | |
766 | + assert_kind_of ExternalPerson, user.person | |
767 | + assert_kind_of Person, user.person_without_external | |
768 | + end | |
769 | + | |
762 | 770 | protected |
763 | 771 | def new_user(options = {}) |
764 | 772 | user = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) | ... | ... |