Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#11371] Instructor sample data: defer until instructor joins #11396

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
d550da4
Defer creation of sample data until after instructor joins
samuelfangjw Aug 27, 2021
5e25591
Fix deleteAccountRequest
samuelfangjw Aug 27, 2021
a0f55dd
Add loading spinner to create-account-page
samuelfangjw Aug 27, 2021
2a0aced
Add check for whether user already has account
samuelfangjw Aug 27, 2021
5e7f2a8
Update frontend tests
samuelfangjw Aug 27, 2021
05051bc
Add component tests
samuelfangjw Aug 27, 2021
074bae4
Add tests for AccountRequestAttributes
samuelfangjw Aug 27, 2021
abb0659
Add component tests for create account actions
samuelfangjw Aug 28, 2021
2ccf794
Fix frontend lint errors
samuelfangjw Aug 28, 2021
d1a4ab9
Fix backend lint errors
samuelfangjw Aug 28, 2021
9531452
Fix e2e tests
samuelfangjw Aug 28, 2021
8f56242
Add account requests to data bundle
samuelfangjw Aug 28, 2021
f70d0a2
Update account requests logic test
samuelfangjw Aug 28, 2021
30837d7
Add e2e Tests
samuelfangjw Aug 28, 2021
6a4c9b7
Fix page not redirecting to login
samuelfangjw Aug 28, 2021
1de8a02
Fix lint errors
samuelfangjw Aug 28, 2021
c4fcdbf
Merge branch 'upstream-master' into 11371-defer-creation-instructor-s…
samuelfangjw Sep 6, 2021
188b7d9
Fix linting issues
samuelfangjw Sep 6, 2021
f3d1631
Change id of AccountRequest to use both email and institute
samuelfangjw Sep 6, 2021
deadc7a
Move create account page to user join page
samuelfangjw Sep 7, 2021
d61683d
Update tests for user-join-page
samuelfangjw Sep 7, 2021
8f8ce64
Add delete account request action
samuelfangjw Sep 8, 2021
0380f04
Delete account request in AdminHomePageE2E test
samuelfangjw Sep 8, 2021
e64308f
Add GetAccountRequest action
samuelfangjw Sep 8, 2021
c1a3f06
Remove unnecessary calls to getAccountRequest
samuelfangjw Sep 8, 2021
68a1fae
Fix failing component tests
samuelfangjw Sep 9, 2021
c55d1eb
Use instructorEmail instead of Email const
samuelfangjw Sep 9, 2021
688d9d8
Fix minor bugs and cleanup
samuelfangjw Sep 9, 2021
bedcaab
Remove trailing whitespace
samuelfangjw Sep 9, 2021
311860e
Merge branch 'upstream-master' into 11371-defer-creation-instructor-s…
samuelfangjw Sep 13, 2021
ff7ee60
Merge branch 'upstream-master' into 11371-defer-creation-instructor-s…
samuelfangjw Nov 15, 2021
e042bce
Add placeholder skeleton to frontend
samuelfangjw Nov 15, 2021
aa92dee
Update AccountRequest and DTO
samuelfangjw Nov 15, 2021
6abc921
Move registration url creation to accountRequest dto
samuelfangjw Nov 15, 2021
92b9db0
Update createAccountAction to soft delete
samuelfangjw Nov 15, 2021
33a2f2c
Update component tests
samuelfangjw Nov 15, 2021
e3048ef
Add endpoint to get account request status
samuelfangjw Nov 15, 2021
94492bc
Update user join page
samuelfangjw Nov 15, 2021
32b9826
Fix indentation
samuelfangjw Nov 17, 2021
cb527e4
Update tests for user-join-page
samuelfangjw Nov 17, 2021
8d45185
Fix failing component tests
samuelfangjw Nov 17, 2021
b77b784
Merge branch 'upstream-master' into 11371-defer-creation-instructor-s…
samuelfangjw Nov 20, 2021
0fb8280
Fix typos
samuelfangjw Nov 20, 2021
12af21f
Fix typo which caused createdAt to be null
samuelfangjw Nov 20, 2021
ff6c483
Fix broken component tests
samuelfangjw Nov 20, 2021
0297d15
Merge branch 'upstream-master' into 11371-defer-creation-instructor-s…
samuelfangjw Dec 7, 2021
cbb5adf
Update exception to use specific exception type
samuelfangjw Dec 7, 2021
9958e09
Change Instant to Long in AccountRequestData.java
samuelfangjw Dec 7, 2021
b54289d
Refactor CreateAccountRequestActionTest to use getJoinLink method
samuelfangjw Dec 7, 2021
0536be1
Fix lint issues
samuelfangjw Dec 7, 2021
c4cf8ea
Merge branch 'master' into 11371-defer-creation-instructor-sample-data
samuelfangjw Dec 11, 2021
9e67ba6
Change getAccountRequest to throw exception
samuelfangjw Dec 11, 2021
c8a22bb
Remove unnecessary null check
samuelfangjw Dec 11, 2021
381da0d
Refactor user join page
samuelfangjw Dec 11, 2021
3c41600
Remove instructor from registration url
samuelfangjw Dec 11, 2021
2a49efe
Remove instructor entity type from tests
samuelfangjw Dec 11, 2021
38b2941
Update sample data to be more realistic
samuelfangjw Dec 11, 2021
f49d7cc
Remove name and registration key update options
samuelfangjw Dec 11, 2021
926c3dd
Fix architecture test violations
samuelfangjw Dec 11, 2021
55d55a2
Merge branch 'master' into 11371-defer-creation-instructor-sample-data
samuelfangjw Dec 11, 2021
1ce255e
Merge branch 'master' into 11371-defer-creation-instructor-sample-data
samuelfangjw Jan 18, 2022
c0f4cb8
Seperate craete and update account request
samuelfangjw Jan 18, 2022
dfda199
Merge branch 'master' into 11371-defer-creation-instructor-sample-data
samuelfangjw Jan 19, 2022
3f10b9d
Merge branch 'master' into 11371-defer-creation-instructor-sample-data
samuelfangjw Jan 31, 2022
6649b9c
Streamline API for join status
samuelfangjw Jan 31, 2022
4a82bbe
Minor bug fix
samuelfangjw Jan 31, 2022
3886856
Remove account request status constant
samuelfangjw Jan 31, 2022
d500cba
Refactor get account request methods
samuelfangjw Jan 31, 2022
a702853
Simplify condition
samuelfangjw Jan 31, 2022
ce2f36a
Fix typo
samuelfangjw Jan 31, 2022
8d4ad39
Remove else block
samuelfangjw Jan 31, 2022
b046861
Create e2e test for account requests
samuelfangjw Jan 31, 2022
ce57ef3
Fix lint issues
samuelfangjw Jan 31, 2022
a27c7ac
Fix failing test
samuelfangjw Jan 31, 2022
868d81c
Remove now unnecessary comment
samuelfangjw Jan 31, 2022
00ec347
Revert unnecessary change
samuelfangjw Jan 31, 2022
19fee86
Remove outdated comment
samuelfangjw Jan 31, 2022
3d9aebe
Fix minor issues
samuelfangjw Jan 31, 2022
ca7f11f
Merge branch 'master' into 11371-defer-creation-instructor-sample-data
samuelfangjw Feb 1, 2022
7f00adc
Remove additional word
samuelfangjw Feb 1, 2022
690a406
Replace boolean with string
samuelfangjw Feb 1, 2022
99782c6
Catch error when accountRequestAttributes is null
samuelfangjw Feb 1, 2022
a4aea9e
Remove entityType from join link
samuelfangjw Feb 1, 2022
15aec0d
Use invalidKey variable
samuelfangjw Feb 1, 2022
d9cf69a
Remove name from update options
samuelfangjw Feb 1, 2022
632e909
Merge branch 'master' into 11371-defer-creation-instructor-sample-data
samuelfangjw Feb 1, 2022
7b4732e
Handle case where accountRequestAttributes not found with assertions …
samuelfangjw Feb 2, 2022
a53cb82
Seperate try block in CreateAccountAction.java
samuelfangjw Feb 2, 2022
7191591
Handle cases in CreateAccountAction where exceptions should not be th…
samuelfangjw Feb 3, 2022
6726a73
Tweak comment language used to be consistent
samuelfangjw Feb 3, 2022
570011a
Collapse catch blocks in CreateAccountAction.java
samuelfangjw Feb 3, 2022
fff66aa
Merge branch 'master' into 11371-defer-creation-instructor-sample-data
wkurniawan07 Feb 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/e2e/java/teammates/e2e/cases/AdminHomePageE2ETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.testng.annotations.Test;

