This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 5766a9ee authored by Eduard Frankford's avatar Eduard Frankford
Browse files

fix mail sending and add role review manager

parent c1cc679f
Branches
1 merge request!191Resolve "Check Email Service in production"
package at.ac.uibk.gitsearch.repository.jpa;
import at.ac.uibk.gitsearch.domain.Authority;
import at.ac.uibk.gitsearch.domain.User;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
/**
* Spring Data JPA repository for the {@link Authority} entity.
......@@ -22,4 +24,7 @@ public interface AuthorityRepository extends JpaRepository<Authority, String> {
List<Authority> getUsedAuthorities();
List<Authority> findAll();
@Query("SELECT u FROM User u JOIN u.authorities auth WHERE auth.name = :authority")
List<User> findAllUsersWithAuthority(@Param("authority") String authority);
}
......@@ -14,6 +14,8 @@ public final class AuthoritiesConstants {
public static final String ANONYMOUS = "ROLE_ANONYMOUS";
public static final String REVIEW_MANAGER = "ROLE_REVIEW_MANAGER";
/** just a convenience enum to access authorities in all their variants */
public enum AuthoritiesConstantEnum {
ADMIN(AuthoritiesConstants.ADMIN),
......
package at.ac.uibk.gitsearch.service;
import at.ac.uibk.gitsearch.domain.User;
import at.ac.uibk.gitsearch.repository.jpa.AuthorityRepository;
import at.ac.uibk.gitsearch.repository.jpa.UserRepository;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class AuthorityService {
private final Logger log = LoggerFactory.getLogger(AuthorityService.class);
private final AuthorityRepository authorityRepository;
private final UserRepository userRepository;
public AuthorityService(UserRepository userRepository, AuthorityRepository authorityRepository) {
this.userRepository = userRepository;
this.authorityRepository = authorityRepository;
}
// Get all users with authority ROLE_REVIEW_MANAGER
List<User> findAllUsersWithAuthority(String authority) {
return authorityRepository.findAllUsersWithAuthority(authority);
}
}
......@@ -57,6 +57,9 @@ public class ReviewService {
@Autowired
private MailService mailService;
@Autowired
private AuthorityService authorityService;
@Autowired
private ReviewRatingMapper reviewRatingMapper;
......@@ -405,13 +408,15 @@ public class ReviewService {
addHistoryEntry(review, null, userO, ReviewStatus.REVIEW_REQUESTED, "");
reviewRepository.save(review);
mailService.sendEmail(
System.getenv("REVIEW_ADMIN"),
"NEW REVIEW REQUESTED",
userO.get().getEmail() + " requested a review for " + request.getResource(),
false,
false
);
for (User u : authorityService.findAllUsersWithAuthority("ROLE_REVIEW_MANAGER")) {
mailService.sendEmail(
u.getEmail(),
"NEW REVIEW REQUESTED",
userO.get().getEmail() + " requested a review for " + request.getResource(),
false,
false
);
}
}
private void addHistoryEntry(
......
......@@ -12,6 +12,7 @@ import at.ac.uibk.gitsearch.service.dto.AdminUserDTO;
import at.ac.uibk.gitsearch.service.dto.UserDTO;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
......@@ -364,7 +365,9 @@ public class UserService {
*/
@Transactional(readOnly = true)
public List<String> getAuthorities() {
return authorityRepository.findAll().stream().map(Authority::getName).collect(Collectors.toList());
List<String> authorities = authorityRepository.findAll().stream().map(Authority::getName).collect(Collectors.toList());
authorities.add(AuthoritiesConstants.REVIEW_MANAGER);
return authorities;
}
public void updateLastLogin(Long userId) {
......
......@@ -45,7 +45,7 @@
</div>
</div>
<h3 class="p-3">Request Reviews From Other Authors</h3>
<h3 class="p-3" jhiTranslate="review.create.requestedReviewsByOther">Request Reviews From Other Authors</h3>
<div class="table-responsive" *ngIf="otherReviews">
<table class="table table-striped" aria-describedby="user-management-page-heading">
......@@ -159,7 +159,7 @@
</tbody>
</table>
</div>
<h3 class="p-3">My Requested Reviews</h3>
<h3 class="p-3" jhiTranslate="review.create.requestedReviewsByMe">My Requested Reviews</h3>
<div class="table-responsive" *ngIf="userReviews">
<table class="table table-striped" aria-describedby="user-management-page-heading">
......
......@@ -59,6 +59,7 @@
class="form-control"
name="username"
id="username"
autocomplete="username"
placeholder="{{ 'global.form.username.placeholder' | translate }}"
formControlName="username"
#username
......@@ -73,6 +74,7 @@
class="form-control"
name="password"
id="password"
autocomplete="current-password"
placeholder="{{ 'login.form.password.placeholder' | translate }}"
formControlName="password"
data-cy="password"
......
......@@ -16,6 +16,8 @@
"comments": "Kommentare ansehen",
"exerciseName": "Aufgaben Name",
"userEmail": "Benutzer Email",
"requestedReviewsByOther": "Review-Anfragen von anderen",
"requestedReviewsByMe": "Meine Review-Anfragen",
"selectResourceToBeReviewed": "Wählen Sie die Ressource aus, die Sie überprüfen lassen möchten",
"pleaseRegister": "Bitte registrieren Sie sich ebenfalls als Reviewer, um Ihre Resoucen reviewen lassen zu können.",
"resourceImproved": "Resource verbessert",
......
......@@ -16,6 +16,8 @@
"rewardBadge": "Reward Badge",
"exerciseName": "Enter exercise name",
"userEmail": "Enter user email",
"requestedReviewsByOther": "Requested Reviews by Others",
"requestedReviewsByMe": "My Requested Reviews",
"selectResourceToBeReviewed": "Select resource to be reviewed by peers",
"pleaseRegister": "Please register yourself as a reviewer if you want others to review your resources.",
"resourceImproved": "Resource Improved",
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment