Skip to content

Commit

Permalink
Force submitter role entity to be linked entity of submitting user
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hank committed Jul 28, 2022
1 parent ebba0fe commit 28f63a2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). It uses [CalVer](https://calver.org/) as of May 2019.

## [22.07h](https://github.com/berkmancenter/lumendatabase/releases/tag/2022.07h) - 2022-07-28
### Changed
* Forced a `submitter role entity` to always be a linked entity of a submitting user.

## [22.07g](https://github.com/berkmancenter/lumendatabase/releases/tag/2022.07g) - 2022-07-27
### Added
* Added a `rake` task for merging similar entities.
Expand Down
5 changes: 4 additions & 1 deletion app/models/notice_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def recipient_name
def set_all_entities
return unless !!user && !!(entity = user.entity)

set_entity(:submitter, entity) unless entity_present?(:submitter)
# Submitter should always be forced to be a linked entity of the current user
@notice.entity_notice_roles = @notice.entity_notice_roles.select { |entity_role| entity_role.name.to_sym != :submitter } if entity_present?(:submitter)

set_entity(:submitter, entity)
set_entity(:recipient, entity) unless entity_present?(:recipient)
end

Expand Down
6 changes: 3 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
end

create_table "active_storage_variant_records", force: :cascade do |t|
t.integer "blob_id", null: false
t.bigint "blob_id", null: false
t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end
Expand Down Expand Up @@ -138,7 +138,7 @@
t.index ["boolean"], name: "index_comfy_cms_fragments_on_boolean"
t.index ["datetime"], name: "index_comfy_cms_fragments_on_datetime"
t.index ["identifier"], name: "index_comfy_cms_fragments_on_identifier"
t.index ["record_type", "record_id"], name: "index_comfy_cms_fragments_on_record"
t.index ["record_type", "record_id"], name: "index_comfy_cms_fragments_on_record_type_and_record_id"
end

create_table "comfy_cms_layouts", force: :cascade do |t|
Expand Down Expand Up @@ -582,7 +582,7 @@
end

create_table "youtube_import_file_locations", force: :cascade do |t|
t.integer "file_upload_id"
t.bigint "file_upload_id"
t.string "path", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
Expand Down
29 changes: 29 additions & 0 deletions spec/integration/submit_notice_via_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,35 @@
expect(notice.recipient).to eq entity
end

scenario 'submitting as a user with a linked entity and providing a submitter entity' do
user = create(:user, :submitter)
entity = create(:entity, user: user, name: 'Twitter')
notice_parameters = default_notice_hash(
title: 'A superduper title',
entity_notice_roles_attributes: [
{
name: 'recipient',
entity_attributes: {
name: 'The Googs'
}
},
{
name: 'submitter',
entity_attributes: {
name: 'Extra submitter entity will be discarded'
}
}
]
)
parameters = request_hash(notice_parameters, user)

curb = post_api('/notices', parameters)

notice = Notice.last
expect(curb.response_code).to eq 201
expect(notice.submitter).to eq entity
end

scenario 'submitting a notice with text file attachments' do
parameters = request_hash(notice_hash_with_text_files)

Expand Down
5 changes: 2 additions & 3 deletions spec/models/notice_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
expect(n.submitter).to eq user.entity
end

it 'leaves existing submitters alone' do
it 'removes submitters that come from request params' do
user = create(:user, :with_entity)
enr = default_notice_hash[:entity_notice_roles_attributes]
enr[0][:name] = 'submitter'
Expand All @@ -69,8 +69,7 @@
).build
n.save

assert user.entity.name != 'The Googs'
expect(n.submitter.name).to eq 'The Googs'
expect(n.submitter).to eq user.entity
end

it 'sets recipient if unset' do
Expand Down

0 comments on commit 28f63a2

Please sign in to comment.