Skip to content

Commit

Permalink
Added admin edit check
Browse files Browse the repository at this point in the history
  • Loading branch information
ChooJeremy committed Nov 1, 2018
1 parent 050885d commit ef951b6
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class SelfEditCommand extends Command {

public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String ADMIN_EDIT_ERROR = "You're currently logged in as admin, not as an employee!\nAdmin"
+ " cannot be edit. Perhaps you meant edit instead?";

private EditCommand.EditPersonDescriptor editPersonDescriptor;

Expand All @@ -52,6 +54,10 @@ public SelfEditCommand(EditCommand.EditPersonDescriptor editPersonDescriptor) {
public CommandResult runBody(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);

if (model.getLoggedInUser().isAdminUser()) {
throw new CommandException(ADMIN_EDIT_ERROR);
}

Person personToEdit = model.getLoggedInUser().getPerson();
Person editedPerson = EditCommand.createEditedPerson(personToEdit, editPersonDescriptor);

Expand Down

0 comments on commit ef951b6

Please sign in to comment.