Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geozones as user segments #2859

Merged
merged 7 commits into from
Dec 20, 2021
Merged

Conversation

MariaCheca
Copy link
Contributor

@MariaCheca MariaCheca commented Aug 23, 2018

References

Objectives

Allow sending newsletters and admin notifications to users of a specific geozone.

Visual changes

Before these changes

When sending admin notifications and newsletters, geozones don't appear in the list of possible recipients

After these changes

When sending admin notifications and newsletters, geozones appear in the list of possible recipients

Notes for reviewers

There are some changes over the original pull requests used in Madrid's fork. The original pull requests were done with the idea that geozones were already in the database and geozones never change (which was the case in Madrid). So they used YAML files to get the geozone's name, they assumed the database already existed (and so new installations might crash when running db:create) and they defined the geozone segments methods when the UserSegments class was loaded (meaning that changing the database in production wouldn't have any effect until the server was restarted).

Here we're supporting the case of new installations (where geozones aren't already defined) and installations adding or removing geozones as time goes by.

@MariaCheca MariaCheca changed the title Adds geozones as user segments [Backport] Adds geozones as user segments Aug 23, 2018
@MariaCheca MariaCheca force-pushed the backport_1579-user_segments_for_geozones branch 3 times, most recently from a0ac5f4 to 5d0a400 Compare August 30, 2018 11:54
@javierm javierm force-pushed the backport_1579-user_segments_for_geozones branch from 5d0a400 to 9972ec3 Compare May 29, 2019 11:11
spec/lib/user_segments_spec.rb Outdated Show resolved Hide resolved
spec/lib/user_segments_spec.rb Outdated Show resolved Hide resolved
spec/lib/user_segments_spec.rb Outdated Show resolved Hide resolved
spec/lib/user_segments_spec.rb Outdated Show resolved Hide resolved
spec/lib/user_segments_spec.rb Outdated Show resolved Hide resolved
spec/lib/user_segments_spec.rb Outdated Show resolved Hide resolved
spec/lib/user_segments_spec.rb Outdated Show resolved Hide resolved
spec/features/admin/emails/newsletters_spec.rb Outdated Show resolved Hide resolved
spec/features/admin/emails/newsletters_spec.rb Outdated Show resolved Hide resolved
@javierm javierm self-assigned this May 29, 2019
@javierm javierm changed the title [Backport] Adds geozones as user segments Add geozones as user segments May 29, 2019
@javierm javierm force-pushed the backport_1579-user_segments_for_geozones branch 3 times, most recently from 0b5b339 to 62d023a Compare May 30, 2019 10:17
@javierm javierm force-pushed the backport_1579-user_segments_for_geozones branch from 62d023a to bcf2aaa Compare May 30, 2019 18:41
@javierm javierm removed the Backport label Oct 11, 2019
@javierm javierm added this to Reviewing in Roadmap via automation Oct 20, 2019
@javierm javierm moved this from Reviewing to Doing in Roadmap Oct 20, 2019
@javierm javierm removed the post 1.1 label Mar 11, 2020
@javierm javierm added this to Doing in Consul Democracy Mar 11, 2020
@javierm javierm removed this from Pending in Roadmap Mar 11, 2020
@javierm javierm force-pushed the backport_1579-user_segments_for_geozones branch 2 times, most recently from 4c98389 to 38c3882 Compare November 10, 2021 20:08
@javierm javierm moved this from Doing to Reviewing in Consul Democracy Nov 10, 2021
@javierm javierm force-pushed the backport_1579-user_segments_for_geozones branch from 38c3882 to 3065e9a Compare November 10, 2021 20:50
@javierm javierm force-pushed the backport_1579-user_segments_for_geozones branch 3 times, most recently from ca9c1c2 to a7604db Compare November 26, 2021 23:50
@javierm javierm force-pushed the backport_1579-user_segments_for_geozones branch from a7604db to 2414b86 Compare November 27, 2021 00:16
@taitus taitus self-assigned this Dec 20, 2021
voodoorai2000 and others added 4 commits December 20, 2021 15:07
We're going to make it dynamic using the geozones. Besides, class
methods can be overwritten using custom models, while constants can't be
overwritten without getting a warning [1].

Makes the definition of segments with geozones a little cleaner. I
think it’s worth it, compared to the slight memory gain of using a
constant [2].

[1] warning: already initialized constant UserSegments::SEGMENTS

[2] https://stackoverflow.com/questions/15903835/class-method-vs-constant-in-ruby-rails#answer-15903970
We generally use "#" to describe instance methods and "." to describe
class methods.
We're going to add geozones as user segments, so it's handy to have the
method in the UserSegments class.

We're also changing the `user_segment_emails` parameter name for
consistency and simplicity.
This way we don't have to use the `send` method in other places, like
the AdminNotification class, and we can change the internal
implementation at any point.
@javierm javierm force-pushed the backport_1579-user_segments_for_geozones branch from 2414b86 to 9bb8c20 Compare December 20, 2021 14:25
voodoorai2000 and others added 2 commits December 20, 2021 15:30
We were testing the creation of newsletters and admin notifications for
each existing segment, which IMHO is a bit overkill, considering how
slow system tests are.

So far we don't have any reasons to believe creating newsletters and
admin notifications will only work for some user segments, so we're
testing a random one instead.

Running these tests on my machine is now about 15 seconds faster.
@javierm javierm force-pushed the backport_1579-user_segments_for_geozones branch from 9bb8c20 to 18910d0 Compare December 20, 2021 14:31
The `parameterize` method uses the `I18n.transliterate` method, whose
documentation says:

```
I18n.transliterate("Ærøskøbing")
=> "AEroskobing"

I18n.transliterate("日本語")
=> "???"
```

That means we can't use it for dictionaries where characters don't have
a transliteration to the latin alphabet.

So we're changing the code in order to only transliterate characters
with a transliteration to the latin alphabet.

Note the first example ("Česká republika") already worked with the
previous code; the test has been added to make sure accented characters
are handled properly.
Consul Democracy automation moved this from Reviewing to Testing Dec 20, 2021
@javierm javierm merged commit e45ae0d into master Dec 20, 2021
Consul Democracy automation moved this from Testing to Release 1.5.0 Dec 20, 2021
@javierm javierm deleted the backport_1579-user_segments_for_geozones branch December 20, 2021 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants