DEV: migrate no_ads_for_groups to use IDs instead of group names (#77)

This commit is contained in:
Roman Rizzi 2019-07-16 11:35:16 -03:00 committed by GitHub
parent 3aa9cb8a0c
commit 09a92f3438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -46,12 +46,21 @@ export default Ember.Component.extend({
return true;
}
const groupNames = groups.map(g => g.name.toLowerCase());
const noAdsGroupNames = this.siteSettings.no_ads_for_groups
.split("|")
.map(g => g.toLowerCase());
let noAdsGroups = this.siteSettings.no_ads_for_groups
.split("|")
return !groupNames.any(g => noAdsGroupNames.includes(g));
// TODO: Remove when 2.4 becomes the new stable. This is for backwards compatibility.
const groupListUseIDs = this.site.group_list_use_ids;
let currentGroups = groups;
if (groupListUseIDs) {
currentGroups = currentGroups.map(g => g.id.toString());
} else {
currentGroups = currentGroups.map(g => g.name.toLowerCase());
noAdsGroups = noAdsGroups.map(g => g.toLowerCase());
}
return !currentGroups.any(g => noAdsGroups.includes(g));
},
@computed(

View File

@ -35,6 +35,11 @@ after_initialize do
require_dependency File.expand_path('../app/controllers/house_ad_settings_controller', __FILE__)
require_dependency 'application_controller'
# TODO: remove when 2.4 becomes the new stable
current_version = ActiveRecord::Migrator.current_version
min_version = 201_907_081_533_31
add_to_serializer(:site, :group_list_use_ids) { current_version >= min_version }
add_to_serializer :site, :house_creatives do
AdPlugin::HouseAdSetting.settings_and_ads
end