fix permissions
All checks were successful
Builder / Build-Project (push) Successful in 2m56s

This commit is contained in:
alex 2025-01-05 20:03:23 -05:00
parent 1a6a4f69e8
commit 9f87f9be38
15 changed files with 80 additions and 81 deletions

Binary file not shown.

View File

@ -1,7 +1,5 @@
package com.primefactorsolutions.model; package com.primefactorsolutions.model;
import io.hypersistence.utils.hibernate.type.json.JsonType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Lob; import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
@ -9,9 +7,6 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;
import java.util.Map;
@Entity @Entity
@Data @Data
@ -25,9 +20,7 @@ public class Submission extends BaseEntity {
@Lob @Lob
private String text; private String text;
@Type(JsonType.class) private String output;
@Column(columnDefinition = "json")
private Map<String, Object> results;
private SubmissionStatus submissionStatus; private SubmissionStatus submissionStatus;

View File

@ -12,7 +12,6 @@ import org.springframework.stereotype.Service;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -32,7 +31,7 @@ public class ExamService {
public void sendEmail(final Exam exam) { public void sendEmail(final Exam exam) {
try { try {
final String evaluationLink = String.format("https://careers.primefactorsolutions.com/evaluation/%s", final String evaluationLink = String.format("https://careers.primefactorsolutions.com/candidate-exam/%s",
exam.getId()); exam.getId());
final SimpleMailMessage message = new SimpleMailMessage(); final SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("no-reply@primefactorsolutions.com"); message.setFrom("no-reply@primefactorsolutions.com");
@ -95,7 +94,7 @@ public class ExamService {
.findFirst(); .findFirst();
if (submissionToReturn.isEmpty()) { if (submissionToReturn.isEmpty()) {
final Submission result = new Submission(firstQuestion, firstQuestion.getContent(), Map.of(), final Submission result = new Submission(firstQuestion, firstQuestion.getContent(), null,
SubmissionStatus.FAIL, exam); SubmissionStatus.FAIL, exam);
exam.getSubmissions().add(result); exam.getSubmissions().add(result);
} }
@ -125,7 +124,7 @@ public class ExamService {
.findFirst(); .findFirst();
if (submissionToReturn.isEmpty()) { if (submissionToReturn.isEmpty()) {
final Submission result = new Submission(nextQuestion, nextQuestion.getContent(), Map.of(), final Submission result = new Submission(nextQuestion, nextQuestion.getContent(), null,
SubmissionStatus.FAIL, exam); SubmissionStatus.FAIL, exam);
exam.getSubmissions().add(result); exam.getSubmissions().add(result);
} }

View File

@ -54,10 +54,10 @@ import java.util.stream.Collectors;
@PageTitle("Evaluacion") @PageTitle("Evaluacion")
@SpringComponent @SpringComponent
@Scope("prototype") @Scope("prototype")
@Route(value = "/evaluation", layout = MainLayout.class) @Route(value = "/candidate-exam", layout = MainLayout.class)
@AnonymousAllowed @AnonymousAllowed
@Slf4j @Slf4j
public class EvaluationView extends Main implements HasUrlParameter<String> { public class CandidateExamView extends Main implements HasUrlParameter<String> {
private final CompilerService compilerService; private final CompilerService compilerService;
private final ExamService examService; private final ExamService examService;
@ -83,7 +83,7 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
private H3 questionTitle = null; private H3 questionTitle = null;
private Text questionDescription = null; private Text questionDescription = null;
public EvaluationView(final CompilerService compilerService, final ExamService examService) { public CandidateExamView(final CompilerService compilerService, final ExamService examService) {
this.compilerService = compilerService; this.compilerService = compilerService;
this.examService = examService; this.examService = examService;

View File

@ -11,6 +11,7 @@ import com.primefactorsolutions.views.timeoff.TimeOffRequestsListView;
import com.primefactorsolutions.views.timeoff.TimeOffSummaryListView; import com.primefactorsolutions.views.timeoff.TimeOffSummaryListView;
import com.primefactorsolutions.views.timesheet.TimesheetListView; import com.primefactorsolutions.views.timesheet.TimesheetListView;
import com.primefactorsolutions.views.timesheet.TimesheetReportView; import com.primefactorsolutions.views.timesheet.TimesheetReportView;
import com.primefactorsolutions.views.util.AuthUtils;
import com.vaadin.flow.component.Component; import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Text; import com.vaadin.flow.component.Text;
import com.vaadin.flow.component.applayout.AppLayout; import com.vaadin.flow.component.applayout.AppLayout;
@ -39,8 +40,6 @@ import org.vaadin.lineawesome.LineAwesomeIcon;
import java.util.UUID; import java.util.UUID;
import static com.primefactorsolutions.views.util.AuthUtils.isAdmin;
/** /**
* The main view is a top-level placeholder for other views. * The main view is a top-level placeholder for other views.
*/ */
@ -137,9 +136,11 @@ public class MainLayout extends AppLayout {
private SideNav createNavigation() { private SideNav createNavigation() {
final SideNav nav = new SideNav(); final SideNav nav = new SideNav();
if (AuthUtils.isUser(authContext)) {
nav.addItem(new SideNavItem("Home", MainView.class, LineAwesomeIcon.HOME_SOLID.create())); nav.addItem(new SideNavItem("Home", MainView.class, LineAwesomeIcon.HOME_SOLID.create()));
if (isAdmin(authContext)) { if (AuthUtils.isAdmin(authContext)) {
SideNavItem admin = new SideNavItem("Admin"); SideNavItem admin = new SideNavItem("Admin");
admin.setPrefixComponent(LineAwesomeIcon.BUILDING.create()); admin.setPrefixComponent(LineAwesomeIcon.BUILDING.create());
admin.addItem(new SideNavItem("Calendario", TimeOffListView.class, admin.addItem(new SideNavItem("Calendario", TimeOffListView.class,
@ -169,7 +170,7 @@ public class MainLayout extends AppLayout {
timesheet.addItem(new SideNavItem("Registro de Horas Trabajadas", TimesheetListView.class, timesheet.addItem(new SideNavItem("Registro de Horas Trabajadas", TimesheetListView.class,
LineAwesomeIcon.ID_CARD_SOLID.create())); LineAwesomeIcon.ID_CARD_SOLID.create()));
if (isAdmin(authContext)) { if (AuthUtils.isAdmin(authContext)) {
timesheet.addItem(new SideNavItem("Reporte Horas Trabajadas", TimesheetReportView.class, timesheet.addItem(new SideNavItem("Reporte Horas Trabajadas", TimesheetReportView.class,
LineAwesomeIcon.ID_CARD_SOLID.create())); LineAwesomeIcon.ID_CARD_SOLID.create()));
} }
@ -177,7 +178,7 @@ public class MainLayout extends AppLayout {
final SideNavItem profile = new SideNavItem("Employee"); final SideNavItem profile = new SideNavItem("Employee");
profile.setPrefixComponent(LineAwesomeIcon.USER_TIE_SOLID.create()); profile.setPrefixComponent(LineAwesomeIcon.USER_TIE_SOLID.create());
if (isAdmin(authContext)) { if (AuthUtils.isAdmin(authContext)) {
profile.addItem(new SideNavItem("Profiles", EmployeesListView.class, profile.addItem(new SideNavItem("Profiles", EmployeesListView.class,
LineAwesomeIcon.USER_FRIENDS_SOLID.create())); LineAwesomeIcon.USER_FRIENDS_SOLID.create()));
} }
@ -190,6 +191,7 @@ public class MainLayout extends AppLayout {
nav.addItem(profile); nav.addItem(profile);
nav.addItem(timesheet); nav.addItem(timesheet);
nav.addItem(timeOff); nav.addItem(timeOff);
}
return nav; return nav;
} }

View File

@ -20,9 +20,9 @@ import com.vaadin.flow.component.menubar.MenuBarVariant;
import com.vaadin.flow.component.orderedlayout.FlexComponent; import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.*; import com.vaadin.flow.router.*;
import com.vaadin.flow.server.auth.AnonymousAllowed;
import com.vaadin.flow.spring.annotation.SpringComponent; import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.theme.lumo.LumoUtility.*; import com.vaadin.flow.theme.lumo.LumoUtility.*;
import jakarta.annotation.security.RolesAllowed;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
@ -37,8 +37,8 @@ import java.util.stream.Collectors;
@PageTitle("Evaluacion") @PageTitle("Evaluacion")
@SpringComponent @SpringComponent
@Scope("prototype") @Scope("prototype")
@Route(value = "/submission", layout = MainLayout.class) @RolesAllowed("ROLE_ADMIN")
@AnonymousAllowed @Route(value = "/submissions", layout = MainLayout.class)
@Slf4j @Slf4j
public class SubmissionView extends Main implements HasUrlParameter<String> { public class SubmissionView extends Main implements HasUrlParameter<String> {

View File

@ -12,7 +12,7 @@ import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route; import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent; import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.security.AuthenticationContext; import com.vaadin.flow.spring.security.AuthenticationContext;
import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
@ -23,7 +23,7 @@ import java.util.UUID;
@Scope("prototype") @Scope("prototype")
@PageTitle("Candidates") @PageTitle("Candidates")
@Route(value = "/candidates", layout = MainLayout.class) @Route(value = "/candidates", layout = MainLayout.class)
@PermitAll @RolesAllowed("ROLE_ADMIN")
public class CandidateView extends BaseEntityForm<Candidate> implements HasUrlParameter<String> { public class CandidateView extends BaseEntityForm<Candidate> implements HasUrlParameter<String> {
private final CandidateService candidateService; private final CandidateService candidateService;

View File

@ -16,7 +16,7 @@ import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route; import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent; import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.security.AuthenticationContext; import com.vaadin.flow.spring.security.AuthenticationContext;
import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.vaadin.firitin.components.grid.VGrid; import org.vaadin.firitin.components.grid.VGrid;
@ -27,7 +27,7 @@ import java.util.Map;
@Scope("prototype") @Scope("prototype")
@PageTitle("Candidates") @PageTitle("Candidates")
@Route(value = "/candidates", layout = MainLayout.class) @Route(value = "/candidates", layout = MainLayout.class)
@PermitAll @RolesAllowed("ROLE_ADMIN")
public class CandidatesListView extends BaseView { public class CandidatesListView extends BaseView {
public CandidatesListView(final AuthenticationContext authenticationContext, public CandidatesListView(final AuthenticationContext authenticationContext,

View File

@ -16,7 +16,7 @@ import com.vaadin.flow.router.HasUrlParameter;
import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route; import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent; import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.vaadin.firitin.fields.SubListSelector; import org.vaadin.firitin.fields.SubListSelector;
@ -26,7 +26,7 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
@SpringComponent @SpringComponent
@PermitAll @RolesAllowed("ROLE_ADMIN")
@Scope("prototype") @Scope("prototype")
@PageTitle("Exams") @PageTitle("Exams")
@Route(value = "/exams", layout = MainLayout.class) @Route(value = "/exams", layout = MainLayout.class)

View File

@ -17,7 +17,7 @@ import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route; import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent; import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.security.AuthenticationContext; import com.vaadin.flow.spring.security.AuthenticationContext;
import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.vaadin.addon.stefan.clipboard.ClientsideClipboard; import org.vaadin.addon.stefan.clipboard.ClientsideClipboard;
@ -27,7 +27,7 @@ import org.vaadin.firitin.components.grid.VGrid;
@Scope("prototype") @Scope("prototype")
@PageTitle("Exams") @PageTitle("Exams")
@Route(value = "/exams", layout = MainLayout.class) @Route(value = "/exams", layout = MainLayout.class)
@PermitAll @RolesAllowed("ROLE_ADMIN")
public class ExamsListView extends BaseView { public class ExamsListView extends BaseView {
public ExamsListView(final AuthenticationContext authenticationContext, public ExamsListView(final AuthenticationContext authenticationContext,
@ -53,7 +53,8 @@ public class ExamsListView extends BaseView {
getUI().flatMap(ui -> ui.navigate(SubmissionView.class, exam.getId().toString()))), getUI().flatMap(ui -> ui.navigate(SubmissionView.class, exam.getId().toString()))),
Pair.of("Copy", __ -> Pair.of("Copy", __ ->
ClientsideClipboard.writeToClipboard( ClientsideClipboard.writeToClipboard(
String.format("email: %s link: https://intra.primefactorsolutions.com/evaluation/%s", String.format("email: %s link: "
+ "https://intra.primefactorsolutions.com/candidate-exam/%s",
exam.getCandidate().getEmail(), exam.getCandidate().getEmail(),
exam.getId()))), exam.getId()))),
Pair.of("Email", __ -> { Pair.of("Email", __ -> {

View File

@ -11,7 +11,7 @@ import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.*; import com.vaadin.flow.router.*;
import com.vaadin.flow.spring.annotation.SpringComponent; import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.security.AuthenticationContext; import com.vaadin.flow.spring.security.AuthenticationContext;
import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
@ -22,7 +22,7 @@ import java.util.UUID;
@Scope("prototype") @Scope("prototype")
@PageTitle("Questions") @PageTitle("Questions")
@Route(value = "/questions", layout = MainLayout.class) @Route(value = "/questions", layout = MainLayout.class)
@PermitAll @RolesAllowed("ROLE_ADMIN")
public class QuestionView extends BaseEntityForm<Question> implements HasUrlParameter<String> { public class QuestionView extends BaseEntityForm<Question> implements HasUrlParameter<String> {
private final QuestionService questionService; private final QuestionService questionService;

View File

@ -15,7 +15,7 @@ import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route; import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent; import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.security.AuthenticationContext; import com.vaadin.flow.spring.security.AuthenticationContext;
import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.vaadin.firitin.components.grid.VGrid; import org.vaadin.firitin.components.grid.VGrid;
@ -24,7 +24,7 @@ import org.vaadin.firitin.components.grid.VGrid;
@Scope("prototype") @Scope("prototype")
@PageTitle("Questions") @PageTitle("Questions")
@Route(value = "/questions", layout = MainLayout.class) @Route(value = "/questions", layout = MainLayout.class)
@PermitAll @RolesAllowed("ROLE_ADMIN")
public class QuestionsListView extends BaseView { public class QuestionsListView extends BaseView {
public QuestionsListView(final AuthenticationContext authenticationContext, final QuestionService questionService) { public QuestionsListView(final AuthenticationContext authenticationContext, final QuestionService questionService) {

View File

@ -11,6 +11,10 @@ import java.util.UUID;
@UtilityClass @UtilityClass
public class AuthUtils { public class AuthUtils {
public static boolean isUser(final AuthenticationContext authenticationContext) {
return authenticationContext.getAuthenticatedUser(UserDetails.class).isPresent();
}
public static boolean isAdmin(final AuthenticationContext authenticationContext) { public static boolean isAdmin(final AuthenticationContext authenticationContext) {
return authenticationContext.getAuthenticatedUser(UserDetails.class) return authenticationContext.getAuthenticatedUser(UserDetails.class)
.map(u -> .map(u ->

View File

@ -35,7 +35,7 @@ public class AbstractAppTests {
protected void login(String user, String pass, final List<String> roles) { protected void login(String user, String pass, final List<String> roles) {
final List<SimpleGrantedAuthority> authorities = final List<SimpleGrantedAuthority> authorities =
roles.stream().map(it -> new SimpleGrantedAuthority("ROLE_" + it)).collect(Collectors.toList()); roles.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList());
UsernamePasswordAuthenticationToken authReq UsernamePasswordAuthenticationToken authReq
= new UsernamePasswordAuthenticationToken(new User(user, pass, authorities), pass, authorities); = new UsernamePasswordAuthenticationToken(new User(user, pass, authorities), pass, authorities);
SecurityContext sc = SecurityContextHolder.getContext(); SecurityContext sc = SecurityContextHolder.getContext();

View File

@ -14,7 +14,7 @@ import static com.github.mvysny.kaributesting.v10.LocatorJ.*;
public class CandidateViewTests extends AbstractAppTests { public class CandidateViewTests extends AbstractAppTests {
@BeforeEach @BeforeEach
public void login() { public void login() {
login("user", "user", List.of("user")); login("user", "user", List.of("ROLE_ADMIN"));
} }
@Test @Test