This commit is contained in:
parent
1a6a4f69e8
commit
9f87f9be38
Binary file not shown.
@ -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;
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
@ -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,60 +136,63 @@ public class MainLayout extends AppLayout {
|
|||||||
|
|
||||||
private SideNav createNavigation() {
|
private SideNav createNavigation() {
|
||||||
final SideNav nav = new SideNav();
|
final SideNav nav = new SideNav();
|
||||||
nav.addItem(new SideNavItem("Home", MainView.class, LineAwesomeIcon.HOME_SOLID.create()));
|
|
||||||
|
|
||||||
if (isAdmin(authContext)) {
|
if (AuthUtils.isUser(authContext)) {
|
||||||
SideNavItem admin = new SideNavItem("Admin");
|
nav.addItem(new SideNavItem("Home", MainView.class, LineAwesomeIcon.HOME_SOLID.create()));
|
||||||
admin.setPrefixComponent(LineAwesomeIcon.BUILDING.create());
|
|
||||||
admin.addItem(new SideNavItem("Calendario", TimeOffListView.class,
|
|
||||||
LineAwesomeIcon.CALENDAR.create()));
|
|
||||||
nav.addItem(admin);
|
|
||||||
|
|
||||||
SideNavItem recruiting = new SideNavItem("Recruiting");
|
if (AuthUtils.isAdmin(authContext)) {
|
||||||
recruiting.setPrefixComponent(LineAwesomeIcon.BUSINESS_TIME_SOLID.create());
|
SideNavItem admin = new SideNavItem("Admin");
|
||||||
recruiting.addItem(new SideNavItem("Exams", ExamsListView.class,
|
admin.setPrefixComponent(LineAwesomeIcon.BUILDING.create());
|
||||||
LineAwesomeIcon.RIBBON_SOLID.create()));
|
admin.addItem(new SideNavItem("Calendario", TimeOffListView.class,
|
||||||
recruiting.addItem(new SideNavItem("Candidates", CandidatesListView.class,
|
LineAwesomeIcon.CALENDAR.create()));
|
||||||
LineAwesomeIcon.USER.create()));
|
nav.addItem(admin);
|
||||||
recruiting.addItem(new SideNavItem("Questions", QuestionsListView.class,
|
|
||||||
LineAwesomeIcon.QUESTION_SOLID.create()));
|
|
||||||
nav.addItem(recruiting);
|
|
||||||
}
|
|
||||||
|
|
||||||
final SideNavItem timeOff = new SideNavItem("Time-off");
|
SideNavItem recruiting = new SideNavItem("Recruiting");
|
||||||
timeOff.setPrefixComponent(LineAwesomeIcon.PLANE_DEPARTURE_SOLID.create());
|
recruiting.setPrefixComponent(LineAwesomeIcon.BUSINESS_TIME_SOLID.create());
|
||||||
timeOff.addItem(new SideNavItem("Vacations", TimeOffSummaryListView.class,
|
recruiting.addItem(new SideNavItem("Exams", ExamsListView.class,
|
||||||
LineAwesomeIcon.UMBRELLA_BEACH_SOLID.create()));
|
LineAwesomeIcon.RIBBON_SOLID.create()));
|
||||||
timeOff.addItem(new SideNavItem("Requests", TimeOffRequestsListView.class,
|
recruiting.addItem(new SideNavItem("Candidates", CandidatesListView.class,
|
||||||
LineAwesomeIcon.LIST_ALT.create()));
|
LineAwesomeIcon.USER.create()));
|
||||||
|
recruiting.addItem(new SideNavItem("Questions", QuestionsListView.class,
|
||||||
|
LineAwesomeIcon.QUESTION_SOLID.create()));
|
||||||
|
nav.addItem(recruiting);
|
||||||
|
}
|
||||||
|
|
||||||
final SideNavItem timesheet = new SideNavItem("Timesheet");
|
final SideNavItem timeOff = new SideNavItem("Time-off");
|
||||||
timesheet.setPrefixComponent(LineAwesomeIcon.HOURGLASS_START_SOLID.create());
|
timeOff.setPrefixComponent(LineAwesomeIcon.PLANE_DEPARTURE_SOLID.create());
|
||||||
timesheet.addItem(new SideNavItem("Registro de Horas Trabajadas", TimesheetListView.class,
|
timeOff.addItem(new SideNavItem("Vacations", TimeOffSummaryListView.class,
|
||||||
LineAwesomeIcon.ID_CARD_SOLID.create()));
|
LineAwesomeIcon.UMBRELLA_BEACH_SOLID.create()));
|
||||||
|
timeOff.addItem(new SideNavItem("Requests", TimeOffRequestsListView.class,
|
||||||
|
LineAwesomeIcon.LIST_ALT.create()));
|
||||||
|
|
||||||
if (isAdmin(authContext)) {
|
final SideNavItem timesheet = new SideNavItem("Timesheet");
|
||||||
timesheet.addItem(new SideNavItem("Reporte Horas Trabajadas", TimesheetReportView.class,
|
timesheet.setPrefixComponent(LineAwesomeIcon.HOURGLASS_START_SOLID.create());
|
||||||
|
timesheet.addItem(new SideNavItem("Registro de Horas Trabajadas", TimesheetListView.class,
|
||||||
LineAwesomeIcon.ID_CARD_SOLID.create()));
|
LineAwesomeIcon.ID_CARD_SOLID.create()));
|
||||||
|
|
||||||
|
if (AuthUtils.isAdmin(authContext)) {
|
||||||
|
timesheet.addItem(new SideNavItem("Reporte Horas Trabajadas", TimesheetReportView.class,
|
||||||
|
LineAwesomeIcon.ID_CARD_SOLID.create()));
|
||||||
|
}
|
||||||
|
|
||||||
|
final SideNavItem profile = new SideNavItem("Employee");
|
||||||
|
profile.setPrefixComponent(LineAwesomeIcon.USER_TIE_SOLID.create());
|
||||||
|
|
||||||
|
if (AuthUtils.isAdmin(authContext)) {
|
||||||
|
profile.addItem(new SideNavItem("Profiles", EmployeesListView.class,
|
||||||
|
LineAwesomeIcon.USER_FRIENDS_SOLID.create()));
|
||||||
|
}
|
||||||
|
|
||||||
|
profile.addItem(new SideNavItem("My Profile", "/employees/me",
|
||||||
|
LineAwesomeIcon.USER_EDIT_SOLID.create()));
|
||||||
|
profile.addItem(new SideNavItem("Documents", DocumentsListView.class,
|
||||||
|
LineAwesomeIcon.FILE_ALT_SOLID.create()));
|
||||||
|
|
||||||
|
nav.addItem(profile);
|
||||||
|
nav.addItem(timesheet);
|
||||||
|
nav.addItem(timeOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
final SideNavItem profile = new SideNavItem("Employee");
|
|
||||||
profile.setPrefixComponent(LineAwesomeIcon.USER_TIE_SOLID.create());
|
|
||||||
|
|
||||||
if (isAdmin(authContext)) {
|
|
||||||
profile.addItem(new SideNavItem("Profiles", EmployeesListView.class,
|
|
||||||
LineAwesomeIcon.USER_FRIENDS_SOLID.create()));
|
|
||||||
}
|
|
||||||
|
|
||||||
profile.addItem(new SideNavItem("My Profile", "/employees/me",
|
|
||||||
LineAwesomeIcon.USER_EDIT_SOLID.create()));
|
|
||||||
profile.addItem(new SideNavItem("Documents", DocumentsListView.class,
|
|
||||||
LineAwesomeIcon.FILE_ALT_SOLID.create()));
|
|
||||||
|
|
||||||
nav.addItem(profile);
|
|
||||||
nav.addItem(timesheet);
|
|
||||||
nav.addItem(timeOff);
|
|
||||||
|
|
||||||
return nav;
|
return nav;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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> {
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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,
|
||||||
|
@ -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)
|
||||||
|
@ -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", __ -> {
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -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 ->
|
||||||
|
@ -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();
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user