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

Use the privacy of the external source to set defaults #241

Open
wants to merge 1 commit into
base: bbg-merge-28032017
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/models/table/user_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class UserTable < Sequel::Model
PRIVACY_LINK => 'link'
}

PRIVACY_TEXTS_TO_VALUES = {
'private' => PRIVACY_PRIVATE,
'public' => PRIVACY_PUBLIC,
'link' => PRIVACY_LINK
}

# For compatibility with AR model
def new_record?
new?
Expand Down Expand Up @@ -251,6 +257,7 @@ def privacy_text
PRIVACY_VALUES_TO_TEXTS[self.privacy].upcase
end


# TODO move privacy to value object
# enforce standard format for this field
def privacy=(value)
Expand Down Expand Up @@ -342,7 +349,8 @@ def partially_dependent_visualizations
private

def default_privacy_value
user.try(:private_tables_enabled) ? PRIVACY_PRIVATE : PRIVACY_PUBLIC
esv = external_source_visualization
esv.nil? ? (user.try(:private_tables_enabled) ? PRIVACY_PRIVATE : PRIVACY_PUBLIC) : PRIVACY_TEXTS_TO_VALUES[esv.privacy]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

end

def set_default_table_privacy
Expand Down Expand Up @@ -379,7 +387,7 @@ def create_default_visualization
attributions: esv.try(:attributions),
source: esv.try(:source),
tags: (tags.split(',') if tags),
privacy: UserTable::PRIVACY_VALUES_TO_TEXTS[default_privacy_value],
privacy: esv.nil? ? UserTable::PRIVACY_VALUES_TO_TEXTS[default_privacy_value] : esv.privacy,
user_id: user.id,
kind: kind,
exportable: esv.nil? ? true : esv.exportable,
Expand Down