Commit d9394c87c83e05fafbb78d4fbd48264cf8f90501
1 parent
3aa7898c
Exists in
master
and in
29 other branches
Display location only if address' fields are public
Showing
2 changed files
with
19 additions
and
3 deletions
Show diff stats
app/helpers/profile_helper.rb
| 1 | 1 | module ProfileHelper |
| 2 | 2 | |
| 3 | 3 | def display_field(title, profile, field, force = false) |
| 4 | - if (!force && !profile.active_fields.include?(field.to_s)) || | |
| 5 | - (profile.active_fields.include?(field.to_s) && !profile.public_fields.include?(field.to_s) && (!user || (user != profile && !user.is_a_friend?(profile)))) | |
| 4 | + if not force or not profile.may_display_field_to? field, user | |
| 6 | 5 | return '' |
| 7 | 6 | end |
| 8 | 7 | value = profile.send(field) | ... | ... |
app/models/profile.rb
| ... | ... | @@ -226,12 +226,14 @@ class Profile < ActiveRecord::Base |
| 226 | 226 | |
| 227 | 227 | belongs_to :region |
| 228 | 228 | |
| 229 | + LOCATION_FIELDS = %w[address district city state country_name zip_code] | |
| 230 | + | |
| 229 | 231 | def location(separator = ' - ') |
| 230 | 232 | myregion = self.region |
| 231 | 233 | if myregion |
| 232 | 234 | myregion.hierarchy.reverse.first(2).map(&:name).join(separator) |
| 233 | 235 | else |
| 234 | - %w[address district city state country_name zip_code ].map {|item| (self.respond_to?(item) && !self.send(item).blank?) ? self.send(item) : nil }.compact.join(separator) | |
| 236 | + LOCATION_FIELDS.map {|item| (self.respond_to?(item) && !self.send(item).blank?) ? self.send(item) : nil }.compact.join(separator) | |
| 235 | 237 | end |
| 236 | 238 | end |
| 237 | 239 | |
| ... | ... | @@ -882,6 +884,21 @@ private :generate_url, :url_options |
| 882 | 884 | [] |
| 883 | 885 | end |
| 884 | 886 | |
| 887 | + def may_display_field_to? field, user = nil | |
| 888 | + if not self.active_fields.include? field.to_s | |
| 889 | + self.send "may_display_#{field}_to?", user rescue true | |
| 890 | + else | |
| 891 | + not (!self.public_fields.include? field.to_s and (!user or (user != self and !user.is_a_friend?(self)))) | |
| 892 | + end | |
| 893 | + end | |
| 894 | + | |
| 895 | + def may_display_location_to? user = nil | |
| 896 | + LOCATION_FIELDS.each do |field| | |
| 897 | + return false if !self.may_display_field_to? field, user | |
| 898 | + end | |
| 899 | + return true | |
| 900 | + end | |
| 901 | + | |
| 885 | 902 | # field => privacy (e.g.: "address" => "public") |
| 886 | 903 | def fields_privacy |
| 887 | 904 | self.data[:fields_privacy] | ... | ... |