-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] split audience from visibility
Essentially we go back to the original
- Loading branch information
Showing
36 changed files
with
253 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,68 @@ | ||
# frozen_string_literal: true | ||
|
||
# This could be nicely implemented as enum but it is not yet implemented for mysql | ||
# audience: 0=world, 1=intranet, 2=authenticated user | ||
# visibility: 0=public, 1=draft, 2=hidden | ||
# TODO: write unit tests | ||
# TODO: when importing legacy data: | ||
# - visible => audience=0 | ||
# - hidden => audience=4 | ||
# - visible => audience=0, visibility=0 | ||
# - hidden => audience=0, visibility=2 | ||
|
||
module AudienceLimitable | ||
AUDIENCE_OPTIONS = [ | ||
{ label: 'public', icon: 'globe' }, | ||
{ label: 'intranet', icon: 'home' }, | ||
{ label: 'authenticated', icon: 'user-check' } | ||
].freeze | ||
|
||
VISIBILITY_OPTIONS = [ | ||
{ label: 'published', icon: 'eye' }, | ||
{ label: 'draft', icon: 'edit-3' }, | ||
{ label: 'hidden', icon: 'eye-off' } | ||
].freeze | ||
|
||
extend ActiveSupport::Concern | ||
|
||
included do | ||
scope :world_visible, -> { where(audience: 0) } | ||
scope :intranet_visible, -> { where(audience: 0...2) } | ||
scope :auth_visible, -> { where(audience: 0...3) } | ||
scope :owner_visible, -> { where(audience: 0...4) } | ||
scope :for_audience, ->(audience) { where(audience: 0...(audience + 1)) } | ||
validates :audience, numericality: { in: 0...5 } | ||
# Reminder: ranges do not include the upper limit | ||
scope :world_visible, -> { where(audience: 0, visibility: 0) } | ||
scope :intranet_visible, -> { where(audience: 0...2, visibility: 0) } | ||
scope :auth_visible, -> { where(audience: 0...3, visibility: 0) } | ||
scope :owner_visible, -> { where(visibility: 0...2) } | ||
scope :for_audience, ->(audience) { where(audience: 0...(audience + 1), visibility: 0) } | ||
validates :audience, numericality: { in: 0...3 } | ||
validates :visibility, numericality: { in: 0...3 } | ||
end | ||
|
||
def visible_by?(level = 0) | ||
audience <= level | ||
end | ||
|
||
def world_visible? | ||
audience.zero? | ||
visibilty.zero? && audience.zero? | ||
end | ||
|
||
def intranet_visible? | ||
audience < 2 | ||
visibilty.zero? && audience < 2 | ||
end | ||
|
||
def auth_visible? | ||
audience < 3 | ||
visibilty.zero? && audience < 3 | ||
end | ||
|
||
def owner_visible? | ||
audience < 4 | ||
visibility != 2 | ||
end | ||
|
||
def hidden? | ||
audience > 3 | ||
visibility == 2 | ||
end | ||
|
||
def visibility_label(v = visibility) | ||
VISIBILITY_OPTIONS[v][:label] | ||
end | ||
|
||
def audience_label(v = audience) | ||
AUDIENCE_OPTIONS[v][:label] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
json.extract! award, :id, :title_en, :title_fr, :issuer, :year, | ||
:updated_at, :position, :audience, :visible | ||
:updated_at, :position, :audience, :visibility | ||
|
||
json.profile profile_url(award.profile, format: :json) | ||
json.url award_url(award, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
json.extract! box, :id, :type, :subkind, :title_en, :title_fr, :show_title, :locked, | ||
:updated_at, :position, :audience, :visible | ||
:updated_at, :position, :audience, :visibility | ||
json.profile profile_url(box.profile, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
json.extract! experience, :id, :title_en, :title_fr, :location, :year_begin, :year_end, :position, :created_at, | ||
:updated_at, :position, :audience | ||
:updated_at, :position, :audience, :visibility | ||
json.profile profile_url(experience.profile, format: :json) | ||
json.url experience_url(experience, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
json.extract! publication, :id, :title, :url, :authors, :year, | ||
:audience, :created_at, :position, :updated_at | ||
:audience, :visibility, :created_at, :position, :updated_at | ||
json.profile profile_url(publication.profile, format: :json) | ||
json.url publication_url(publication, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
json.extract! box, :id, :created_at, :updated_at | ||
json.extract! box, :id, :audience, :visibility, :created_at, :updated_at | ||
json.url box_url(box, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.