Skip to content

Commit

Permalink
Merge branch 'main' into issue-517-log-file-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcorrea committed Oct 24, 2022
2 parents d030652 + 4777aaf commit 3826551
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def resolve_ark
def edit
@work = Work.find(params[:id])
if current_user && @work.editable_by?(current_user)
if @work.approved? && @work.submitted_by?(current_user)
if @work.approved? && !@work.administered_by?(current_user)
redirect_to root_path, notice: I18n.t("works.approved.uneditable")
else
@uploads = @work.uploads
Expand Down
12 changes: 7 additions & 5 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ class Work < ApplicationRecord
# @param [User]
# @return [Boolean]
def editable_by?(user)
return true if submitted_by?(user)
collection = Collection.find(collection_id)
return true if user.has_role?(:collection_admin, collection)
false
submitted_by?(user) || administered_by?(user)
end

def submitted_by?(user)
return true if created_by_user_id == user.id
created_by_user_id == user.id
end

def administered_by?(user)
user.has_role?(:collection_admin, collection)
end

class << self
Expand Down Expand Up @@ -242,6 +243,7 @@ def to_json
end

def uploads_attributes
return [] if approved? # once approved we no longer allow the updating of uploads via the application
uploads.map do |upload|
{
id: upload.id,
Expand Down
9 changes: 8 additions & 1 deletion app/views/works/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@
<% if !@wizard_mode %>
<hr />
<div class="deposit-uploads">
<%= render(partial: 'works/uploads_form', locals: { form: form }) %>
<% if @work.approved? %>
<section class="uploads">
<h2 class="h2"><%= t('works.uploads.post_curation.heading') %></h2>
<%= render(partial: 'works/uploads/post_curation_s3_resources') %>
</section>
<% else %>
<%= render(partial: 'works/uploads_form', locals: { form: form }) %>
<% end %>
</div>
<% end %>

Expand Down
16 changes: 15 additions & 1 deletion spec/system/view_data_in_s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

context "when user is a curator" do
let(:user) { FactoryBot.create(:research_data_moderator) }
pending "shows data from S3" do
it "shows data from S3" do
stub_s3(data: s3_data)
visit work_path(work)
expect(page).to have_content file1.filename
Expand All @@ -83,6 +83,20 @@
expect(page).to have_content file1.filename
expect(page).to have_content file2.filename
end

context "when user is a super super_admin_user" do
let(:user) { FactoryBot.create(:research_data_moderator) }
it "shows data from S3" do
stub_s3(data: s3_data)
visit work_path(work)
expect(page).to have_content file1.filename
expect(page).to have_content file2.filename

click_on "Edit"
expect(page).to have_content file1.filename
expect(page).to have_content file2.filename
end
end
end
end
end
Expand Down

0 comments on commit 3826551

Please sign in to comment.