Skip to content

Commit 49b9d88

Browse files
Merge branch 'release-5.20.5'
2 parents b5297c9 + d174d5b commit 49b9d88

69 files changed

Lines changed: 2725 additions & 2140 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wise",
3-
"version": "5.20.4",
3+
"version": "5.20.5",
44
"description": "Web-based Inquiry Science Environment",
55
"main": "app.js",
66
"browserslist": [

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<artifactId>wise</artifactId>
3535
<packaging>war</packaging>
3636
<name>Web-based Inquiry Science Environment</name>
37-
<version>5.20.4</version>
37+
<version>5.20.5</version>
3838
<url>http://wise5.org</url>
3939
<licenses>
4040
<license>

src/main/java/org/wise/portal/presentation/web/controllers/teacher/TeacherAPIController.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.apache.commons.lang3.RandomStringUtils;
1515
import org.springframework.beans.factory.annotation.Autowired;
1616
import org.springframework.beans.factory.annotation.Value;
17-
import org.springframework.context.MessageSource;
1817
import org.springframework.security.access.annotation.Secured;
1918
import org.springframework.security.acls.model.Permission;
2019
import org.springframework.security.core.Authentication;
@@ -38,7 +37,6 @@
3837
import org.wise.portal.presentation.web.response.SimpleResponse;
3938
import org.wise.portal.service.authentication.DuplicateUsernameException;
4039
import org.wise.portal.service.authentication.UserDetailsService;
41-
import org.wise.portal.service.mail.IMailFacade;
4240

4341
/**
4442
* Teacher REST API
@@ -55,12 +53,6 @@ public class TeacherAPIController extends UserAPIController {
5553
@Autowired
5654
private UserDetailsService userDetailsService;
5755

58-
@Autowired
59-
protected IMailFacade mailService;
60-
61-
@Autowired
62-
protected MessageSource messageSource;
63-
6456
@Value("${google.clientId:}")
6557
private String googleClientId;
6658

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package org.wise.portal.presentation.web.controllers.user;
2+
3+
import java.util.HashMap;
4+
import java.util.Locale;
5+
6+
import javax.mail.MessagingException;
7+
8+
import org.springframework.security.access.annotation.Secured;
9+
import org.springframework.security.core.Authentication;
10+
import org.springframework.web.bind.annotation.GetMapping;
11+
import org.springframework.web.bind.annotation.PostMapping;
12+
import org.springframework.web.bind.annotation.RequestMapping;
13+
import org.springframework.web.bind.annotation.RequestParam;
14+
import org.springframework.web.bind.annotation.RestController;
15+
import org.wise.portal.domain.authentication.impl.PersistentUserDetails;
16+
import org.wise.portal.domain.authentication.impl.TeacherUserDetails;
17+
import org.wise.portal.domain.user.User;
18+
import org.wise.portal.presentation.web.exception.InvalidPasswordExcpetion;
19+
20+
@RestController
21+
@RequestMapping("/api/google-user")
22+
public class GoogleUserAPIController extends UserAPIController {
23+
24+
@GetMapping("/check-user-exists")
25+
boolean isGoogleIdExist(@RequestParam String googleUserId) {
26+
return userService.retrieveUserByGoogleUserId(googleUserId) != null;
27+
}
28+
29+
@GetMapping("/check-user-matches")
30+
boolean isGoogleIdMatches(@RequestParam String googleUserId, @RequestParam String userId) {
31+
User user = userService.retrieveUserByGoogleUserId(googleUserId);
32+
return user != null && user.getId().toString().equals(userId);
33+
}
34+
35+
@GetMapping("/get-user")
36+
HashMap<String, Object> getUserByGoogleId(@RequestParam String googleUserId) {
37+
User user = userService.retrieveUserByGoogleUserId(googleUserId);
38+
HashMap<String, Object> response = new HashMap<String, Object>();
39+
if (user == null) {
40+
response.put("status", "error");
41+
} else {
42+
response.put("status", "success");
43+
response.put("userId", user.getId());
44+
response.put("username", user.getUserDetails().getUsername());
45+
response.put("firstName", user.getUserDetails().getFirstname());
46+
response.put("lastName", user.getUserDetails().getLastname());
47+
}
48+
return response;
49+
}
50+
51+
@Secured("ROLE_USER")
52+
@PostMapping("/unlink-account")
53+
HashMap<String, Object> unlinkGoogleAccount(Authentication auth, @RequestParam String newPassword)
54+
throws InvalidPasswordExcpetion {
55+
if (newPassword.isEmpty()) {
56+
throw new InvalidPasswordExcpetion();
57+
}
58+
String username = auth.getName();
59+
User user = userService.retrieveUserByUsername(username);
60+
((PersistentUserDetails) user.getUserDetails()).setGoogleUserId(null);
61+
userService.updateUserPassword(user, newPassword);
62+
boolean isSendEmail = Boolean.parseBoolean(appProperties.getProperty("send_email_enabled", "false"));
63+
if (isSendEmail && user.isTeacher()) {
64+
this.sendUnlinkGoogleEmail((TeacherUserDetails) user.getUserDetails());
65+
}
66+
return this.getUserInfo(auth, username);
67+
}
68+
69+
private void sendUnlinkGoogleEmail(TeacherUserDetails userDetails) {
70+
String[] recipients = { userDetails.getEmailAddress() };
71+
String subject = messageSource.getMessage("unlink_google_account_success_email_subject", null,
72+
"Successfully Unlinked Google Account", new Locale(userDetails.getLanguage()));
73+
String username = userDetails.getUsername();
74+
String message = messageSource.getMessage("unlink_google_account_success_email_body",
75+
new Object[]{username},
76+
"You have unlinked your Google account from WISE. To sign in to WISE in the future, please use your username and the password you just created. Your username is: " + username,
77+
new Locale(userDetails.getLanguage()));
78+
try {
79+
mailService.postMail(recipients, subject, message, appProperties.getProperty("portalemailaddress"));
80+
} catch (MessagingException e) {
81+
e.printStackTrace();
82+
}
83+
}
84+
}

src/main/java/org/wise/portal/presentation/web/controllers/user/UserAPIController.java

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import org.springframework.beans.factory.annotation.Autowired;
1414
import org.springframework.beans.factory.annotation.Value;
15+
import org.springframework.context.MessageSource;
1516
import org.springframework.security.core.Authentication;
1617
import org.springframework.security.core.GrantedAuthority;
1718
import org.springframework.security.web.authentication.switchuser.SwitchUserFilter;
@@ -63,6 +64,9 @@ public class UserAPIController {
6364
@Autowired
6465
protected IMailFacade mailService;
6566

67+
@Autowired
68+
protected MessageSource messageSource;
69+
6670
@Value("${google.clientId:}")
6771
protected String googleClientId = "";
6872

@@ -189,33 +193,6 @@ List<HashMap<String, String>> getSupportedLanguages() {
189193
return langs;
190194
}
191195

192-
@GetMapping("/check-google-user-exists")
193-
boolean isGoogleIdExist(@RequestParam String googleUserId) {
194-
return userService.retrieveUserByGoogleUserId(googleUserId) != null;
195-
}
196-
197-
@GetMapping("/check-google-user-matches")
198-
boolean isGoogleIdMatches(@RequestParam String googleUserId, @RequestParam String userId) {
199-
User user = userService.retrieveUserByGoogleUserId(googleUserId);
200-
return user != null && user.getId().toString().equals(userId);
201-
}
202-
203-
@GetMapping("/google-user")
204-
HashMap<String, Object> getUserByGoogleId(@RequestParam String googleUserId) {
205-
User user = userService.retrieveUserByGoogleUserId(googleUserId);
206-
HashMap<String, Object> response = new HashMap<String, Object>();
207-
if (user == null) {
208-
response.put("status", "error");
209-
} else {
210-
response.put("status", "success");
211-
response.put("userId", user.getId());
212-
response.put("username", user.getUserDetails().getUsername());
213-
response.put("firstName", user.getUserDetails().getFirstname());
214-
response.put("lastName", user.getUserDetails().getLastname());
215-
}
216-
return response;
217-
}
218-
219196
private String getLanguageName(String localeString) {
220197
if (localeString.toLowerCase().equals("zh_tw")) {
221198
return "Chinese (Traditional)";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.wise.portal.presentation.web.exception;
2+
3+
public class InvalidPasswordExcpetion extends Exception {
4+
5+
private static final long serialVersionUID = 1L;
6+
}

src/main/resources/i18n/i18n.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ teacher_cap.description=Text for the word "Teacher"
308308
team_cap=Team
309309
team_cap.description=Text for the word "Team"
310310

311+
unlink_google_account_success_email_subject=Successfully Unlinked Google Account
312+
unlink_google_account_success_email_subject.description=Subject text in email to notify user about successfuly unlinking google account
313+
314+
unlink_google_account_success_email_body=You have unlinked your Google account from WISE. To sign in to WISE in the future, please use your username and the password you just created.\n\nYour username is: {0}\n\nThank you for using WISE,\nWISE Team
315+
unlink_google_account_success_email_body.description=Body text in email to notify user about successfully unlinking google account
316+
311317
# Root (/) Pages #
312318

313319
accountmenu.forgot=Forgot Username or Password?

src/main/resources/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.20.4
1+
5.20.5

src/main/webapp/site/src/app/modules/library/copy-project-dialog/copy-project-dialog.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { finalize } from 'rxjs/operators';
55
import { LibraryProject } from '../libraryProject';
66
import { LibraryService } from '../../../services/library.service';
77
import { MatSnackBar } from '@angular/material/snack-bar';
8-
import { Subscription } from 'rxjs';
98

109
@Component({
1110
selector: 'app-copy-project-dialog',

0 commit comments

Comments
 (0)