6772312ea7
The primary license of the project is changing to: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later with some specific files to be licensed under the one of two licenses: CC0-1.0 LGPL-3.0-or-later This commit is one of the many steps to relicense the entire codebase. Documentation granting permission for this relicensing (from all past contributors who hold copyrights) is on file with Software Freedom Conservancy, Inc.
39 lines
1.3 KiB
Ruby
39 lines
1.3 KiB
Ruby
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
|
module CreateCustomFieldJoin
|
|
|
|
def self.create(supporter, profile_id, params)
|
|
custom_field = supporter.custom_field_joins.create(params)
|
|
return custom_field
|
|
end
|
|
|
|
# In the future, this should create an activity feed entry
|
|
|
|
# @param [Array<Hash>] custom_fields Hash with following keys:
|
|
# * custom_field_master_id [Integer] for the key corresponding to custom_field_master_id
|
|
# * value [Object] the expected value of the field. If this key is an empty string, we remove the custom_field
|
|
|
|
def self.modify(np, user, supporter_ids, custom_fields)
|
|
return if supporter_ids.nil? || supporter_ids.empty?
|
|
return if custom_fields.nil? || custom_fields.empty?
|
|
supporter_ids.each do |sid|
|
|
supporter = np.supporters.find(sid)
|
|
custom_fields.each do |custom_field|
|
|
existing = supporter.custom_field_joins.find_by_custom_field_master_id(custom_field[:custom_field_master_id])
|
|
if existing
|
|
existing.update_attributes({
|
|
custom_field_master_id: custom_field[:custom_field_master_id],
|
|
value: custom_field[:value]
|
|
})
|
|
else
|
|
self.create(supporter, user.profile.id, {
|
|
custom_field_master_id: custom_field[:custom_field_master_id],
|
|
value: custom_field[:value]
|
|
})
|
|
end
|
|
end
|
|
end
|
|
return np
|
|
end
|
|
|
|
end
|
|
|