Skip to content

Commit

Permalink
Improve ootb user experience and fix minor errors
Browse files Browse the repository at this point in the history
Change OotbActiveUserProfileService in the test from autowired to MockBean and add mocking in setup function for better unit test

Ignore post construct in ootb controller in OotbSecurityConfigTest to fucus on the functions of OotbSecurityConfig test

test for v4 git actions

Change post construct function to update admin user at first to EventListener
  • Loading branch information
gitCarrot committed Sep 6, 2024
1 parent 2e4742f commit 31e995e
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
git push
fi
- name: Upload Jacoco coverage report
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: jacoco-report
path: target/site/jacoco/
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import java.util.List;

import jakarta.annotation.PostConstruct;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.owasp.html.PolicyFactory;
import org.owasp.html.Sanitizers;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -51,6 +55,20 @@ public OotbRestController(UserContextService userContextService,
this.ootbHttpRequestService = ootbHttpRequestService;
}

@EventListener
public void onApplicationEvent(ContextRefreshedEvent event) {
init();
}

public void init() {
String adminProfile = ootbActiveUserProfileService.findGivenNameForAdminRole();
if (adminProfile != null) {
updateActiveDefaultUser(adminProfile);
} else {
logger.error("Admin profile not found, unable to initiate default API request.");
}
}

/*
* Checks to make sure that the API is running and that there are no issues with
* the overrides file. Gets the active profiles and only runs the tests the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.hawaii.its.groupings.controller;

import java.util.Arrays;
import java.util.Locale;
import java.util.Map;

Expand All @@ -9,6 +10,7 @@
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand All @@ -20,6 +22,7 @@
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import edu.hawaii.its.groupings.access.UserContextService;
import edu.hawaii.its.groupings.configuration.Realm;
import edu.hawaii.its.groupings.service.EmailService;
import edu.hawaii.its.groupings.type.Feedback;

Expand All @@ -38,15 +41,21 @@ public class HomeController {

private final UserContextService userContextService;

public HomeController(EmailService emailService, UserContextService userContextService) {
private final Realm realmService;

public HomeController(EmailService emailService, UserContextService userContextService, Realm realmService) {
this.emailService = emailService;
this.userContextService = userContextService;
this.realmService = realmService;
}

// Mapping to home.
@GetMapping(value = { "/", "/home" })
public String home(Map<String, Locale> locale) {
logger.info("User at home. The client locale is " + locale);
if (realmService.isOotb()) {
return "redirect:/login";
}
return "home";
}

Expand Down
Loading

0 comments on commit 31e995e

Please sign in to comment.