diff --git a/assets/src/bundles/add_forge/index.js b/assets/src/bundles/add_forge/add-forge.css similarity index 65% copy from assets/src/bundles/add_forge/index.js copy to assets/src/bundles/add_forge/add-forge.css index 10fa0236..46190e60 100644 --- a/assets/src/bundles/add_forge/index.js +++ b/assets/src/bundles/add_forge/add-forge.css @@ -1,12 +1,18 @@ /** * Copyright (C) 2022 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ -// bundle for add forge views +.request-actions { + padding-right: 10px; +} -export * from './create-request'; -export * from './moderation-dashboard'; -export * from './request-dashboard'; +.details-text { + padding-top: 5px; +} + +.history-item { + padding-bottom: 5px; +} diff --git a/assets/src/bundles/add_forge/add-request-history-item.ejs b/assets/src/bundles/add_forge/add-request-history-item.ejs index 18ace60d..a930b469 100644 --- a/assets/src/bundles/add_forge/add-request-history-item.ejs +++ b/assets/src/bundles/add_forge/add-request-history-item.ejs @@ -1,30 +1,31 @@ <%# Copyright (C) 2022 The Software Heritage developers See the AUTHORS file at the top-level directory of this distribution License: GNU Affero General Public License version 3, or any later version See top-level LICENSE file for more information %> - -
-
-

- +

+
+
+
+

<%= event.text %>

<%if (event.new_status !== null) { %> - New status: <%= event.new_status %> +

+ Status changed to: <%= event.new_status %> +

<% } %> - - -
-
-
-

<%= event.text %>

- <%if (event.new_status !== null) { %> -

- Status changed to: <%= event.new_status %> -

- <% } %> +
-
+ \ No newline at end of file diff --git a/assets/src/bundles/add_forge/index.js b/assets/src/bundles/add_forge/index.js index 10fa0236..2ad140ac 100644 --- a/assets/src/bundles/add_forge/index.js +++ b/assets/src/bundles/add_forge/index.js @@ -1,12 +1,13 @@ /** * Copyright (C) 2022 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ // bundle for add forge views +export * from './add-forge.css'; export * from './create-request'; export * from './moderation-dashboard'; export * from './request-dashboard'; diff --git a/assets/src/bundles/add_forge/request-dashboard.js b/assets/src/bundles/add_forge/request-dashboard.js index e6d7f269..578950db 100644 --- a/assets/src/bundles/add_forge/request-dashboard.js +++ b/assets/src/bundles/add_forge/request-dashboard.js @@ -1,135 +1,140 @@ /** * Copyright (C) 2022 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ import {handleFetchError, csrfPost} from 'utils/functions'; import emailTempate from './forge-admin-email.ejs'; import requestHistoryItem from './add-request-history-item.ejs'; +let forgeRequest; + export function onRequestDashboardLoad(requestId) { $(document).ready(() => { populateRequestDetails(requestId); $('#contactForgeAdmin').click((event) => { contactForgeAdmin(event); }); $('#updateRequestForm').submit(async function(event) { event.preventDefault(); try { const response = await csrfPost($(this).attr('action'), {'Content-Type': 'application/x-www-form-urlencoded'}, $(this).serialize()); handleFetchError(response); $('#userMessage').text('The request status has been updated '); $('#userMessage').removeClass('badge-danger'); $('#userMessage').addClass('badge-success'); populateRequestDetails(requestId); } catch (response) { $('#userMessage').text('Sorry; Updating the request failed'); $('#userMessage').removeClass('badge-success'); $('#userMessage').addClass('badge-danger'); } }); }); } async function populateRequestDetails(requestId) { try { const response = await fetch(Urls.api_1_add_forge_request_get(requestId)); handleFetchError(response); const data = await response.json(); - $('#requestStatus').text(data.request.status); - $('#requestType').text(data.request.forge_type); - $('#requestURL').text(data.request.forge_url); - $('#requestEmail').text(data.request.forge_contact_email); - $('#submitterMessage').text(data.request.forge_contact_comment); + forgeRequest = data.request; + + $('#requestStatus').text(forgeRequest.status); + $('#requestType').text(forgeRequest.forge_type); + $('#requestURL').text(forgeRequest.forge_url); + $('#requestContactName').text(forgeRequest.forge_contact_name); + $('#requestContactConsent').text(forgeRequest.submitter_forward_username); + $('#requestContactEmail').text(forgeRequest.forge_contact_email); + $('#submitterMessage').text(forgeRequest.forge_contact_comment); $('#updateComment').val(''); // Setting data for the email, now adding static data - $('#swh-input-forge-admin-email').val(emailTempate({'forgeUrl': data.request.forge_url}).trim()); - $('#contactForgeAdmin').attr('emailTo', data.request.forge_contact_email); - $('#contactForgeAdmin').attr('emailSubject', `[swh-add_forge_now] Request ${data.request.id}`); + $('#contactForgeAdmin').attr('emailTo', forgeRequest.forge_contact_email); + $('#contactForgeAdmin').attr('emailSubject', `[swh-add_forge_now] Request ${forgeRequest.id}`); populateRequestHistory(data.history); - populateDecisionSelectOption(data.request.status); + populateDecisionSelectOption(forgeRequest.status); } catch (response) { // The error message $('#fetchError').removeClass('d-none'); $('#requestDetails').addClass('d-none'); } } function populateRequestHistory(history) { $('#requestHistory').children().remove(); history.forEach((event, index) => { const historyEvent = requestHistoryItem({'event': event, 'index': index}); $('#requestHistory').append(historyEvent); }); } export function populateDecisionSelectOption(currentStatus) { const nextStatusesFor = { 'PENDING': ['WAITING_FOR_FEEDBACK', 'REJECTED', 'SUSPENDED'], 'WAITING_FOR_FEEDBACK': ['FEEDBACK_TO_HANDLE'], 'FEEDBACK_TO_HANDLE': [ 'WAITING_FOR_FEEDBACK', 'ACCEPTED', 'REJECTED', 'SUSPENDED' ], 'ACCEPTED': ['SCHEDULED'], 'SCHEDULED': [ 'FIRST_LISTING_DONE', 'FIRST_ORIGIN_LOADED' ], 'FIRST_LISTING_DONE': ['FIRST_ORIGIN_LOADED'], 'FIRST_ORIGIN_LOADED': [], 'REJECTED': [], 'SUSPENDED': ['PENDING'], 'DENIED': [] }; const statusLabel = { 'PENDING': 'pending', 'WAITING_FOR_FEEDBACK': 'waiting for feedback', 'FEEDBACK_TO_HANDLE': 'feedback to handle', 'ACCEPTED': 'accepted', 'SCHEDULED': 'scheduled', 'FIRST_LISTING_DONE': 'first listing done', 'FIRST_ORIGIN_LOADED': 'first origin loaded', 'REJECTED': 'rejected', 'SUSPENDED': 'suspended', 'DENIED': 'denied' }; // Determine the possible next status out of the current one const nextStatuses = nextStatusesFor[currentStatus]; function addStatusOption(status, index) { // Push the next possible status options const label = statusLabel[status]; $('#decisionOptions').append( `` ); } // Remove all the options and add new ones $('#decisionOptions').children().remove(); nextStatuses.forEach(addStatusOption); $('#decisionOptions').append( '' ); } function contactForgeAdmin(event) { // Open the mailclient with pre-filled text const mailTo = $('#contactForgeAdmin').attr('emailTo'); const subject = $('#contactForgeAdmin').attr('emailSubject'); - const emailText = $('#swh-input-forge-admin-email').val().replace(/\n/g, '%0D%0A'); + const emailText = emailTempate({'forgeUrl': forgeRequest.forge_url}).trim().replace(/\n/g, '%0D%0A'); const w = window.open('', '_blank', '', true); w.location.href = `mailto: ${mailTo}?subject=${subject}&body=${emailText}`; w.focus(); } diff --git a/cypress/integration/add-forge-now-request-dashboard.spec.js b/cypress/integration/add-forge-now-request-dashboard.spec.js index 96aa42af..9a1d432c 100644 --- a/cypress/integration/add-forge-now-request-dashboard.spec.js +++ b/cypress/integration/add-forge-now-request-dashboard.spec.js @@ -1,68 +1,72 @@ /** * Copyright (C) 2022 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ const requestId = 1; describe('Test add forge now request dashboard load', function() { beforeEach(function() { const url = this.Urls.add_forge_now_request_dashboard(requestId); cy.adminLogin(); cy.intercept(`${this.Urls.api_1_add_forge_request_get(requestId)}**`, {fixture: 'add-forge-now-request'}).as('forgeAddRequest'); cy.visit(url); }); it('should load add forge request details', function() { cy.wait('@forgeAddRequest'); cy.get('#requestStatus') .should('contain', 'PENDING'); cy.get('#requestType') .should('contain', 'bitbucket'); cy.get('#requestURL') .should('contain', 'test.com'); - cy.get('#requestEmail') + cy.get('#requestContactEmail') .should('contain', 'test@example.com'); + + cy.get('#requestContactName') + .should('contain', 'test user'); + }); it('should not show any error message', function() { cy.get('#fetchError') .should('have.class', 'd-none'); cy.get('#requestDetails') .should('not.have.class', 'd-none'); }); it('should show error message for an api error', function() { const invalidRequestId = 2; const url = this.Urls.add_forge_now_request_dashboard(invalidRequestId); cy.visit(url); cy.get('#fetchError') .should('not.have.class', 'd-none'); cy.get('#requestDetails') .should('have.class', 'd-none'); }); it('should load add forge request history', function() { cy.get('#requestHistory') .children() .should('have.length', 1); cy.get('#requestHistory') .children() .should('contain', 'New status: PENDING'); }); it('should load possible next status', function() { // 3 possible next status and the comment option cy.get('#decisionOptions') .children() .should('have.length', 4); }); }); diff --git a/swh/web/templates/add_forge_now/request-dashboard.html b/swh/web/templates/add_forge_now/request-dashboard.html index b2f76c14..33ee61bd 100644 --- a/swh/web/templates/add_forge_now/request-dashboard.html +++ b/swh/web/templates/add_forge_now/request-dashboard.html @@ -1,135 +1,120 @@ {% extends "../layout.html" %} {% comment %} Copyright (C) 2022 The Software Heritage developers See the AUTHORS file at the top-level directory of this distribution License: GNU Affero General Public License version 3, or any later version See top-level LICENSE file for more information {% endcomment %} {% load render_bundle from webpack_loader %} {% load static %} {% block header %} {% render_bundle 'add_forge' %} {% endblock %} {% block title %}{{heading}} – Software Heritage archive{% endblock %} {% block navbar-content %}

Add forge now request dashboard

{% endblock %} {% block content %} -
-
-
-

Error fetching information about the request

-
-
-
-
- -
    -
  • -
    -
    Status
    -
    - -
  • -
  • -
    -
    Type
    -
    - -
  • -
  • -
    -
    Forge URL
    -
    - -
  • -
  • -
    -
    Forge contact email
    -
    - -
  • -
  • -

    -
  • -
-
-
-
-
- -
-
-
-
- -
- -
- -
-
- -
-
- +
+
+

Error fetching information about the request

+
+
+
+
+
- -
-
-
+ + style="padding-top: 5px;" id="updateRequestForm"> {% csrf_token %}
Enter a comment related to your decision.

-
+ +
+
+
+
+ Request status +
+ +
+
+ Forge type +
+ +
+
+ Forge URL +
+ +
+
+ Contact name +
+ +
+
+ Consent to use name +
+ +
+
+ Contact email +
+ +
+
+ Message +
+

+
+
+
- {% endblock %}