Skip to content

Commit

Permalink
merge changes from develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
akochari committed Dec 6, 2024
2 parents 96e3843 + b1dd402 commit 7d64d26
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 12 deletions.
8 changes: 8 additions & 0 deletions common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
logger = get_logger(__name__)


class UserProfileManager(models.Manager):
def create_user_profile(self, user: User):
user_profile = self.create(user=user)
return user_profile


class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
affiliation = models.CharField(max_length=100, blank=True)
Expand All @@ -19,6 +25,8 @@ class UserProfile(models.Model):

note = models.TextField(max_length=1000, blank=True)

objects = UserProfileManager()

def __str__(self):
return f"{self.user.email}"

Expand Down
9 changes: 9 additions & 0 deletions cypress/e2e/setup-scripts/seed_login_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.conf import settings
from django.contrib.auth.models import User

from common.models import UserProfile
from projects.models import Project

cypress_path = os.path.join(settings.BASE_DIR, "cypress/fixtures")
Expand All @@ -22,4 +23,12 @@

# Create the login user
user = User.objects.create_user(username, email, pwd)
user.first_name = userdata["first_name"]
user.last_name = userdata["last_name"]
user.save()

# needed for editing profile information (see SS-1177)
user_profile = UserProfile.objects.create_user_profile(user)
user_profile.department = userdata["department"]
user_profile.affiliation = userdata["affiliation"]
user_profile.save()
35 changes: 35 additions & 0 deletions cypress/e2e/ui-tests/test-deploy-app.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ describe("Test deploying app", () => {
const createResources = Cypress.env('create_resources');
const app_type = "Custom App"
const app_source_code_public = "https://doi.org/example"
const default_url_subpath = "default/url/subpath/"
const changed_default_url_subpath = "changed/subpath/"
const invalid_default_url_subpath = "€% / ()"

let volume_display_text = "project-vol (" + project_name + ")"

Expand All @@ -97,9 +100,15 @@ describe("Test deploying app", () => {
cy.get('#id_port').clear().type(image_port)
cy.get('#id_image').clear().type(image_name)
cy.get('#id_path').clear().type(app_path)
cy.get('button.accordion-button.collapsed[data-bs-target="#advanced-settings"]').click(); // Go to Advanced settings
cy.get('#id_default_url_subpath').clear().type(default_url_subpath) // provide default_url_subpath
cy.get('#submit-id-submit').contains('Submit').click()
// check that the app was created
verifyAppStatus(app_name_project, "Running", "project")
// check that the default URL subpath was created
cy.contains('a', app_name_project)
.should('have.attr', 'href')
.and('include', default_url_subpath);
// check that the app is not visible under public apps
cy.visit('/apps/')
cy.get('h3').should('contain', 'Public applications and models')
Expand Down Expand Up @@ -138,6 +147,8 @@ describe("Test deploying app", () => {
cy.get('#id_image').clear().type(image_name)
cy.get('#id_path').clear().type(app_path)
cy.get('#id_volume').select(volume_display_text)
cy.get('button.accordion-button.collapsed[data-bs-target="#advanced-settings"]').click(); // Go to Advanced settings
cy.get('#id_default_url_subpath').clear().type(default_url_subpath) // provide default_url_subpath
cy.get('#submit-id-submit').contains('Submit').click()

verifyAppStatus(app_name_public, "Running", "public")
Expand All @@ -147,6 +158,11 @@ describe("Test deploying app", () => {
verifyAppStatus(app_name_public, "Running", "public")
})

// check that the default URL subpath was created
cy.contains('a', app_name_public)
.should('have.attr', 'href')
.and('include', default_url_subpath);

cy.visit("/apps")
cy.get('h5.card-title').should('contain', app_name_public)
cy.get('.card-text').find('p').should('contain', app_description)
Expand Down Expand Up @@ -199,6 +215,9 @@ describe("Test deploying app", () => {
cy.get('#id_image').clear().type(image_name_2)
cy.get('#id_path').should('have.value', app_path)
cy.get('#id_path').clear().type(app_path_2)
cy.get('button.accordion-button.collapsed[data-bs-target="#advanced-settings"]').click(); // Go to Advanced settings
cy.get('#id_default_url_subpath').should('have.value', default_url_subpath) // default_url_subpath should be same as before
cy.get('#id_default_url_subpath').clear().type(changed_default_url_subpath) // provide changed_default_url_subpath
cy.get('#submit-id-submit').contains('Submit').click()

// NB: it will get status "Running" but it won't work because the new port is incorrect
Expand All @@ -209,6 +228,11 @@ describe("Test deploying app", () => {
verifyAppStatus(app_name_public_2, "Running", "link")
})

// check that the default URL subpath was changed
cy.contains('a', app_name_public_2)
.should('have.attr', 'href')
.and('include', changed_default_url_subpath);

// Check that the changes were saved
cy.visit("/projects/")
cy.contains('.card-title', project_name).parents('.card-body').siblings('.card-footer').find('a:contains("Open")').first().click()
Expand All @@ -221,6 +245,17 @@ describe("Test deploying app", () => {
cy.get('#id_port').should('have.value', image_port_2)
cy.get('#id_image').should('have.value', image_name_2)
cy.get('#id_path').should('have.value', app_path_2)
cy.get('button.accordion-button.collapsed[data-bs-target="#advanced-settings"]').click(); // Go to Advanced settings
cy.get('#id_default_url_subpath').should('have.value', changed_default_url_subpath) // changed_url_subpath should be same as before

// Make sure that giving invalid input in default_url_subpath field results in an error
cy.get('#id_default_url_subpath').clear().type(invalid_default_url_subpath) // provide invalid_default_url_subpath
cy.get('#submit-id-submit').contains('Submit').click() // this should trigger the error

// check this invalid_default_url_subpath error was matched
cy.get('.client-validation-feedback.client-validation-invalid')
.should('exist')
.and('include.text', 'Your custom URL subpath is not valid, please correct it');

// Remove the created public app and verify that it is deleted from public apps page
cy.logf("Now deleting the public app", Cypress.currentTest)
Expand Down
33 changes: 33 additions & 0 deletions cypress/e2e/ui-tests/test-login-account-handling.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,39 @@ describe("Test login, profile page view, password change, password reset", () =>
cy.get('div.col-8').should("contain", users.login_user.email)
})

it("can edit user profile information", () => {

function editProfile(firstName, lastName, department) {

cy.url().should("include", "edit-profile/")

cy.get('#id_first_name').clear().type(firstName);
cy.get('#id_last_name').clear().type(lastName);
cy.get('#id_department').clear().type(department);
cy.get('#submit-id-save').click();

cy.contains(firstName).should('exist');
cy.contains(lastName).should('exist');
cy.contains(department).should('exist');
}


cy.loginViaUI(users.login_user.email, users.login_user.password)

cy.log("Editing and verifying userprofile by accessing it from the navbar")
cy.visit("/")
cy.get('button.btn-profile').click()
cy.get('li.btn-group').find('a').contains("Edit profile").click()
editProfile('changing first name', 'changing last name', 'changing department name');

cy.log("Editing and verifying userprofile by accessing it from the profile view")
cy.visit("/")
cy.get('button.btn-profile').click()
cy.get('li.btn-group').find('a').contains("My profile").click()
cy.get('button.btn-profile').contains('a', 'Edit').click();
editProfile('changing first name again', 'changing last name again', 'changing department name again');
})

it("can change user password", () => {
cy.loginViaUI(users.login_user.email, users.login_user.password)
cy.visit("/")
Expand Down
4 changes: 4 additions & 0 deletions cypress/fixtures/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
"username": "e2e_tests_deploy_app_user"
},
"login_user": {
"affiliation": "uu",
"department": "e2e-tests-login-user-department-name",
"email": "[email protected]",
"first_name": "e2e-tests-login-user-first-name",
"last_name": "e2e-tests-login-user-last-name",
"password": "tesT12345@",
"reset_password": "^x#^PbLnDY!{J0ju",
"username": "e2e_tests_login_user"
Expand Down
29 changes: 17 additions & 12 deletions static/js/form-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ window.onload = (event) => {
const domainRegex = /^(?:(?!\b(?:student|stud)\b\.)[A-Z0-9](?:[\.A-Z0-9-]{0,61}[A-Z0-9])?\.)*?(uu|lu|gu|su|umu|liu|ki|kth|chalmers|ltu|hhs|slu|kau|lth|lnu|oru|miun|mau|mdu|bth|fhs|gih|hb|du|hig|hh|hkr|his|hv|ju|sh)\.se$/i;

function changeVisibility() {

let shouldHide = false;
let match;

Expand All @@ -30,23 +31,27 @@ window.onload = (event) => {
department_label.classList.remove('required');
}

if (shouldHide) {
request_account_field.classList.add('hidden');
} else {
request_account_field.classList.remove('hidden');
request_account_label.classList.add('required');
if (request_account_field){ // to prevent Uncaught TypeError for null value
if (shouldHide) {
request_account_field.classList.add('hidden');
} else {
request_account_field.classList.remove('hidden');
request_account_label.classList.add('required');
}
}
}

// Temporarily disable transitions
request_account_field.style.transition = 'none';
if (request_account_field){ // to prevent Uncaught TypeError for null value
// Temporarily disable transitions
request_account_field.style.transition = 'none';

changeVisibility();
changeVisibility();

// Restore transitions after a short delay
setTimeout(() => {
request_account_field.style.transition = '';
}, 50);
// Restore transitions after a short delay
setTimeout(() => {
request_account_field.style.transition = '';
}, 50);
}

email.addEventListener('input', changeVisibility);
};

0 comments on commit 7d64d26

Please sign in to comment.