Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin management #12

Merged
merged 49 commits into from
Sep 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c01b5f1
Add login Command
Psyf Sep 23, 2018
a8a7319
Add stub test for LoginCommand
Psyf Sep 23, 2018
cf987d4
LoginCommand takes args
Psyf Sep 23, 2018
824857b
move to proper classes in LoginCommand
Psyf Sep 23, 2018
80f0e5e
Add equality and hashCode to new models
Psyf Sep 24, 2018
c4c4d6f
Add equality to LoginCommand
Psyf Sep 24, 2018
1e6d8ac
Rename PasswordHash to Password; Add to LoginCommandTest
Psyf Sep 24, 2018
a2cb936
Modify tests, add more test stub for TODO
Psyf Sep 24, 2018
1b20e22
Add LogoutCommand stubs
Psyf Sep 24, 2018
c331ade
Add UniqueAdminList and relevant Exceptions
Psyf Sep 25, 2018
e3b745a
Add test stubs
Psyf Sep 25, 2018
866c0ff
Add remove method in UniqueAdminList
Psyf Sep 25, 2018
b8fce7b
Edit AddressBook.java to include Admin#methods
Psyf Sep 25, 2018
a6c42f4
Add model#methods and edit LoginCommand
Psyf Sep 25, 2018
1cebf39
Make changes to LogoutCommand#execute
Psyf Sep 25, 2018
5eefadc
Add initial admin to AB
Psyf Sep 25, 2018
20d617a
Fix LoginCommandParser bug
Psyf Sep 25, 2018
de9f239
Try fix Travis errors
Psyf Sep 25, 2018
702f768
Style fix
Psyf Sep 25, 2018
fd7cbef
Style fix...again
Psyf Sep 25, 2018
d8b278a
Style fix...again
Psyf Sep 25, 2018
4bac37f
Style check...again
Psyf Sep 25, 2018
512130a
Merge branch 'admin_access' into refact-classes
Psyf Sep 28, 2018
1827efa
Merge branch 'refact-classes'
Psyf Sep 28, 2018
219ad6b
Merge remote-tracking branch 'upstream/master'
Psyf Sep 29, 2018
d5aefd3
Added addAdmin Command; working in memory
Psyf Sep 28, 2018
0781bdb
Update docs
Psyf Sep 28, 2018
9175196
Some work towards removeAdmin
Psyf Sep 28, 2018
82c58ce
removeAdmin working as expected
Psyf Sep 28, 2018
4187bcd
addAdmin does not allow duplicate usernames
Psyf Sep 28, 2018
f3610ba
Style fixes
Psyf Sep 28, 2018
0c2ad56
Add UpdatePasswordCommand()
Psyf Sep 28, 2018
e47557f
Update Parsers for UpdatePasswordCommand
Psyf Sep 28, 2018
6317af9
UpdatePassword working correctly
Psyf Sep 28, 2018
dc87689
Make RemoveAdmin less primitive
Psyf Sep 28, 2018
d787a7e
Add Comment
Psyf Sep 28, 2018
e38d8fc
Work on XmlAdaptedAdmin
Psyf Sep 28, 2018
0016143
Modify XmlSerializableAddressBook.java
Psyf Sep 28, 2018
f017c32
make necessary modifications to UniqueAdminList
Psyf Sep 28, 2018
7c070df
Attempt (failed) at fileStorage
Psyf Sep 28, 2018
63fa393
Fix Merge bugs
Psyf Sep 29, 2018
6638bf0
Refactor code in command+parser
Psyf Sep 29, 2018
e9dd03a
Major refactoring for AdminStorage, renamings for machineStorage: WIP…
Psyf Sep 29, 2018
2926d7a
Verify AdminStorage works standalone; fixed typo
Psyf Sep 29, 2018
afb70a1
Fix Travis Errors
Psyf Sep 29, 2018
2f3b189
Fix Travis Errors
Psyf Sep 29, 2018
400b8f0
Fix issues in tests
Psyf Sep 29, 2018
457f2f3
Fix style issues in test
Psyf Sep 29, 2018
51018ac
Modify ModelClassDiagram
Psyf Sep 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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