| 1 | package edu.ucsb.cs.citelines.startup; | |
| 2 | ||
| 3 | import edu.ucsb.cs.citelines.entity.Admin; | |
| 4 | import edu.ucsb.cs.citelines.repository.AdminRepository; | |
| 5 | import java.util.List; | |
| 6 | import lombok.extern.slf4j.Slf4j; | |
| 7 | import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | import org.springframework.beans.factory.annotation.Value; | |
| 9 | import org.springframework.stereotype.Component; | |
| 10 | ||
| 11 | /** | |
| 12 | * Seeds the admins table from ADMIN_EMAILS on every startup, so that users listed there get | |
| 13 | * ROLE_ADMIN on login without first needing to be added manually through the Admins page. | |
| 14 | */ | |
| 15 | @Slf4j | |
| 16 | @Component | |
| 17 | public class ScaffoldStartup { | |
| 18 | ||
| 19 | @Value("#{'${app.admin.emails}'.split(',')}") | |
| 20 | List<String> adminEmails; | |
| 21 | ||
| 22 | @Autowired AdminRepository adminRepository; | |
| 23 | ||
| 24 | public void alwaysRunOnStartup() { | |
| 25 | log.info("ScaffoldStartup.alwaysRunOnStartup called"); | |
| 26 | ||
| 27 | try { | |
| 28 |
1
1. alwaysRunOnStartup : removed call to java/util/List::forEach → KILLED |
adminEmails.forEach( |
| 29 | (email) -> { | |
| 30 | Admin admin = new Admin(email.strip()); | |
| 31 | adminRepository.save(admin); | |
| 32 | }); | |
| 33 | } catch (Exception e) { | |
| 34 | log.error("Error loading ADMIN_EMAILS into admins table:", e); | |
| 35 | } | |
| 36 | } | |
| 37 | } | |
Mutations | ||
| 28 |
1.1 |