import teammates.common.datatransfer.attributes.CourseAttributes;
import teammates.common.util.AppUrl;
import teammates.common.util.Const;
import teammates.e2e.pageobjects.AdminHomePage;
Expand All @@ -26,9 +25,6 @@ public void testAll() {
String name = "AHPUiT Instrúctör WithPlusInEmail";
String email = "[email protected]";
String institute = "TEAMMATES Test Institute 1";
String demoCourseId = "AHPUiT____.instr1_.gma-demo";

BACKDOOR.deleteCourse(demoCourseId);
samuelfangjw marked this conversation as resolved.
Show resolved Hide resolved

homePage.queueInstructorForAdding(name, email, institute);

Expand All @@ -42,14 +38,12 @@ public void testAll() {
assertTrue(successMessage.contains(
"Instructor \"AHPUiT Instrúctör WithPlusInEmail\" has been successfully created"));

CourseAttributes demoCourse = getCourse(demoCourseId);
assertNotNull(demoCourse);

String failureMessage = homePage.getMessageForInstructor(1);
assertTrue(failureMessage.contains(
"\"invalidemail\" is not acceptable to TEAMMATES as a/an email because it is not in the correct format."));

BACKDOOR.deleteCourse(demoCourseId);
assertNotNull(BACKDOOR.getAccountRequest(email, institute));
BACKDOOR.deleteAccountRequest(email, institute);
}

}
6 changes: 6 additions & 0 deletions src/e2e/java/teammates/e2e/cases/BaseE2ETestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import teammates.common.datatransfer.DataBundle;
import teammates.common.datatransfer.attributes.AccountAttributes;
import teammates.common.datatransfer.attributes.AccountRequestAttributes;
import teammates.common.datatransfer.attributes.CourseAttributes;
import teammates.common.datatransfer.attributes.FeedbackQuestionAttributes;
import teammates.common.datatransfer.attributes.FeedbackResponseAttributes;
Expand Down Expand Up @@ -307,6 +308,11 @@ String getKeyForStudent(StudentAttributes student) {
return getStudent(student).getKey();
}

