Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit b4cf25e

Browse files
author
Irene
committed
Fix migrating from /mooc -server
1 parent 4407c33 commit b4cf25e

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

src/main/java/fi/helsinki/cs/tmc/cli/backend/Account.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Account {
2121
private boolean sendDiagnostics;
2222
private boolean sendAnalytics;
2323
private boolean sendDetailedAnalytics;
24-
private static final String DEFAULT_SERVER = "https://tmc.mooc.fi/staging";
24+
private static final String DEFAULT_SERVER = "https://tmc.mooc.fi";
2525

2626
// for gson
2727
public Account() {

src/main/java/fi/helsinki/cs/tmc/cli/backend/Settings.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ public void setAccount(CliContext context, Account account) {
6464

6565
private boolean migrateAccount(CliContext context, Account account) throws Exception {
6666
Io io = context.getIo();
67-
io.println("TMC cli has been updated. Please provide the following information.");
67+
// the old server doesn't have any organizations
68+
if (account.getServerAddress().contains("tmc.mooc.fi/mooc")) {
69+
return false;
70+
}
6871
TmcServerAddressNormalizer normalizer = new TmcServerAddressNormalizer();
6972
normalizer.normalize();
7073
normalizer.selectOrganizationAndCourse();
74+
io.println("TMC cli has been updated. Please provide the following information.");
7175
if (!context.getSettings().getOrganization().isPresent()) {
7276
OrganizationCommand organizationCommand = new OrganizationCommand();
7377
Optional<Organization> organization = organizationCommand.chooseOrganization(context, null);

src/main/java/fi/helsinki/cs/tmc/cli/command/ConfigCommand.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class ConfigCommand extends AbstractCommand {
2626
private static final Set<String> PROGRESS_BAR_COLORS = new HashSet<>(Arrays.asList("black", "red", "green", "blue", "yellow", "blue", "purple", "cyan", "white", "none"));
2727
private static final String sendAnalyticsKey = "send-analytics";
2828
private static final String serverAddressKey = "server-address";
29-
private static final String updateDateKey = "update-date";
3029
private static final String testResultRightKey = "testresults-right";
3130
private static final String testResultLeftKey = "testresults-left";
3231
private static final String progressBarLeftKey = "progressbar-left";
@@ -84,10 +83,6 @@ public void setter(String value) throws BadValueTypeException {
8483
}
8584
context.getSettings().setServerAddress(addr);
8685
normalizeServerAddress();
87-
if (addr.matches("^https?://tmc.mooc.fi/mooc")) {
88-
io.println("Please note that the server http://tmc.mooc.fi/mooc is no longer supported.");
89-
}
90-
io.println("All courses are now hosted at https://tmc.mooc.fi. We do not advise changing the server address.");
9186
SettingsIo.saveCurrentSettingsToAccountList(context.getSettings());
9287
}
9388
});
@@ -289,6 +284,16 @@ private void setProperties(String[] arguments) {
289284
continue;
290285
}
291286
String oldValue = properties.get(parts[0]);
287+
if (parts[0].equals(serverAddressKey)) {
288+
io.println("All courses are now hosted at https://tmc.mooc.fi. We do not advise changing the server address.");
289+
if (parts[0].contains("tmc.mooc.fi/mooc")) {
290+
io.println("The server https://tmc.mooc.fi/mooc is no longer supported by this client.\n" +
291+
"If you'd like to do the migrated courses, you'll have to create an account on the new server.\n" +
292+
"Choose the MOOC organization when logging in.\n\n" +
293+
"For more information, check the course materials on mooc.fi.");
294+
return;
295+
}
296+
}
292297
if (io.readConfirmation(" Set " + parts[0] + " to \"" + parts[1] + "\"?", true)) {
293298
if (!saveValue(parts[0], parts[1])) {
294299
continue;

src/main/java/fi/helsinki/cs/tmc/cli/command/OrganizationCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public Optional<Organization> chooseOrganization(CliContext ctx, CommandLine arg
100100
oneLine = args.hasOption("o");
101101
}
102102
List<Organization> organizations = listOrganizations();
103-
if (organizations == null) {
103+
if (organizations == null || organizations.isEmpty()) {
104104
io.errorln("Failed to fetch organizations from server.");
105105
return Optional.absent();
106106
}

src/main/java/fi/helsinki/cs/tmc/cli/core/CliContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,15 @@ public void loadUserInformation(boolean useCache) {
224224
cachedAccount = list.getAccount();
225225
}
226226
hasLogin = cachedAccount != null;
227+
if (hasLogin && cachedAccount.getServerAddress().contains("tmc.mooc.fi/mooc")) {
228+
io.println("The server https://tmc.mooc.fi/mooc is no longer supported by this client.\n" +
229+
"All the courses have been migrated to our main server https://tmc.mooc.fi.\n" +
230+
"If you'd like to do the migrated courses, you have to create a new account on the new server.\n" +
231+
"Choose the MOOC organization when logging in.\n\n" +
232+
"For more information, check the course materials on mooc.fi.");
233+
SettingsIo.delete();
234+
return;
235+
}
227236
if (useCache) {
228237
this.settings.setAccount(this, cachedAccount);
229238
}

0 commit comments

Comments
 (0)