Commit c383bcdc2828c665db2df81c997bdcd00eef6099
1 parent
c4a8f9bf
Exists in
federation-webfinger
Creates concerns for concealing common attributes for different types of person
Showing
5 changed files
with
79 additions
and
54 deletions
Show diff stats
... | ... | @@ -0,0 +1,33 @@ |
1 | +module Human | |
2 | + extend ActiveSupport::Concern | |
3 | + | |
4 | + included do | |
5 | + has_many :comments, :foreign_key => :author_id | |
6 | + has_many :abuse_reports, :foreign_key => 'reporter_id', :dependent => :destroy | |
7 | + | |
8 | + scope :abusers, -> { | |
9 | + joins(:abuse_complaints).where('tasks.status = 3').distinct.select('profiles.*') | |
10 | + } | |
11 | + scope :non_abusers, -> { | |
12 | + distinct.select("profiles.*"). | |
13 | + joins("LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'"). | |
14 | + where("tasks.status != 3 OR tasks.id is NULL") | |
15 | + } | |
16 | + end | |
17 | + | |
18 | + def already_reported?(profile) | |
19 | + abuse_reports.any? { |report| report.abuse_complaint.reported == profile && report.abuse_complaint.opened? } | |
20 | + end | |
21 | + | |
22 | + def register_report(abuse_report, profile) | |
23 | + AbuseComplaint.create!(:reported => profile, :target => profile.environment) if !profile.opened_abuse_complaint | |
24 | + abuse_report.abuse_complaint = profile.opened_abuse_complaint | |
25 | + abuse_report.reporter = self | |
26 | + abuse_report.save! | |
27 | + end | |
28 | + | |
29 | + def abuser? | |
30 | + AbuseComplaint.finished.where(:requestor_id => self).count > 0 | |
31 | + end | |
32 | + | |
33 | +end | ... | ... |
... | ... | @@ -0,0 +1,33 @@ |
1 | +module ProfileEntity | |
2 | + extend ActiveSupport::Concern | |
3 | + | |
4 | + included do | |
5 | + attr_accessible :name, :identifier, :environment, :redirection_after_login | |
6 | + | |
7 | + validates_presence_of :identifier, :name | |
8 | + validates_inclusion_of :redirection_after_login, :in => Environment.login_redirection_options.keys, :allow_nil => true | |
9 | + | |
10 | + belongs_to :environment | |
11 | + has_many :search_terms, :as => :context | |
12 | + has_many :abuse_complaints, :foreign_key => 'requestor_id', :dependent => :destroy | |
13 | + | |
14 | + end | |
15 | + | |
16 | + def disable | |
17 | + self.visible = false | |
18 | + self.save | |
19 | + end | |
20 | + | |
21 | + def enable | |
22 | + self.visible = true | |
23 | + self.save | |
24 | + end | |
25 | + | |
26 | + def preferred_login_redirection | |
27 | + redirection_after_login.blank? ? environment.redirection_after_login : redirection_after_login | |
28 | + end | |
29 | + | |
30 | + def opened_abuse_complaint | |
31 | + abuse_complaints.opened.first | |
32 | + end | |
33 | +end | ... | ... |
app/models/person.rb
1 | 1 | # A person is the profile of an user holding all relationships with the rest of the system |
2 | 2 | class Person < Profile |
3 | 3 | |
4 | + include Human | |
5 | + | |
4 | 6 | attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone, :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference, :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study, :custom_area_of_study, :professional_activity, :organization_website, :following_articles |
5 | 7 | |
6 | 8 | SEARCH_FILTERS = { |
... | ... | @@ -88,7 +90,6 @@ class Person < Profile |
88 | 90 | memberships.where('role_assignments.role_id = ?', role.id) |
89 | 91 | end |
90 | 92 | |
91 | - has_many :comments, :foreign_key => :author_id | |
92 | 93 | has_many :article_followers, :dependent => :destroy |
93 | 94 | has_many :following_articles, :class_name => 'Article', :through => :article_followers, :source => :article |
94 | 95 | has_many :friendships, :dependent => :destroy |
... | ... | @@ -100,8 +101,6 @@ class Person < Profile |
100 | 101 | |
101 | 102 | has_many :requested_tasks, :class_name => 'Task', :foreign_key => :requestor_id, :dependent => :destroy |
102 | 103 | |
103 | - has_many :abuse_reports, :foreign_key => 'reporter_id', :dependent => :destroy | |
104 | - | |
105 | 104 | has_many :mailings |
106 | 105 | |
107 | 106 | has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id, :dependent => :destroy |
... | ... | @@ -123,15 +122,6 @@ class Person < Profile |
123 | 122 | |
124 | 123 | scope :more_popular, -> { order 'friends_count DESC' } |
125 | 124 | |
126 | - scope :abusers, -> { | |
127 | - joins(:abuse_complaints).where('tasks.status = 3').distinct.select('profiles.*') | |
128 | - } | |
129 | - scope :non_abusers, -> { | |
130 | - distinct.select("profiles.*"). | |
131 | - joins("LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'"). | |
132 | - where("tasks.status != 3 OR tasks.id is NULL") | |
133 | - } | |
134 | - | |
135 | 125 | scope :admins, -> { joins(:role_assignments => :role).where('roles.key = ?', 'environment_administrator') } |
136 | 126 | scope :activated, -> { joins(:user).where('users.activation_code IS NULL AND users.activated_at IS NOT NULL') } |
137 | 127 | scope :deactivated, -> { joins(:user).where('NOT (users.activation_code IS NULL AND users.activated_at IS NOT NULL)') } |
... | ... | @@ -517,21 +507,6 @@ class Person < Profile |
517 | 507 | leave_hash.to_json |
518 | 508 | end |
519 | 509 | |
520 | - def already_reported?(profile) | |
521 | - abuse_reports.any? { |report| report.abuse_complaint.reported == profile && report.abuse_complaint.opened? } | |
522 | - end | |
523 | - | |
524 | - def register_report(abuse_report, profile) | |
525 | - AbuseComplaint.create!(:reported => profile, :target => profile.environment) if !profile.opened_abuse_complaint | |
526 | - abuse_report.abuse_complaint = profile.opened_abuse_complaint | |
527 | - abuse_report.reporter = self | |
528 | - abuse_report.save! | |
529 | - end | |
530 | - | |
531 | - def abuser? | |
532 | - AbuseComplaint.finished.where(:requestor_id => self).count > 0 | |
533 | - end | |
534 | - | |
535 | 510 | def control_panel_settings_button |
536 | 511 | {:title => _('Edit Profile'), :icon => 'edit-profile'} |
537 | 512 | end | ... | ... |
app/models/profile.rb
... | ... | @@ -3,9 +3,10 @@ |
3 | 3 | # which by default is the one returned by Environment:default. |
4 | 4 | class Profile < ApplicationRecord |
5 | 5 | |
6 | - attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, | |
7 | - :redirection_after_login, :custom_url_redirection, | |
8 | - :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret, :profile_admin_mail_notification | |
6 | + include ProfileEntity | |
7 | + | |
8 | + attr_accessible :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, | |
9 | + :custom_url_redirection, :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret, :profile_admin_mail_notification | |
9 | 10 | |
10 | 11 | # use for internationalizable human type names in search facets |
11 | 12 | # reimplement on subclasses |
... | ... | @@ -224,8 +225,6 @@ class Profile < ApplicationRecord |
224 | 225 | welcome_page && welcome_page.published ? welcome_page.body : nil |
225 | 226 | end |
226 | 227 | |
227 | - has_many :search_terms, :as => :context | |
228 | - | |
229 | 228 | def scraps(scrap=nil) |
230 | 229 | scrap = scrap.is_a?(Scrap) ? scrap.id : scrap |
231 | 230 | scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) |
... | ... | @@ -278,7 +277,6 @@ class Profile < ApplicationRecord |
278 | 277 | |
279 | 278 | has_many :domains, :as => :owner |
280 | 279 | belongs_to :preferred_domain, :class_name => 'Domain', :foreign_key => 'preferred_domain_id' |
281 | - belongs_to :environment | |
282 | 280 | |
283 | 281 | has_many :articles, :dependent => :destroy |
284 | 282 | belongs_to :home_page, :class_name => Article.name, :foreign_key => 'home_page_id' |
... | ... | @@ -305,8 +303,6 @@ class Profile < ApplicationRecord |
305 | 303 | has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization' |
306 | 304 | has_many :categories_including_virtual, :through => :profile_categorizations_including_virtual, :source => :category |
307 | 305 | |
308 | - has_many :abuse_complaints, :foreign_key => 'requestor_id', :dependent => :destroy | |
309 | - | |
310 | 306 | has_many :profile_suggestions, :foreign_key => :suggestion_id, :dependent => :destroy |
311 | 307 | |
312 | 308 | def top_level_categorization |
... | ... | @@ -401,7 +397,6 @@ class Profile < ApplicationRecord |
401 | 397 | self.all |
402 | 398 | end |
403 | 399 | |
404 | - validates_presence_of :identifier, :name | |
405 | 400 | validates_length_of :nickname, :maximum => 16, :allow_nil => true |
406 | 401 | validate :valid_template |
407 | 402 | validate :valid_identifier |
... | ... | @@ -1042,20 +1037,6 @@ private :generate_url, :url_options |
1042 | 1037 | end |
1043 | 1038 | end |
1044 | 1039 | |
1045 | - def opened_abuse_complaint | |
1046 | - abuse_complaints.opened.first | |
1047 | - end | |
1048 | - | |
1049 | - def disable | |
1050 | - self.visible = false | |
1051 | - self.save | |
1052 | - end | |
1053 | - | |
1054 | - def enable | |
1055 | - self.visible = true | |
1056 | - self.save | |
1057 | - end | |
1058 | - | |
1059 | 1040 | def control_panel_settings_button |
1060 | 1041 | {:title => _('Edit Profile'), :icon => 'edit-profile'} |
1061 | 1042 | end |
... | ... | @@ -1122,10 +1103,6 @@ private :generate_url, :url_options |
1122 | 1103 | display_private_info_to?(current_person) || (public_fields.include?(field) && public?) |
1123 | 1104 | end |
1124 | 1105 | |
1125 | - validates_inclusion_of :redirection_after_login, :in => Environment.login_redirection_options.keys, :allow_nil => true | |
1126 | - def preferred_login_redirection | |
1127 | - redirection_after_login.blank? ? environment.redirection_after_login : redirection_after_login | |
1128 | - end | |
1129 | 1106 | settings_items :custom_url_redirection, type: String, default: nil |
1130 | 1107 | |
1131 | 1108 | def remove_from_suggestion_list(person) | ... | ... |