@Override
protected AccountRequestAttributes getAccountRequest(AccountRequestAttributes accountRequest) {
return BACKDOOR.getAccountRequest(accountRequest.getEmail(), accountRequest.getInstitute());
}

@Override
protected boolean doRemoveAndRestoreDataBundle(DataBundle testData) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,33 @@ public void testAll() {
______TS("Already joined, no confirmation page");

getNewPageInstance(joinLink, InstructorHomePage.class);

logout();

______TS("Click join link: invalid key");
joinLink = createFrontendUrl(Const.WebPageURIs.JOIN_PAGE)
.withIsCreatingAccount("true")
.withRegistrationKey(invalidKey);
confirmationPage = loginToPage(joinLink, CourseJoinConfirmationPage.class, "ICJoinConf.newinstr");

confirmationPage.verifyDisplayedMessage("The course join link is invalid. You may have "
+ "entered the URL incorrectly or the URL may correspond to a/an instructor that does not exist.");

______TS("Click join link: valid account request key");

String regKey = BACKDOOR
.getRegKeyForAccountRequest("[email protected]", "TEAMMATES Test Institute 1");

joinLink = createFrontendUrl(Const.WebPageURIs.JOIN_PAGE)
.withIsCreatingAccount("true")
.withRegistrationKey(regKey);

confirmationPage = getNewPageInstance(joinLink, CourseJoinConfirmationPage.class);
confirmationPage.verifyJoiningUser("ICJoinConf.newinstr");
confirmationPage.confirmJoinCourse(InstructorHomePage.class);

______TS("Regkey for account request used, no confirmation page");

getNewPageInstance(joinLink, InstructorHomePage.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
"institute": "TEAMMATES Test Institute 1"
}
},
"accountRequests": {
"ICJoinConf.instr.CS1101": {
"name": "Teammates Test 2",
"email": "[email protected]",
"institute": "TEAMMATES Test Institute 1",
"createdAt": "2011-01-01T00:00:00Z",
"registeredAt": "1970-02-14T00:00:00Z"
},
"ICJoinConf.newinstr": {
"name": "Teammates Test 3",
"email": "[email protected]",
"institute": "TEAMMATES Test Institute 1",
"createdAt": "2011-01-01T00:00:00Z"
}
},
"courses": {
"ICJoinConf.CS1101": {
"id": "tm.e2e.ICJoinConf.CS1101",
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/teammates/common/datatransfer/DataBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Map;

import teammates.common.datatransfer.attributes.AccountAttributes;
import teammates.common.datatransfer.attributes.AccountRequestAttributes;
import teammates.common.datatransfer.attributes.CourseAttributes;
import teammates.common.datatransfer.attributes.FeedbackQuestionAttributes;
import teammates.common.datatransfer.attributes.FeedbackResponseAttributes;
Expand All @@ -21,6 +22,7 @@
// CHECKSTYLE.OFF:JavadocVariable each field represents different entity types
public class DataBundle {
public Map<String, AccountAttributes> accounts = new LinkedHashMap<>();
public Map<String, AccountRequestAttributes> accountRequests = new LinkedHashMap<>();
public Map<String, CourseAttributes> courses = new LinkedHashMap<>();
public Map<String, InstructorAttributes> instructors = new LinkedHashMap<>();
public Map<String, StudentAttributes> students = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
package teammates.common.datatransfer.attributes;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import teammates.common.util.Config;
import teammates.common.util.Const;
import teammates.common.util.FieldValidator;
import teammates.common.util.SanitizationHelper;
import teammates.storage.entity.AccountRequest;

/**
* The data transfer object for {@link AccountRequest} entities.
*/
public class AccountRequestAttributes extends EntityAttributes<AccountRequest> {

private String email;
private String name;
private String institute;
private Instant registeredAt;
private Instant createdAt;
private transient String registrationKey;

private AccountRequestAttributes(String email, String institute, String name) {
this.email = email;
this.institute = institute;
this.name = name;
this.registrationKey = null;
this.registeredAt = null;
this.createdAt = null;
}

/**
* Gets the {@link AccountRequestAttributes} instance of the given {@link AccountRequest}.
*/
public static AccountRequestAttributes valueOf(AccountRequest accountRequest) {
AccountRequestAttributes accountRequestAttributes = new AccountRequestAttributes(accountRequest.getEmail(),
accountRequest.getInstitute(), accountRequest.getName());

accountRequestAttributes.registrationKey = accountRequest.getRegistrationKey();
accountRequestAttributes.registeredAt = accountRequest.getRegisteredAt();
accountRequestAttributes.createdAt = accountRequest.getCreatedAt();

return accountRequestAttributes;
}

/**
* Returns a builder for {@link AccountRequestAttributes}.
*/
public static Builder builder(String email, String institute, String name) {
return new Builder(email, institute, name);
}

public String getRegistrationKey() {
return registrationKey;
}

public String getName() {
return name;
}

public String getEmail() {
return email;
}

public String getInstitute() {
return institute;
}

public Instant getRegisteredAt() {
return registeredAt;
}

public Instant getCreatedAt() {
return createdAt;
}

public String getRegistrationUrl() {
return Config.getFrontEndAppUrl(Const.WebPageURIs.JOIN_PAGE)
.withIsCreatingAccount("true")
.withRegistrationKey(this.getRegistrationKey())
.toAbsoluteString();
}

@Override
public List<String> getInvalidityInfo() {
List<String> errors = new ArrayList<>();

addNonEmptyError(FieldValidator.getInvalidityInfoForEmail(getEmail()), errors);
addNonEmptyError(FieldValidator.getInvalidityInfoForPersonName(getName()), errors);
addNonEmptyError(FieldValidator.getInvalidityInfoForInstituteName(getInstitute()), errors);

return errors;
}

@Override
public AccountRequest toEntity() {
AccountRequest accountRequest = new AccountRequest(getEmail(), getName(), getInstitute());

if (this.getRegistrationKey() != null) {
accountRequest.setRegistrationKey(this.getRegistrationKey());
wkurniawan07 marked this conversation as resolved.
Show resolved Hide resolved
}

if (this.getCreatedAt() != null) {
accountRequest.setCreatedAt(this.getCreatedAt());
}

accountRequest.setRegisteredAt(this.getRegisteredAt());

return accountRequest;
}

@Override
public String toString() {
return "[" + AccountRequestAttributes.class.getSimpleName() + "] email: "
+ getEmail() + " name: " + getName() + " institute: " + getInstitute();
}

@Override
public int hashCode() {
return (this.email + this.name + this.institute).hashCode();
}

@Override
public boolean equals(Object other) {
if (other == null) {
return false;
} else if (this == other) {
return true;
} else if (this.getClass() == other.getClass()) {
AccountRequestAttributes otherAccountRequest = (AccountRequestAttributes) other;
return Objects.equals(this.email, otherAccountRequest.email)
&& Objects.equals(this.institute, otherAccountRequest.institute)
&& Objects.equals(this.name, otherAccountRequest.name);
} else {
return false;
}
}

@Override
public void sanitizeForSaving() {
this.institute = SanitizationHelper.sanitizeTitle(institute);
this.name = SanitizationHelper.sanitizeName(name);
this.email = SanitizationHelper.sanitizeEmail(email);
}

/**
* Updates with {@link UpdateOptions}.
*/
public void update(UpdateOptions updateOptions) {
updateOptions.registeredAtOption.ifPresent(s -> registeredAt = s);
}

/**
* Returns a {@link UpdateOptions.Builder} to build {@link UpdateOptions} for an account request.
*/
public static UpdateOptions.Builder updateOptionsBuilder(String email, String institute) {
return new UpdateOptions.Builder(email, institute);
}

/**
* A builder for {@link AccountRequestAttributes}.
*/
public static class Builder extends BasicBuilder<AccountRequestAttributes, Builder> {
private final AccountRequestAttributes accountRequestAttributes;

private Builder(String email, String institute, String name) {
super(new UpdateOptions(email, institute));
thisBuilder = this;

accountRequestAttributes = new AccountRequestAttributes(email, institute, name);
}

@Override
public AccountRequestAttributes build() {
accountRequestAttributes.update(updateOptions);

return accountRequestAttributes;
}
}

/**
* Helper class to specify the fields to update in {@link AccountRequestAttributes}.
*/
public static class UpdateOptions {
private String email;
private String institute;

private UpdateOption<Instant> registeredAtOption = UpdateOption.empty();

private UpdateOptions(String email, String institute) {
assert email != null;
assert institute != null;

this.email = email;
this.institute = institute;
}

public String getEmail() {
return email;
}

public String getInstitute() {
return institute;
}

@Override
public String toString() {
return "AccountRequestAttributes.UpdateOptions ["
+ ", email = " + email
+ ", institute = " + institute
+ ", registeredAt = " + registeredAtOption
+ "]";
}

/**
* Builder class to build {@link UpdateOptions}.
*/
public static class Builder extends BasicBuilder<UpdateOptions, Builder> {
private Builder(String email, String institute) {
super(new UpdateOptions(email, institute));
thisBuilder = this;
}

@Override
public UpdateOptions build() {
return updateOptions;
}

}

}

/**
* Basic builder to build {@link AccountRequestAttributes} related classes.
*
* @param <T> type to be built
* @param <B> type of the builder
*/
private abstract static class BasicBuilder<T, B extends BasicBuilder<T, B>> {

UpdateOptions updateOptions;
B thisBuilder;

BasicBuilder(UpdateOptions updateOptions) {
this.updateOptions = updateOptions;
}

public B withRegisteredAt(Instant registeredAt) {
assert registeredAt != null;

updateOptions.registeredAtOption = UpdateOption.of(registeredAt);
return thisBuilder;
}

public abstract T build();

}
}
4 changes: 4 additions & 0 deletions src/main/java/teammates/common/util/AppUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public AppUrl withRegistrationKey(String key) {
return withParam(Const.ParamsNames.REGKEY, key);
}

public AppUrl withIsCreatingAccount(String isCreatingAccount) {
return withParam(Const.ParamsNames.IS_CREATING_ACCOUNT, isCreatingAccount);
}

public AppUrl withCourseId(String courseId) {
return withParam(Const.ParamsNames.COURSE_ID, courseId);
}
Expand Down
Loading