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

Implemented the changes I made in Project 1 #6

Open
wants to merge 4 commits into
base: f24
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ NodeBB by itself contains a "common core" of basic functionality, while addition

### [Try it now](//try.nodebb.org) | [Documentation](//docs.nodebb.org)

### Team Members
+ Abdallah Almana [email protected]
+ Abdulwahab Al-Rumaihi [email protected]
+ Hiba Hamad [email protected]
+ Najoud Al-Talib [email protected]
+ Reem Kensouh [email protected]

## Screenshots

NodeBB's theming engine is highly flexible and does not restrict your design choices. Check out some themed installs in these screenshots below:
Expand Down
25 changes: 15 additions & 10 deletions src/api/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,8 @@ postsAPI.getRaw = async (caller, { pid }) => {
return result.postData.content;
};

postsAPI.edit = async function (caller, data) {
if (!data || !data.pid || (meta.config.minimumPostLength !== 0 && !data.content)) {
throw new Error('[[error:invalid-data]]');
}
if (!caller.uid) {
throw new Error('[[error:not-logged-in]]');
}
// Trim and remove HTML (latter for composers that send in HTML, like redactor)
const contentLen = utils.stripHTMLTags(data.content).trim().length;

// Added code to lower cognitive complexity below, Procos12
async function validatePost(data, meta, contentLen, caller) {
if (data.title && data.title.length < meta.config.minimumTitleLength) {
throw new Error(`[[error:title-too-short, ${meta.config.minimumTitleLength}]]`);
} else if (data.title && data.title.length > meta.config.maximumTitleLength) {
Expand All @@ -104,6 +96,19 @@ postsAPI.edit = async function (caller, data) {
} else if (!await posts.canUserPostContentWithLinks(caller.uid, data.content)) {
throw new Error(`[[error:not-enough-reputation-to-post-links, ${meta.config['min:rep:post-links']}]]`);
}
}

postsAPI.edit = async function (caller, data) {
if (!data || !data.pid || (meta.config.minimumPostLength !== 0 && !data.content)) {
throw new Error('[[error:invalid-data]]');
}
if (!caller.uid) {
throw new Error('[[error:not-logged-in]]');
}
// Trim and remove HTML (latter for composers that send in HTML, like redactor)
const contentLen = utils.stripHTMLTags(data.content).trim().length;

await validatePost(data, meta, contentLen, caller);

data.uid = caller.uid;
data.req = apiHelpers.buildReqObject(caller);
Expand Down