#8: Use Permissions in Nurse Controller
Some checks failed
Quality Check / Linting Check (push) Failing after 12s
Quality Check / Javadoc Check (push) Successful in 21s
Quality Check / Linting Check (pull_request) Failing after 13s
Quality Check / Javadoc Check (pull_request) Successful in 21s

Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
This commit is contained in:
Dominik Säume 2024-05-22 09:36:07 +02:00
parent ae7fc3ab64
commit 7db1c83a08
Signed by: SZUT-Dominik
GPG key ID: 67D15BB250B41E7C
2 changed files with 55 additions and 18 deletions

View file

@ -20,12 +20,24 @@ import java.util.List;
* @author Dorian Nemec
*/
public class MainWindowController {
private static MainWindowController instace;
@FXML
public TabPane mainTabPane;
private User user;
private TabManager tabManager;
public MainWindowController() {
instace = this;
}
public static MainWindowController getInstance() {
return instace;
}
public User getUser() {
return user;
}
/**
* JavaFX Initialization method that is called after the binding of all the fields.
*
@ -33,6 +45,7 @@ public class MainWindowController {
*/
@FXML
public void initialize(User user) {
instace = this;
this.user = user;
this.tabManager = new TabManager(user);
setupTabs();
@ -63,7 +76,7 @@ public class MainWindowController {
new TabStruct(
"Pfleger",
"/de/hitec/nhplus/nurse/AllNurseView.fxml",
Permissions.NURSE | Permissions.MANAGEMENT
Permissions.NURSE | Permissions.MANAGEMENT | Permissions.OWNER
),
new TabStruct(
"Gesperrte Pfleger",

View file

@ -1,8 +1,8 @@
package de.hitec.nhplus.nurse;
import static de.hitec.nhplus.utils.Validator.*;
import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.login.Permissions;
import de.hitec.nhplus.main.MainWindowController;
import de.hitec.nhplus.nurse.database.NurseDao;
import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
@ -17,6 +17,8 @@ import javafx.scene.control.cell.TextFieldTableCell;
import java.sql.SQLException;
import static de.hitec.nhplus.utils.Validator.*;
/**
* The controller for viewing all {@link Nurse}s.
*
@ -49,12 +51,17 @@ public class AllNurseController {
private final ObservableList<Nurse> nurses = FXCollections.observableArrayList();
private NurseDao dao;
private boolean hasEditPermissions;
/**
* Initialization method that is called after the binding of all the fields.
*/
@FXML
public void initialize() {
int editPermissions = Permissions.MANAGEMENT | Permissions.OWNER;
int userPermissions = MainWindowController.getInstance().getUser().getPermissions();
hasEditPermissions = (userPermissions & editPermissions) != 0;
this.readAllAndShowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
@ -71,7 +78,13 @@ public class AllNurseController {
this.tableView.setItems(this.nurses);
this.buttonAdd.setDisable(true);
if (!hasEditPermissions) {
this.buttonLock.setDisable(true);
return;
}
ChangeListener<String> inputNewNurseValidationListener = (observableValue, oldText, newText) ->
{
boolean isValid = isValidFirstName(this.textFieldFirstName.getText())
@ -126,8 +139,7 @@ public class AllNurseController {
String phoneNumber = this.textFieldPhoneNumber.getText();
try {
this.dao.create(new Nurse(firstName, surname, phoneNumber));
}
catch (SQLException exception){
} catch (SQLException exception) {
exception.printStackTrace();
}
readAllAndShowInTableView();
@ -152,6 +164,10 @@ public class AllNurseController {
@FXML
public void handleOnEditSurname(TableColumn.CellEditEvent<Nurse, String> event) {
if(!hasEditPermissions){
event.getTableView().refresh();
return;
}
String newSurName = event.getNewValue();
if (!isValidSurName(newSurName)) {
showValidationError("Nachname");
@ -164,6 +180,10 @@ public class AllNurseController {
@FXML
public void handleOnEditFirstname(TableColumn.CellEditEvent<Nurse, String> event) {
if(!hasEditPermissions){
event.getTableView().refresh();
return;
}
String newFirstName = event.getNewValue();
if (!isValidFirstName(newFirstName)) {
showValidationError("Vorname");
@ -176,6 +196,10 @@ public class AllNurseController {
@FXML
public void handleOnEditPhoneNumber(TableColumn.CellEditEvent<Nurse, String> event) {
if(!hasEditPermissions){
event.getTableView().refresh();
return;
}
String newPhoneNumber = event.getNewValue();
if (!isValidPhoneNumber(newPhoneNumber)) {
showValidationError("Telefonnummer");