Skip to content

Commit

Permalink
Attempts to make coordinate interpolation a little bit harder (#2959)
Browse files Browse the repository at this point in the history
When viewing an obs where you can't see the true coordinates:
  * Removed prev/next links on obs detail
  * Removed "More from" section and other extras at the bottom that show
    context
  * Truncated Date Added and Date Observed to year and month
  * Obscure activity item timestamps on obscured observations

When viewing an obs on the same day as an obs where you can't see the true
coordinates:
  * Stopped showing obscured obs as prev or next
  * Stopped showing obscured obs in contextual sections

When viewing obs/search:
  * Truncated dates when you can't see the true coordinates
  * Removed attributes that show full time stamp
  * Removed full observed date from grid on obs search when obscured

On observations/:login:
  * Removed obs where you can't see the true coordinates entirely

Currently an opt-in test for curators.
  • Loading branch information
kueda committed Apr 6, 2021
1 parent e555ce9 commit 938c742
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 83 deletions.
24 changes: 22 additions & 2 deletions app/assets/javascripts/ang/inaturalist_angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,27 @@ iNatAPI.directive('inatCalendarDate', ["shared", function(shared) {
scope: {
time: "=",
date: "=",
timezone: "="
timezone: "=",
obscured: "=",
short: "="
},
link: function(scope, elt, attr) {
scope.dateString = function() {
if( !scope.date ) {
return shared.t( "missing_date" );
}
if (
typeof ( CURRENT_USER ) === "object"
&& CURRENT_USER.testGroups
&& CURRENT_USER.testGroups.indexOf( "interpolation" ) >= 0
&& scope.obscured
) {
return moment(scope.date).format(
scope.short
? I18n.t( "momentjs.month_year_short" )
: I18n.t( "momentjs.month_year" )
);
}
var date = moment(scope.date),
now = moment(new Date()),
dateString;
Expand All @@ -174,7 +188,13 @@ iNatAPI.directive('inatCalendarDate', ["shared", function(shared) {
return dateString;
}
scope.timeString = function() {
if( !scope.time ) { return; }
if ( scope.obscured ) return;
if(
typeof ( CURRENT_USER ) === "object"
&& CURRENT_USER.testGroups
&& CURRENT_USER.testGroups.indexOf( "interpolation" ) >= 0
&& !scope.time
) return;
scope.timezone = scope.timezone || "UTC";
return moment(scope.time.replace( /[+-]\d\d:\d\d/, "" )).tz(scope.timezone).format("LT z");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
%span.favorites{"ng-show" => "o.faves_count > 0", title: "{{ shared.t('x_faves', {count: o.faves_count}) }}"}
%i.fa.fa-star
{{ o.faves_count }}
%span.pull-right{"am-time-ago" => "o.time_observed_at || o.observed_on", title: "{{ shared.t('observed_on') + ' ' + (o.time_observed_at || o.observed_on ) }}"}
%span.pull-right{"am-time-ago" => "o.time_observed_at || o.observed_on", title: "{{ (!o.obscured || o.private_geojson ) && shared.t('observed_on') + ' ' + (o.time_observed_at || o.observed_on ) }}"}
.spinner.ng-cloak{ "ng-show": "pagination.searching" }
%span.fa.fa-spin.fa-refresh
.noresults.text-muted.ng-cloak{ "ng-show" => "noObservations( )" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
%a{ href: "/observations/{{ o.id }}", title: "{{ o.user.login }}", target: "_self" }
{{ o.user.login }}
%td{ :class => "{{ params.order_by == 'observed_on' ? 'sorting' : '' }}", title: "{{ shared.t('observed_on_datetime', { datetime: o.time_observed_at || o.observed_on }) }}" }
%inat-calendar-date{ date: "o.observed_on_details.date", timezone: "o.observed_time_zone", time: "o.time_observed_at" }
%inat-calendar-date{ date: "o.observed_on_details.date", timezone: "o.observed_time_zone", time: "o.time_observed_at", obscured: "o.obscured && !o.private_geojson" }
%td.place
%span{ "ng-bind-html": "o.placeIcon() | sanitize" }
{{ o.displayPlace( ) }}
%td{ :class => "{{ params.order_by == 'observations.id' ? 'sorting' : '' }}", title: "{{ shared.t('added_on_datetime', { datetime: o.created_at } ) }}" }
%inat-calendar-date{ date: "o.created_at_details.date", timezone: "o.created_time_zone", time: "o.created_at", }
%inat-calendar-date{ date: "o.created_at_details.date", timezone: "o.created_time_zone", time: "o.created_at", obscured: "o.obscured && !o.private_geojson" }
.spinner.ng-cloak{ "ng-show": "pagination.searching" }
%span.fa.fa-spin.fa-refresh
.noresults.text-muted.ng-cloak{ "ng-show" => "noObservations( )" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
%span.location{ title: "{{ o.displayPlace() }}" }
.hidden-lg {{ o.displayPlace() | characters:6:true }}
.visible-lg-inline-block {{ o.displayPlace() | characters:18:true }}
%span.date{ title: "{{ shared.t( 'observed_on_datetime', { datetime: shared.l( 'datetime.formats.long', o.time_observed_at || o.observed_on ) } ) }}" }
%span.hidden-lg {{ (o.observed_on | amDateFormat : 'l') || shared.t('unknown') }}
%span.visible-lg-inline-block {{ (o.observed_on | amDateFormat : 'll') || shared.t('unknown') }}
%inat-calendar-date.hidden-lg{ date: "o.observed_on_details.date", timezone: "o.observed_time_zone", obscured: "o.obscured && !o.private_geojson", short: "true" }
%inat-calendar-date.visible-lg-inline-block{ date: "o.observed_on_details.date", timezone: "o.observed_time_zone", obscured: "o.obscured && !o.private_geojson" }
.meta.ng-cloak
%span{ :class => "quality_grade {{ o.quality_grade }}" }
{{ o.qualityGrade( ) }}
Expand All @@ -27,4 +26,4 @@
%span.favorites{ "ng-show" => "o.faves_count > 0", title: "{{ shared.t('x_faves', {count: o.faves_count}) }}" }
%i.fa.fa-star
{{ o.faves_count }}
%span.created_at.pull-right{ "am-time-ago" => "o.created_at", title: "{{ shared.t('added_on_datetime', { datetime: shared.l('datetime.formats.long', o.created_at )}) }}" }
%span.created_at.pull-right{ "am-time-ago" => "o.created_at", title: "{{ (!o.obscured || o.private_geojson ) && shared.t('added_on_datetime', { datetime: shared.l('datetime.formats.long', o.created_at )}) }}" }
7 changes: 7 additions & 0 deletions app/controllers/calendars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def show
{ taxon: { taxon_names: :place_taxon_names } },
{ photos: :flags }
)
if @selected_user != current_user && current_user && current_user.in_test_group?( "interpolation" )
filtered_obs = @observations.select {|o| o.coordinates_viewable_by?( current_user )}
diff = @observations.total_entries - filtered_obs.size
@observations = WillPaginate::Collection.create( 1, 200, @observations.total_entries - diff ) do |pager|
pager.replace( filtered_obs )
end
end
@taxa = @observations.map{|o| o.taxon}.uniq.compact
@taxa_count = @taxa.size
@taxa_by_iconic_taxon_id = @taxa.group_by{|t| t.iconic_taxon_id}
Expand Down
12 changes: 11 additions & 1 deletion app/controllers/observations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ def show
else
I18n.t( "something" )
end
@shareable_description = @observation.to_plain_s( no_place_guess: !@coordinates_viewable, viewer: current_user )
@shareable_description = @observation.to_plain_s(
no_place_guess: !@coordinates_viewable,
viewer: current_user
)
unless @observation.description.blank?
@shareable_description += ".\n\n#{FakeView.truncate( @observation.description, length: 100 )}"
end
Expand Down Expand Up @@ -1235,6 +1238,13 @@ def by_login
@observations = Observation.page_of_results(search_params)
set_up_instance_variables(search_params)
Observation.preload_for_component(@observations, logged_in: !!current_user)
if @selected_user != current_user && current_user && current_user.in_test_group?( "interpolation" )
filtered_obs = @observations.select {|o| o.coordinates_viewable_by?( current_user )}
diff = @observations.total_entries - filtered_obs.size
@observations = WillPaginate::Collection.create( 1, 200, @observations.total_entries - diff ) do |pager|
pager.replace( filtered_obs )
end
end
respond_to do |format|
format.html do
prepare_map(search_params)
Expand Down
18 changes: 10 additions & 8 deletions app/models/observation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -801,13 +801,15 @@ def to_plain_s(options = {})
key += "_from_place"
i18n_vars[:place] = place_guess
end
unless self.observed_on.blank?
key += "_on_day"
i18n_vars[:day] = I18n.l( self.observed_on, format: :long )
end
unless self.time_observed_at.blank? || options[:no_time]
key += "_at_time"
i18n_vars[:time] = I18n.l( time_observed_at_in_zone, format: :compact )
if !options[:viewer] || !options[:viewer].in_test_group?( "interpolation" ) || coordinates_viewable_by?( options[:viewer] )
unless self.observed_on.blank?
key += "_on_day"
i18n_vars[:day] = I18n.l( self.observed_on, format: :long )
end
unless self.time_observed_at.blank? || options[:no_time]
key += "_at_time"
i18n_vars[:time] = I18n.l( time_observed_at_in_zone, format: :compact )
end
end
unless options[:no_user]
key += "_by_user"
Expand Down Expand Up @@ -1437,7 +1439,7 @@ def geoprivacy_obscured?
geoprivacy == OBSCURED
end

def coordinates_viewable_by?(viewer)
def coordinates_viewable_by?( viewer )
return true unless coordinates_obscured?
return false if viewer.blank?
viewer = User.find_by_id(viewer) unless viewer.is_a?(User)
Expand Down
3 changes: 2 additions & 1 deletion app/views/layouts/bootstrap.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@
prefers_medialess_obs_maps: <%= current_user.prefers_medialess_obs_maps %>,
prefers_captive_obs_maps: <%= current_user.prefers_captive_obs_maps %>,
preferred_observations_search_map_type: "<%= current_user.preferred_observations_search_map_type %>",
prefers_not_nearby_suggestions: <%= !!session[:prefers_not_nearby_suggestions] %>
prefers_not_nearby_suggestions: <%= !!session[:prefers_not_nearby_suggestions] %>,
testGroups: <%= current_user.test_groups_array.to_json.html_safe %>
};
<% end -%>
var RAILS_FLASH = <%= flash.to_hash.compact.to_json.html_safe %>;
Expand Down
15 changes: 9 additions & 6 deletions app/views/observations/_observation_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Some notes:
elsif observation.quality_grade == Observation::RESEARCH_GRADE
css_class += ' research_grade'
end
testing_interpolation_mitigation = current_user && current_user.in_test_group?( "interpolation" )
coordinates_viewable ||= !testing_interpolation_mitigation || observation.coordinates_viewable_by?( current_user )
-%>
<div id="observation-<%= observation.id rescue rand(999) %>" class="<%= css_class %>"
data-taxon-id=<%= observation.taxon_id %>
Expand Down Expand Up @@ -129,20 +131,21 @@ Some notes:
</div>
<div class="observed_on attribute">
<h4 class="label"><%=t :observation_date %></h4>
<span class="date" title="<%= observation.observed_on ? observation.observed_on.strftime("%Y-%m-%d") : '' %>">
<%#= observation.observed_on ? observation.observed_on.strftime("%b. %e, %Y") : 'the past' %>
<span class="date" title="<%= observation.observed_on && coordinates_viewable ? observation.observed_on.strftime("%Y-%m-%d") : '' %>">
<% if observation.observed_on -%>
<%= link_to t("date_format.month.#{observation.observed_on.strftime('%B').downcase}").titleize,
observations_path( user_id: observation.user.login, on: "#{observation.observed_on.year}-#{observation.observed_on.month}") %>
<%= link_to observation.observed_on.day,
observations_path( user_id: observation.user.login, on: "#{observation.observed_on.year}-#{observation.observed_on.month}-#{observation.observed_on.day}") %>,
<%= link_to observation.observed_on.year,
<% if coordinates_viewable %>
<%= link_to observation.observed_on.day,
observations_path( user_id: observation.user.login, on: "#{observation.observed_on.year}-#{observation.observed_on.month}-#{observation.observed_on.day}") %>,
<% end %>
<%= link_to observation.observed_on.year,
observations_path( user_id: observation.user.login, on: observation.observed_on.year) %>
<% else %>
<%=t :missing_date %>
<% end -%>
</span>
<% if observation.time_observed_at %>
<% if observation.time_observed_at && coordinates_viewable %>
<span class="time">
<%= observation.time_observed_at.in_time_zone(observation.time_zone).strftime("%I:%M %p %Z") %>
</span>
Expand Down
39 changes: 32 additions & 7 deletions app/webpack/observations/show/components/activity_item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,37 @@ class ActivityItem extends React.Component {
}
const elementID = this.isID ? `activity_identification_${item.uuid}` : `activity_comment_${item.uuid}`;
const itemURL = this.isID ? `/identifications/${item.uuid}` : `/comments/${item.uuid}`;
let time = (
<time
className="time"
dateTime={item.created_at}
title={moment( item.created_at ).format( "LLL" )}
>
<a href={itemURL} target={linkTarget}>{relativeTime}</a>
</time>
);
const { testingInterpolationMitigation } = config;
if (
testingInterpolationMitigation
&& observation
&& observation.obscured
&& !observation.private_geojson
) {
const coordinatesObscured = observation
&& observation.obscured
&& !observation.private_geojson;
const viewerCreatedItem = config
&& config.currentUser
&& item.user
&& item.user.id === config.currentUser.id;
if ( coordinatesObscured && !viewerCreatedItem ) {
time = (
<time className="time">
{ moment( item.created_at ).format( I18n.t( "momentjs.month_year_short" ) ) }
</time>
);
}
}
return (
<div id={elementID} className={`ActivityItem ${className} ${byClass}`}>
<div className="icon">
Expand All @@ -575,13 +606,7 @@ class ActivityItem extends React.Component {
<Panel.Title>
<span className="title_text" dangerouslySetInnerHTML={{ __html: header }} />
{headerItems}
<time
className="time"
dateTime={item.created_at}
title={moment( item.created_at ).format( "LLL" )}
>
<a href={itemURL} target={linkTarget}>{relativeTime}</a>
</time>
{ time }
<ActivityItemMenu
item={item}
observation={observation}
Expand Down
Loading

0 comments on commit 938c742

Please sign in to comment.