Skip to content

Commit

Permalink
Trim icon name. Filter private bookmarks if user is not authenticated
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelmalak committed Nov 12, 2021
1 parent d94a6ce commit 6281994
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion controllers/apps/createApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const createApp = asyncWrapper(async (req, res, next) => {
const { pinAppsByDefault } = await loadConfig();

let app;
let _body = { ...req.body };
let _body = { ...req.body, icon: req.body.icon.trim() };

if (req.file) {
_body.icon = req.file.filename;
Expand Down
4 changes: 4 additions & 0 deletions controllers/apps/updateApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const updateApp = asyncWrapper(async (req, res, next) => {

let _body = { ...req.body };

if (_body.icon) {
_body.icon = _body.icon.trim();
}

if (req.file) {
_body.icon = req.file.filename;
}
Expand Down
4 changes: 4 additions & 0 deletions controllers/bookmarks/createBookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const createBookmark = asyncWrapper(async (req, res, next) => {
categoryId: parseInt(req.body.categoryId),
};

if (_body.icon) {
_body.icon = _body.icon.trim();
}

if (req.file) {
_body.icon = req.file.filename;
}
Expand Down
4 changes: 4 additions & 0 deletions controllers/bookmarks/updateBookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const updateBookmark = asyncWrapper(async (req, res, next) => {
categoryId: parseInt(req.body.categoryId),
};

if (_body.icon) {
_body.icon = _body.icon.trim();
}

if (req.file) {
_body.icon = req.file.filename;
}
Expand Down
16 changes: 13 additions & 3 deletions controllers/categories/getAllCategories.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const getAllCategories = asyncWrapper(async (req, res, next) => {
const { useOrdering: orderType } = await loadConfig();

let categories;
let output;

// categories visibility
const where = req.isAuthenticated ? {} : { isPublic: true };
Expand All @@ -21,7 +22,6 @@ const getAllCategories = asyncWrapper(async (req, res, next) => {
{
model: Bookmark,
as: 'bookmarks',
where,
},
],
order: [[Sequelize.fn('lower', Sequelize.col('Category.name')), 'ASC']],
Expand All @@ -33,17 +33,27 @@ const getAllCategories = asyncWrapper(async (req, res, next) => {
{
model: Bookmark,
as: 'bookmarks',
where,
},
],
order: [[orderType, 'ASC']],
where,
});
}

if (req.isAuthenticated) {
output = categories;
} else {
// filter out private bookmarks
output = categories.map((c) => c.get({ plain: true }));
output = output.map((c) => ({
...c,
bookmarks: c.bookmarks.filter((b) => b.isPublic),
}));
}

res.status(200).json({
success: true,
data: categories,
data: output,
});
});

Expand Down

0 comments on commit 6281994

Please sign in to comment.