Skip to content

Commit

Permalink
Merge pull request #12 from Psyf/admin-mgmt
Browse files Browse the repository at this point in the history
Admin management
  • Loading branch information
trufflepirate committed Sep 30, 2018
2 parents 0bf6185 + 51018ac commit 9affb07
Show file tree
Hide file tree
Showing 33 changed files with 809 additions and 45 deletions.
15 changes: 15 additions & 0 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ Disable admin mode. +

Format: logout

... *Add Admin:*
Add another admin. +
Format: addAdmin USERNAME PASSWORD VERIFY_PASSWORD

... *Remove Admin:*
Add another admin. +
Format: removeAdmin USERNAME

... *Update Admin Password:*
Add another admin. +
Format: updatePW USERNAME OLD_PW NEW_PW NEW_PW_VERIFY

... *Add Machine:*
Adds a new machine. All machine names must be unique. Status can only be either “enabled” or “disabled”. +

Expand Down Expand Up @@ -170,6 +182,9 @@ Edits an existing machine. All machine names must be unique. Status can only be
. exit
. login ADMIN_ID PASSWORD
. logout
. addAdmin USERNAME PASSWORD VERIFY_PASSWORD
. removeAdmin USERNAME
. updatePassword USERNAME OLD_PW NEW_PW NEW_PW_VERIFY
. add_machine n/MACHINE_NAME s/STATUS
. remove_machine MACHINE_NAME
. edit_machine MACHINE_NAME [n/MACHINE_NAME] [s/STATUS]
Binary file modified docs/diagrams/ModelComponentClassDiagram.pptx
Binary file not shown.
Binary file modified docs/images/ModelClassDiagram.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 8 additions & 7 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import seedu.address.storage.StorageManager;
import seedu.address.storage.UserPrefsStorage;
import seedu.address.storage.XmlAddressBookStorage;
import seedu.address.storage.admin.XmlMakerManagerAdminStorage;
import seedu.address.storage.machine.XmlMakerManagerMachineStorage;
import seedu.address.ui.Ui;
import seedu.address.ui.UiManager;
Expand Down Expand Up @@ -71,16 +72,16 @@ public void init() throws Exception {
* old path instead of the new one
*/
//Path path = Paths.get("data", "makerManagerMachines.xml");
//userPrefs.setMakerManagerAddressBookFilePath(path);
//logger.info("Address book file for maker manager " + userPrefs.getMakerManagerAddressBookFilePath());
//userPrefs.setMakerManagerMachinesFilePath(path);
//logger.info("Address book file for maker manager " + userPrefs.getMakerManagerMachinesFilePath());

AddressBookStorage addressBookStorage = new XmlAddressBookStorage(userPrefs.getAddressBookFilePath());
AddressBookStorage makerManagerAddressBookStorage =
new XmlMakerManagerMachineStorage(userPrefs.getMakerManagerAddressBookFilePath());
AddressBookStorage makerManagerMachineStorage =
new XmlMakerManagerMachineStorage(userPrefs.getMakerManagerMachinesFilePath());
AddressBookStorage makerManagerAdminStorage =
new XmlMakerManagerAdminStorage(userPrefs.getMakerManagerAdminsFilePath());



//TODO completely remove persons and integrate machines completely
//TODO: completely remove persons and integrate machines completely
/**
* Can change back to addressBookStorage here instead of makerManagerAddressBookStorage
* Need to change MainWindow UI back also for initial addressbook app to work normally
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package seedu.address.logic.commands.admin;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.admin.Admin;
import seedu.address.model.admin.Password;
import seedu.address.model.admin.Username;


/**
* Lets one admin add another admin
*/
public class AddAdminCommand extends Command {
public static final String COMMAND_WORD = "addAdmin";
public static final String MESSAGE_NO_ACCESS = "You must be logged in to add another admin!";
public static final String MESSAGE_SUCCESS = "New admin added successfully!";
public static final String MESSAGE_ADMIN_ALREADY_EXISTS = "This username already exists. Try a new one or login.";
public static final String MESSAGE_USAGE = COMMAND_WORD + "Used to add another admin.\n"
+ "Example: addAdmin USERNAME PASSWORD PASSWORD\n";
public static final String MESSAGE_PASSWORDS_DONT_MATCH = "The two password fields don't match! Please try again.";

private final Username username;
private final Password password;
private final Password passwordVerify;
private final Admin toAddIn;

public AddAdminCommand(Username username, Password password, Password passwordVerify) {
this.username = username;
this.password = password;
this.passwordVerify = passwordVerify;
this.toAddIn = new Admin(username, password);
}

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
if (!model.isLoggedIn()) {
throw new CommandException(MESSAGE_NO_ACCESS);
}

if (!password.equals(passwordVerify)) {
throw new CommandException(MESSAGE_PASSWORDS_DONT_MATCH);
}

if (model.findAdmin(username) != null) {
throw new CommandException(MESSAGE_ADMIN_ALREADY_EXISTS);
}

model.addAdmin(toAddIn);
model.commitAddressBook(); //TODO: not sure what this does;

return new CommandResult(MESSAGE_SUCCESS);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddAdminCommand // instanceof handles nulls
&& username.equals(((AddAdminCommand) other).username)
&& password.equals(((AddAdminCommand) other).password)
&& password.equals(((AddAdminCommand) other).passwordVerify)); // state check
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.admin;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.admin.Admin;
Expand All @@ -15,7 +17,7 @@ public class LoginCommand extends Command {
public static final String COMMAND_WORD = "login";
public static final String MESSAGE_SUCCESS = "login success!";
public static final String MESSAGE_WRONG_DETAILS = "Login failed! Wrong Username/Password.";
private static final String MESSAGE_ALREADY_LOGGED_IN = "Login failed! "
public static final String MESSAGE_ALREADY_LOGGED_IN = "Login failed! "
+ "Please Logout of current account before logging in again.";

public static final String MESSAGE_USAGE = COMMAND_WORD + "Login used for admin access.\n"
Expand All @@ -33,13 +35,13 @@ public LoginCommand(Username username, Password password) {

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
if (!model.hasAdmin(toLogIn)) {
throw new CommandException(MESSAGE_WRONG_DETAILS);
} else if (model.isLoggedIn()) {
if (model.isLoggedIn()) {
throw new CommandException(MESSAGE_ALREADY_LOGGED_IN);
} else if (!model.hasAdmin(toLogIn)) {
throw new CommandException(MESSAGE_WRONG_DETAILS);
}

model.setLogin();
model.setLogin(username);
model.commitAddressBook(); //TODO: not sure what this does;

return new CommandResult(MESSAGE_SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.admin;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package seedu.address.logic.commands.admin;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.admin.Admin;
import seedu.address.model.admin.Username;

/**
* Lets one admin remove another admin
*/
public class RemoveAdminCommand extends Command {
public static final String COMMAND_WORD = "removeAdmin";
public static final String MESSAGE_NO_ACCESS = "You must be logged in to remove another admin!";
public static final String MESSAGE_SUCCESS = "Admin removed successfully!";
public static final String MESSAGE_NO_SUCH_ADMIN = "No such admins exist. Have you typed the username correctly?";
private static final String MESSAGE_CANT_DELETE_LAST_ADMIN = "You can't delete the last admin.";
public static final String MESSAGE_USAGE = COMMAND_WORD + "Used to remove another admin.\n"
+ "Example: removeAdmin USERNAME\n";

private final Username username;

public RemoveAdminCommand(Username username) {
this.username = username;
}

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
if (!model.isLoggedIn()) {
throw new CommandException(MESSAGE_NO_ACCESS);
}

Admin toRemove = model.findAdmin(username);
if (toRemove == null) {
throw new CommandException(MESSAGE_NO_SUCH_ADMIN);
}

if (model.numAdmins() == 1) {
throw new CommandException(MESSAGE_CANT_DELETE_LAST_ADMIN);
}

model.removeAdmin(toRemove);

//Logout current admin if deleted him/herself
if (model.currentlyLoggedIn().equals(username)) {
model.clearLogin();
}

model.commitAddressBook(); //TODO: not sure what this does;

return new CommandResult(MESSAGE_SUCCESS);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof RemoveAdminCommand // instanceof handles nulls
&& username.equals(((RemoveAdminCommand) other).username)); // state check
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package seedu.address.logic.commands.admin;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.admin.Admin;
import seedu.address.model.admin.Password;
import seedu.address.model.admin.Username;

/**
* Command used to update Password of currently logged in Admin
*/
public class UpdatePasswordCommand extends Command {
public static final String COMMAND_WORD = "updatePassword";
public static final String MESSAGE_NO_ACCESS = "You must be logged in to change your password!";
public static final String MESSAGE_SUCCESS = "Your password has been changed successfully!";
public static final String MESSAGE_USAGE = COMMAND_WORD + " is used to change password of logged in admin.\n"
+ "Example: udpatePassword USERNAME OLD_PW NEW_PW NEW_PW_VERIFY\n";
public static final String MESSAGE_ONLY_CHANGE_YOUR_OWN_PW = "You can only change your own password.";
public static final String MESSAGE_PASSWORDS_DONT_MATCH = "The two password fields don't match! Please try again.";

private final Username username;
private final Password oldPassword;
private final Password newPassword;
private final Password passwordVerify;
private final Admin toUpdate;
private final Admin updatedAdmin;

public UpdatePasswordCommand(Username username, Password oldPassword,
Password newPassword, Password passwordVerify) {
this.username = username;
this.oldPassword = oldPassword;
this.newPassword = newPassword;
this.passwordVerify = passwordVerify;
this.toUpdate = new Admin(username, oldPassword);
this.updatedAdmin = new Admin(username, newPassword);
}

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
if (!model.isLoggedIn()) {
throw new CommandException(MESSAGE_NO_ACCESS);
}

if (!newPassword.equals(passwordVerify)) {
throw new CommandException(MESSAGE_PASSWORDS_DONT_MATCH);
}

if (!username.equals(model.currentlyLoggedIn())) {
throw new CommandException(MESSAGE_ONLY_CHANGE_YOUR_OWN_PW);
}

model.updateAdmin(toUpdate, updatedAdmin);
model.commitAddressBook(); //TODO: not sure what this does;

return new CommandResult(MESSAGE_SUCCESS);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof UpdatePasswordCommand // instanceof handles nulls
&& username.equals(((UpdatePasswordCommand) other).username)
&& newPassword.equals(((UpdatePasswordCommand) other).newPassword)
&& oldPassword.equals(((UpdatePasswordCommand) other).oldPassword)
&& passwordVerify.equals(((UpdatePasswordCommand) other).passwordVerify)); // state check
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
/**
* Adds a machine to MakerManager address book
*/
public class AddMachineCommand extends Command {
public class AddMachineCommand extends Command {

public static final String COMMAND_WORD = "add_machine";
public static final String COMMAND_WORD = "addMachine";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a machine to MakerManager address book. "
+ "Parameters: "
Expand Down Expand Up @@ -48,6 +48,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
throw new CommandException(MESSAGE_ACCESS_DENIED);
}

//TODO: @JJ AddMachineCommand Incomplete
return new CommandResult(String.format(MESSAGE_SUCCESS, machineToAdd));
}

Expand Down
26 changes: 19 additions & 7 deletions src/main/java/seedu/address/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.HistoryCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.LoginCommand;
import seedu.address.logic.commands.LogoutCommand;
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.SelectCommand;
import seedu.address.logic.commands.UndoCommand;
import seedu.address.logic.commands.admin.AddAdminCommand;
import seedu.address.logic.commands.admin.LoginCommand;
import seedu.address.logic.commands.admin.LogoutCommand;
import seedu.address.logic.commands.admin.RemoveAdminCommand;
import seedu.address.logic.commands.admin.UpdatePasswordCommand;
import seedu.address.logic.commands.machine.AddMachineCommand;
import seedu.address.logic.parser.admin.AddAdminCommandParser;
import seedu.address.logic.parser.admin.LoginCommandParser;
import seedu.address.logic.parser.admin.RemoveAdminCommandParser;
import seedu.address.logic.parser.admin.UpdatePasswordCommandParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.logic.parser.machine.AddMachineCommandParser;

Expand Down Expand Up @@ -88,18 +95,23 @@ public Command parseCommand(String userInput) throws ParseException {
case RedoCommand.COMMAND_WORD:
return new RedoCommand();

case LoginCommand.COMMAND_WORD:
return new LoginCommandParser().parse(arguments);

// MakerManager commands below
case LogoutCommand.COMMAND_WORD:
return new LogoutCommand();

case AddMachineCommand.COMMAND_WORD:
return new AddMachineCommandParser().parse(arguments);

case LoginCommand.COMMAND_WORD:
return new LoginCommandParser().parse(arguments);
case AddAdminCommand.COMMAND_WORD:
return new AddAdminCommandParser().parse(arguments);

case LogoutCommand.COMMAND_WORD:
return new LogoutCommand();
case RemoveAdminCommand.COMMAND_WORD:
return new RemoveAdminCommandParser().parse(arguments);

case UpdatePasswordCommand.COMMAND_WORD:
return new UpdatePasswordCommandParser().parse(arguments);

default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
Expand Down

0 comments on commit 9affb07

Please sign in to comment.