Skip to content

Commit

Permalink
restricting project tabs to pending projects and eligible system admi…
Browse files Browse the repository at this point in the history
…nistrators (#1149)

* restricting approve and script tabs to pending projects and eligible system administrators

* removing depracated approve button

* updating tests
  • Loading branch information
JaymeeH authored Dec 19, 2024
1 parent 11044ca commit 6a96114
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
27 changes: 19 additions & 8 deletions app/javascript/entrypoints/projectTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ export function projectStyle(railsSession) {
}
});

// $('#project-approval').on('click', (el) => {
// const element = el;
// element.preventDefault();
// approval.style.borderBottom = 'solid';
// approval.style.borderColor = '#E77500';
// approval.classList.add('active');
// });
$('#project-approval').on('click', (el) => {
const element = el;
element.preventDefault();
approval.style.borderBottom = 'solid';
approval.style.borderColor = '#E77500';
approval.classList.add('active');
});
}

export function projectTab(contentUrl, detailsUrl) {
export function projectTab(contentUrl, detailsUrl, approveUrl) {
$('#project-content').on('click', (element) => {
element.preventDefault();
$.ajax({
Expand All @@ -157,4 +157,15 @@ export function projectTab(contentUrl, detailsUrl) {
},
});
});

$('#project-approval').on('click', (element) => {
element.preventDefault();
$.ajax({
type: 'GET',
url: approveUrl,
success() {
window.location.href = approveUrl; // update the browser's URL
},
});
});
}
11 changes: 7 additions & 4 deletions app/views/projects/details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
<div id="project-nav">
<button id="project-content" class="tab-nav"> Content Preview </button>
<button id="project-details" class="tab-nav"> Details </button>
<button id="project-script" class="tab-nav"> View Create Script </button>
<button id="project-approval" class="tab-nav"> Approval Setting </button>
<% if current_user.eligible_sysadmin? %>
<% if @project.pending? %>
<button id="project-script" class="tab-nav"> View Create Script </button>
<button id="project-approval" class="tab-nav"> Approval Setting </button>
<% end %>
<% end %>
</div>

<div class="details">
Expand Down Expand Up @@ -99,7 +103,6 @@
<div class="details">
<% if current_user.eligible_sysadmin? %>
<% if @project.pending? %>
<%= link_to "Approve Project", project_approve_path(@project.id), class: "btn btn-primary btn-sm" %>
<%= link_to " View Create Script", "#", class: "bi bi-code btn btn-secondary btn-sm", id: "create-script-btn" %>
<% end %>
<% end %>
Expand All @@ -113,5 +116,5 @@
// Make the AJAX call to fetch the aterm script
showCreateScript('<%= project_create_script_path(format: "json") %>');
projectStyle('<%= @project_session %>');
projectTab("<%= project_path %>", "<%= project_details_path %>");
projectTab("<%= project_path %>", "<%= project_details_path %>", "<%= project_approve_path %>");
</script>
10 changes: 7 additions & 3 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
<div id="project-nav">
<button id="project-content" class="tab-nav"> Content Preview </button>
<button id="project-details" class="tab-nav"> Details </button>
<button id="project-script" class="tab-nav"> View Create Script </button>
<button id="project-approval" class="tab-nav"> Approval Setting </button>
<% if current_user.eligible_sysadmin? %>
<% if @project.pending? %>
<button id="project-script" class="tab-nav"> View Create Script </button>
<button id="project-approval" class="tab-nav"> Approval Setting </button>
<% end %>
<% end %>
</div>
<div class="row align-items-center contents-summary">
<div class="col-sm-2 file-inventory">File Inventory:</div>
Expand Down Expand Up @@ -51,6 +55,6 @@
</div>
<script type="module">
projectStyle('<%= @project_session %>');
projectTab("<%= project_path %>", "<%= project_details_path %>");
projectTab("<%= project_path %>", "<%= project_details_path %>", "<%= project_approve_path %>");
setupTable('#project-contents');
</script>
6 changes: 3 additions & 3 deletions spec/system/project_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
expect(page).to have_content(pending_text)
expect(page).to have_css ".pending"
expect(page).to have_link("Edit")
expect(page).to have_selector(:link_or_button, "Approve Project")
expect(page).to have_selector(:link_or_button, "Approval Setting")
end
end
end
Expand Down Expand Up @@ -238,7 +238,7 @@
expect(page).to have_content "1234"
expect(page).not_to have_content "This project has not been saved to Mediaflux"
expect(page).not_to have_content pending_text
expect(page).to have_selector(:link_or_button, "Approve Project")
expect(page).to have_selector(:link_or_button, "Approval Setting")
end

it "does not show the mediaflux id to the sponsor" do
Expand All @@ -257,7 +257,7 @@
visit "/projects/#{project_not_in_mediaflux.id}/details"
expect(page).to have_content "This project has not been saved to Mediaflux"
expect(page).to have_content pending_text
expect(page).to have_selector(:link_or_button, "Approve Project")
expect(page).to have_selector(:link_or_button, "Approval Setting")
end
end
end
Expand Down

0 comments on commit 6a96114

Please sign in to comment.