Skip to content

Commit

Permalink
Merge 742ee6b into f1bdb1e
Browse files Browse the repository at this point in the history
  • Loading branch information
xllx1 committed Nov 2, 2018
2 parents f1bdb1e + 742ee6b commit f8a828e
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 79 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ asciidoctor {
idprefix: '', // for compatibility with GitHub preview
idseparator: '-',
'site-root': "${sourceDir}", // must be the same as sourceDir, do not modify
'site-name': 'AddressBook-Level4',
'site-githuburl': 'https://github.com/se-edu/addressbook-level4',
'site-seedu': true, // delete this line if your project is not a fork (not a SE-EDU project)
'site-name': 'ForumBook',
'site-githuburl': 'https://github.com/CS2113-AY1819S1-T13-2/main',
]

options['template_dirs'].each {
Expand Down
35 changes: 19 additions & 16 deletions docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,25 @@ These instructions only provide a starting point for testers to work on; testers
.. Re-launch the app by double-clicking the jar file. +
Expected: The most recent window size and location is retained.


=== Registering and logging in

. Registering a new user

.. Prerequisites: username must not be registered before.
.. Test case: `addUser uName/john uPass/123`
Expected: the user `john` will be added to the UserStorage if there is no duplicate in the UserStorage.

. Loggin in

.. Test case: `login uName/abcd uPass/123`
Expected: Log in with a random username and password that has not been registered. An error message will be shown in the result display panel.
.. Test case: `login uName/john uPass/234`
Expected: Log in with a registered username and a wrong password. An error message will be shown in the result display panel.
.. Test case: `login uName/john uPass/123`
Expected: Log in with a registered username and correct password, a success message will be shown in the result display panel.


=== Announcing new announcement

. Announcing a new announcement by admin.
Expand Down Expand Up @@ -945,20 +964,4 @@ These instructions only provide a starting point for testers to work on; testers

.. _{explain how to simulate a missing/corrupted file and the expected behavior}_

_{ more test cases ... }_

=== Login

. Login test

.. Log in with a random User Name and Password that has not been registered.
.. Log in with a registered user name and a random Password.
.. Log in with a registered user name and password, then log in to the same or other account.

. AddUser test

.. Register a user. Once successful, register the same user again.



_{ more test cases ... }_
58 changes: 30 additions & 28 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ifdef::env-github[]
:tip-caption: :bulb:
:note-caption: :information_source:
endif::[]
:repoURL:https://github.com/CS2113-AY1819S1-T13-2
:repoURL:https://github.com/CS2113-AY1819S1-T13-2/main/

By: `Team CS2113-AY1819S1-T13-2` Since: `Aug 2018` Licence: `MIT`

Expand Down Expand Up @@ -165,7 +165,7 @@ Examples:

* `updateThread tId/123 tTitle/This is a new title`

=== Updating a comment title : `updateComment`
=== Updating a comment content : `updateComment`

Update an existing comment title in the forum book. +
Format: `updateComment cId/COMMENT ID cContent/NEW COMMENT CONTENT`
Expand Down Expand Up @@ -206,7 +206,7 @@ Examples:

=== Announcing new command : `announce`

Announce the new announcement created by admin. +
Announce the new announcement created by admin. The first character of announcement title and content must not be a whitespace. +
Format: `announce aTitle/ANNOUNCEMENT_TITLE aContent/ANNOUNCEMENT_CONTENT`

Example:
Expand All @@ -218,18 +218,20 @@ Example:
Check for the latest announcement. +
Format: `checkAnnounce`

=== Blocking a user from creating thread or comment : `block`
=== Blocking a user from creating thread or comment : `blockUser`

Block a specific user that match the given argument by admin. +
Format: `block uName/USER_NAME`
Block a specific user that match the given argument by admin. `block` only takes `true` or `false` +
Format: `blockUser uName/USER_NAME block/BLOCK_OR_UNBLOCK`

Example:

* `block uName/john`
* `blockUser uName/john block/true`

* `blockUser uName/john block/false`

=== Setting a user as admin or revert an admin to user : `setAdmin`

Set a user as an admin or revert an admin to user. +
Set a user as an admin or revert an admin to user. `set` only takes `true` or `false` +
Format: `setAdmin uName/USER_NAME set/SET_OR_REVERT`

Examples:
Expand All @@ -240,7 +242,7 @@ Examples:

=== Creating a new module : `createModule`

Create a new module by admin. +
Create a new module by admin. Module code should follow (2 or 3 capital letters) + (4 numbers) + (0 or 1 capital letter) and it should not be blank. E.g. MA1580E, CS2113 or USP1000A, USP1000. Module title should only contain letters and spaces.+
Format: `createModule mCode/MODULE_CODE mTitle/MODULE_TITLE`

Example:
Expand Down Expand Up @@ -296,22 +298,11 @@ There is no need to save manually.
*A*: Install the app in the other computer and overwrite the empty data file it creates with the file that contains the data of your previous Forum Book folder.`

== Command Summary
* *Announce* : `announce aTitle/ANNOUNCEMENT_TITLE aContent/ANNOUNCEMENT_CONTENT` +
e.g `announce aTitle/Urgent! aContent/System maintenance from 4pm to 5pm.`
* *CheckAnnounce* : `checkAnnounce`
* *Block* : `block uName/USER_NAME` +
e.g `block uName/john`
* *SetAdmin* : `setAdmin uName/USER_NAME set/SET_OR_REVERT` +
e.g `setAdmin uName/john set/true`
* *CreateModule* : `createModule mCode/MODULE_CODE mTitle/MODULE_TITLE` +
e.g `createModule mCode/CS2113 mTitle/Software Engineering and OOP`
* *DeleteModule* : `deleteModule mCode/MODULE_CODE` +
e.g `deleteModule mCode/CS2113`
* *UpdatePass* : `updatePass uName/USER_NAME uPass/USER_PASSWORD` +
e.g `updatePass uName/john uPass/098`
* *DeleteUser* : `deleteUser uName/USER_NAME` +
e.g `deleteUser uName/john`
* *Help*: `help`
* *RegisterUser* : `addUser uName/USER NAME uPass/USER PASSWORD` +
e.g `addUser uName/MyName uPass/password`
* *Login* : `login uName/USER NAME uPass/USER PASSWORD` +
e.g `login uName/MyName uPass/password`
* *createThread* : `createThread mCode/MODULE CODE tTitle/THREAD TITLE cContent/COMMENT CONTENT` +
e.g `createThread mCode/CS2113 tTitle/Exam Information cContent/All the best for the final guys`
* *createComment* : `createComment tId/THREAD ID cContent/COMMENT CONTENT` +
Expand All @@ -329,8 +320,19 @@ e.g `deleteComment cId/1`
e.g `selectModule mCode/CS2113`
* *selectThread* : `selectThread tId/THREAD ID` +
e.g `selectThread tId/123`
* *RegisterUser* : `addUser uName/USER NAME uPass/USER PASSWORD` +
e.g `addUser uName/MyName uPass/password`
* *Login* : `login uName/USER NAME uPass/USER PASSWORD` +
e.g `login uName/MyName uPass/password`
* *Announce* : `announce aTitle/ANNOUNCEMENT_TITLE aContent/ANNOUNCEMENT_CONTENT` +
e.g `announce aTitle/Urgent! aContent/System maintenance from 4pm to 5pm.`
* *CheckAnnounce* : `checkAnnounce`
* *Block* : `block uName/USER_NAME` +
e.g `block uName/john`
* *SetAdmin* : `setAdmin uName/USER_NAME set/SET_OR_REVERT` +
e.g `setAdmin uName/john set/true`
* *CreateModule* : `createModule mCode/MODULE_CODE mTitle/MODULE_TITLE` +
e.g `createModule mCode/CS2113 mTitle/Software Engineering and OOP`
* *DeleteModule* : `deleteModule mCode/MODULE_CODE` +
e.g `deleteModule mCode/CS2113`
* *UpdatePass* : `updatePass uName/USER_NAME uPass/USER_PASSWORD` +
e.g `updatePass uName/john uPass/098`
* *DeleteUser* : `deleteUser uName/USER_NAME` +
e.g `deleteUser uName/john`
* *Logout* : `logout`
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AdminUpdatePasswordCommand extends Command {
+ PREFIX_USER_PASSWORD + "456";

public static final String MESSAGE_SUCCESS = "Password for %1$s is now %2$s";
public static final String MESSAGE_INVALID_USER = "No user named %1$s found. Please try again!";
public static final String MESSAGE_INVALID_USER = "No user named \"%1$s\" found. Please try again!";


private final String userNameToUpdate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class BlockUserFromCreatingCommand extends Command {
public static final String MESSAGE_INVALID_USER = "The user \"%s\" does not exist.";
public static final String MESSAGE_DUPLICATE_BLOCK = "The user \"%s\" has already been blocked.";
public static final String MESSAGE_DUPLICATE_UNBLOCK = "The user \"%s\" has not been block.";
public static final String MESSAGE_BLOCK_NAME_CONSTRAINTS = "uName cannot be null.";
public static final String MESSAGE_BLOCK_CONSTRAINTS = "block can only take true or false.";

private final String userNameToBlock;
private final boolean block;
Expand Down Expand Up @@ -63,7 +65,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
if (user.isAdmin()) {
throw new CommandException(String.format(MESSAGE_USER_IS_ADMIN, userNameToBlock));
} else if (block && user.isBlock()) {
throw new CommandException(String.format(MESSAGE_DUPLICATE_UNBLOCK, userNameToBlock));
throw new CommandException(String.format(MESSAGE_DUPLICATE_BLOCK, userNameToBlock));
} else if (!block && !user.isBlock()) {
throw new CommandException(String.format(MESSAGE_DUPLICATE_UNBLOCK, userNameToBlock));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SetAdminCommand extends Command {
public static final String MESSAGE_INVALID_USER = "The user \"%1$s\" does not exist.";
public static final String MESSAGE_DUPLICATE_SET = "The user \"%1$s\" is already an admin.";
public static final String MESSAGE_DUPLICATE_REVERT = "%1$s is not an admin, unable to revert.";
public static final String MESSAGE_SET_CONSTRAINTS = "set can only take true or false.";

private final String userNametoSetAdmin;
private final boolean setAdmin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.util.stream.Stream;

import com.t13g2.forum.commons.core.Messages;
import com.t13g2.forum.logic.commands.BlockUserFromCreatingCommand;
import com.t13g2.forum.logic.parser.exceptions.ParseException;

Expand All @@ -25,8 +24,7 @@ public BlockUserFromCreatingCommand parse(String args) throws ParseException {
ArgumentTokenizer.tokenize(args, PREFIX_USER_NAME, PREFIX_BLOCK);
if (!arePrefixesPresent(argMultimap, PREFIX_USER_NAME, PREFIX_BLOCK)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT,
BlockUserFromCreatingCommand.MESSAGE_USAGE));
throw new ParseException(BlockUserFromCreatingCommand.MESSAGE_BLOCK_NAME_CONSTRAINTS);
}
String userName = ParserUtil.parseUserName(argMultimap.getValue(PREFIX_USER_NAME).get());
boolean block;
Expand All @@ -35,8 +33,7 @@ public BlockUserFromCreatingCommand parse(String args) throws ParseException {
} else if (argMultimap.getValue(PREFIX_BLOCK).get().equals("false")) {
block = false;
} else {
throw new ParseException(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT,
BlockUserFromCreatingCommand.MESSAGE_USAGE));
throw new ParseException(BlockUserFromCreatingCommand.MESSAGE_BLOCK_CONSTRAINTS);
}

return new BlockUserFromCreatingCommand(userName, block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CreateModuleCommand parse(String args) throws ParseException {
CreateModuleCommand.MESSAGE_USAGE));
}

Module module = ParserUtil.parseModule(argMultimap.getValue(PREFIX_MODULE_TITLE).get(),
Module module = ParserUtil.parseModuleCodeAndTitle(argMultimap.getValue(PREFIX_MODULE_TITLE).get(),
argMultimap.getValue(PREFIX_MODULE_CODE).get());

return new CreateModuleCommand(module);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DeleteModuleCommand parse(String args) throws ParseException {
DeleteModuleCommand.MESSAGE_USAGE));
}

String moduleCode = argMultimap.getValue(PREFIX_MODULE_CODE).get();
String moduleCode = ParserUtil.parseModule(argMultimap.getValue(PREFIX_MODULE_CODE).get());

return new DeleteModuleCommand(moduleCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public DeleteUserCommand parse(String args) throws ParseException {
DeleteUserCommand.MESSAGE_USAGE));
}

String userName = argMultimap.getValue(PREFIX_USER_NAME).get();
String userName = ParserUtil.parseUserName(argMultimap.getValue(PREFIX_USER_NAME).get());

return new DeleteUserCommand(userName);
}
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/com/t13g2/forum/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,36 @@ public static Announcement parseAnnouncement(String title, String content) throw
requireNonNull(content);
String trimmedTitle = title.trim();
String trimmedContent = content.trim();
if (!Announcement.isValidAnnouncement(trimmedTitle, trimmedContent)) {
throw new ParseException(Announcement.MESSAGE_ANNOUNCEMENT_CONSTRAINTS);
if (!Announcement.isValidAnnouncement(trimmedTitle)) {
throw new ParseException(Announcement.MESSAGE_ANNOUNCEMENT_TITLE_CONSTRAINTS);
} else if (!Announcement.isValidAnnouncement(trimmedContent)) {
throw new ParseException(Announcement.MESSAGE_ANNOUNCEMENT_CONTENT_CONSTRAINTS);
}
return new Announcement(trimmedTitle, trimmedContent);
}

/**
* Parse {@code }
*/
public static Module parseModule(String moduleTitle, String moduleCode) throws ParseException {
public static Module parseModuleCodeAndTitle(String moduleTitle, String moduleCode) throws ParseException {
requireNonNull(moduleTitle);
requireNonNull(moduleCode);
String trimmedModuleTitle = moduleTitle.trim();
String trimmedModuleCode = moduleCode.trim();
if (!isValidModule(trimmedModuleCode)) {
throw new ParseException(Module.MESSAGE_MODULE_CONSTRAINTS);
throw new ParseException(Module.MESSAGE_MODULE_CODE_CONSTRAINTS);
}
if (!isValidModuleTitle(trimmedModuleTitle)) {
throw new ParseException(Module.MESSAGE_MODULE_TITLE_CONSTRAINTS);
}
return new Module(trimmedModuleTitle, trimmedModuleCode);
}

//Returns true if a given strings is a valid module title.
public static boolean isValidModuleTitle(String trimmedModuleTitle) {
return trimmedModuleTitle.matches(Module.MODULE_TITLE_VALIDATION_REGEX);
}

//@@author HansKoh
/**
* moduleCode
Expand All @@ -190,13 +200,13 @@ public static String parseModule(String module) throws ParseException {
requireNonNull(module);
String trimmedModule = module.trim();
if (!isValidModule(trimmedModule)) {
throw new ParseException(Module.MESSAGE_MODULE_CONSTRAINTS);
throw new ParseException(Module.MESSAGE_MODULE_CODE_CONSTRAINTS);
}
return trimmedModule;
}
//Returns true if a given string is a valid module.
public static boolean isValidModule(String trimmedModule) {
return trimmedModule.matches(Module.MODULE_VALIDATION_REGEX);
return trimmedModule.matches(Module.MODULE_CODE_VALIDATION_REGEX);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ public SetAdminCommand parse(String userInput) throws ParseException {
SetAdminCommand.MESSAGE_USAGE));
}

String userName = argMultimap.getValue(PREFIX_USER_NAME).get();
String userName = ParserUtil.parseUserName(argMultimap.getValue(PREFIX_USER_NAME).get());
boolean setAdmin;
if (argMultimap.getValue(PREFIX_ADMIN_SET).get().equals("true")) {
setAdmin = true;
} else if (argMultimap.getValue(PREFIX_ADMIN_SET).get().equals("false")) {
setAdmin = false;
} else {
throw new ParseException(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT,
SetAdminCommand.MESSAGE_USAGE));
throw new ParseException(SetAdminCommand.MESSAGE_SET_CONSTRAINTS);
}

return new SetAdminCommand(userName, setAdmin);
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/t13g2/forum/model/forum/Announcement.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

/**
* Represents the announcement in ForumBook.
* Guarantees: is valid as declared in {@link #isValidAnnouncement(String, String)}
* Guarantees: is valid as declared in {@link #isValidAnnouncement(String)}
*/
public class Announcement extends BaseModel {
/**
* Show message if announcement is not valid
*/
public static final String MESSAGE_ANNOUNCEMENT_CONSTRAINTS =
"Announcement can take any values, and it should not be blank";
public static final String MESSAGE_ANNOUNCEMENT_TITLE_CONSTRAINTS =
"aTitle can take any values, and they should not be blank";
public static final String MESSAGE_ANNOUNCEMENT_CONTENT_CONSTRAINTS =
"aContent can take any values, and they should not be blank";

/**
* The first character of the announcement must not be a whitespace,
Expand All @@ -30,16 +32,17 @@ public Announcement() {
*/
public Announcement(String title, String content) {
CollectionUtil.requireAllNonNull(title, content);
AppUtil.checkArgument(isValidAnnouncement(title, content), MESSAGE_ANNOUNCEMENT_CONSTRAINTS);
AppUtil.checkArgument(isValidAnnouncement(title), MESSAGE_ANNOUNCEMENT_TITLE_CONSTRAINTS);
AppUtil.checkArgument(isValidAnnouncement(content), MESSAGE_ANNOUNCEMENT_CONTENT_CONSTRAINTS);
this.title = title;
this.content = content;
}

/**
* Returns true if a given string is a valid email.
*/
public static boolean isValidAnnouncement(String testTitle, String testContent) {
return (testTitle.matches(ANNOUNCEMENT_VALIDATION_REGEX) || testContent.matches(ANNOUNCEMENT_VALIDATION_REGEX));
public static boolean isValidAnnouncement(String testString) {
return (testString.matches(ANNOUNCEMENT_VALIDATION_REGEX));
}

public String getTitle() {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/t13g2/forum/model/forum/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
* Represents module in ForumBook
*/
public class Module extends BaseModel {
public static final String MESSAGE_MODULE_CONSTRAINTS =
"Module code should only contain alphanumeric characters and spaces, and it should not be blank";
public static final String MODULE_VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";
public static final String MESSAGE_MODULE_CODE_CONSTRAINTS =
"mCode should follow (2 or 3 capital letters)+(4 numbers)+(0 or 1 capital letter)"
+ "\nand it should not be blank. E.g. MA1580E, CS2113 or USP1000A, USP1000";
public static final String MESSAGE_MODULE_TITLE_CONSTRAINTS =
"mTitle should only contain spaces and letters, and it should not be blank";
public static final String MODULE_CODE_VALIDATION_REGEX = "[A-Z]{2,3}[0-9]{4}[A-Z]{0,1}";
public static final String MODULE_TITLE_VALIDATION_REGEX = "^[ A-Za-z]+$l";

private String title;
private String moduleCode;
Expand Down

0 comments on commit f8a828e

Please sign in to comment.