Skip to content

Commit

Permalink
Merge pull request #409 from 51ngul4r1ty/story/000403/vs-code-disconn…
Browse files Browse the repository at this point in the history
…ect-from-atoll

Improvements for VS Code Extension
  • Loading branch information
51ngul4r1ty authored May 3, 2022
2 parents b1853c0 + 2989d17 commit e98efef
Show file tree
Hide file tree
Showing 30 changed files with 191 additions and 171 deletions.
50 changes: 28 additions & 22 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
{
"printWidth": 132,
"singleQuote": false,
"tabWidth": 4,
"useTabs": false,
"trailingComma": "none",
"semi": true,
"arrowParens": "always",
"endOfLine": "auto",
"overrides": [
{
"files": "*.json",
"options": {
"tabWidth": 2
}
},
{
"files": "*.yml",
"options": {
"tabWidth": 2
}
}
]
"printWidth": 132,
"singleQuote": false,
"tabWidth": 4,
"useTabs": false,
"trailingComma": "none",
"semi": true,
"arrowParens": "always",
"endOfLine": "auto",
"overrides": [
{
"files": "*.json",
"options": {
"tabWidth": 2
}
},
{
"files": ".*rc",
"options": {
"tabWidth": 2
}
},
{
"files": "*.yml",
"options": {
"tabWidth": 2
}
}
]
}
7 changes: 2 additions & 5 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"plugins": [
"stylelint-order",
"stylelint-prettier"
],
"plugins": ["stylelint-order", "stylelint-prettier"],
"extends": ["stylelint-prettier/recommended"],
"rules": {
"declaration-block-no-shorthand-property-overrides": [true, { "severity": "warning" } ],
"declaration-block-no-shorthand-property-overrides": [true, { "severity": "warning" }],
"order/properties-alphabetical-order": true,
"color-no-invalid-hex": true,
"font-family-no-duplicate-names": true,
Expand Down
3 changes: 3 additions & 0 deletions atoll-core-main.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
},
{
"path": "../atoll-scripts"
},
{
"path": "../atoll-api-types"
}
],
"settings": {
Expand Down
32 changes: 11 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "atoll",
"version": "0.54.2",
"version": "0.55.0",
"author": {
"name": "Kevin Berry",
"email": "[email protected]"
Expand Down Expand Up @@ -59,7 +59,7 @@
"check:prereqs": "ts-node ./scripts/check-prereqs.ts"
},
"dependencies": {
"@atoll/shared": "0.54.2",
"@atoll/shared": "0.55.0",
"@flopflip/memory-adapter": "1.6.0",
"@flopflip/react-broadcast": "10.1.11",
"axios": "0.26.1",
Expand Down
8 changes: 4 additions & 4 deletions src/server/api/handlers/aggregators/backlogItemAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

// externals
import * as HttpStatus from "http-status-codes";
import { StatusCodes } from "http-status-codes";
import { Transaction } from "sequelize";

// libraries
Expand Down Expand Up @@ -42,15 +42,15 @@ export const fetchBacklogItemWithSprintAllocationInfo = async (
transaction?: Transaction
): Promise<BacklogItemWithSprintAllocationInfoResult | RestApiErrorResult> => {
const backlogItemFetchResult = await fetchBacklogItem(backlogItemId, transaction);
if (backlogItemFetchResult.status === HttpStatus.NOT_FOUND) {
if (backlogItemFetchResult.status === StatusCodes.NOT_FOUND) {
return buildNotFoundResponse(backlogItemFetchResult.message);
} else if (isRestApiItemResult(backlogItemFetchResult)) {
const item = backlogItemFetchResult.data.item;
const productBacklogItem = await fetchProductBacklogItemById(backlogItemId, transaction);
let inProductBacklog: boolean;
if (productBacklogItem.status === HttpStatus.OK) {
if (productBacklogItem.status === StatusCodes.OK) {
inProductBacklog = true;
} else if (productBacklogItem.status === HttpStatus.NOT_FOUND) {
} else if (productBacklogItem.status === StatusCodes.NOT_FOUND) {
inProductBacklog = false;
} else {
const error = `Unable to fetch product backlog item by ID ${backlogItemId}: ${productBacklogItem.message}`;
Expand Down
43 changes: 31 additions & 12 deletions src/server/api/handlers/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// externals
import { Request, Response } from "express";
import * as HttpStatus from "http-status-codes";
import { StatusCodes } from "http-status-codes";
import * as jwt from "jsonwebtoken";

// config
Expand All @@ -12,26 +12,31 @@ import { ROLE_USER, RefreshTokenContents } from "../../types";
// utils
import { buildAuthToken, buildRefreshToken } from "../utils/tokenHelper";
import { getSimpleUuid } from "../utils/uuidHelper";
import { buildResponseWithItem } from "../utils/responseBuilder";
import { buildMessageResponse, buildResponseWithItem } from "../utils/responseBuilder";

export const loginPostHandler = async (req: Request, res: Response) => {
const username = req.body?.username;
const password = req.body?.password;
if (!username || !password) {
res.status(HttpStatus.BAD_REQUEST).send("username and password is required");
const messageResponse = buildMessageResponse(StatusCodes.BAD_REQUEST, "username and password is required");
res.status(messageResponse.status).send(messageResponse);
return;
}
const authKey = getAuthKey();
if (!authKey) {
res.status(HttpStatus.INTERNAL_SERVER_ERROR).send("Invalid configuration - auth key has not been set up");
const messageResponse = buildMessageResponse(
StatusCodes.INTERNAL_SERVER_ERROR,
"Invalid configuration - auth key has not been set up"
);
res.status(messageResponse.status).send(messageResponse);
return;
}
// TODO: Query the database to get list of users
if (username === "test" && password === "atoll") {
try {
const refreshTokenId = getSimpleUuid();
res.status(HttpStatus.OK).send({
status: HttpStatus.OK,
res.status(StatusCodes.OK).send({
status: StatusCodes.OK,
data: {
item: {
authToken: buildAuthToken("217796f6e1ab455a980263171099533f", username, ROLE_USER),
Expand All @@ -41,32 +46,42 @@ export const loginPostHandler = async (req: Request, res: Response) => {
});
return;
} catch (err) {
res.status(HttpStatus.INTERNAL_SERVER_ERROR).send("An unknown error occurred while generating an auth token");
const messageResponse = buildMessageResponse(
StatusCodes.INTERNAL_SERVER_ERROR,
"An unknown error occurred while generating an auth token"
);
res.status(messageResponse.status).send(messageResponse);
return;
}
} else {
res.status(HttpStatus.UNAUTHORIZED).send("Either username or password is incorrect");
const messageResponse = buildMessageResponse(StatusCodes.UNAUTHORIZED, "Either username or password is incorrect");
res.status(messageResponse.status).send(messageResponse);
return;
}
};

export const refreshTokenPostHandler = async (req: Request, res: Response) => {
const refreshToken = req.body?.refreshToken;
if (!refreshToken) {
res.status(HttpStatus.BAD_REQUEST).send("refreshToken is required");
const messageResponse = buildMessageResponse(StatusCodes.BAD_REQUEST, "refreshToken is required");
res.status(messageResponse.status).send(messageResponse);
return;
}
const authKey = getAuthKey();
if (!authKey) {
res.status(HttpStatus.INTERNAL_SERVER_ERROR).send("Invalid configuration - auth key has not been set up");
const messageResponse = buildMessageResponse(
StatusCodes.INTERNAL_SERVER_ERROR,
"Invalid configuration - auth key has not been set up"
);
res.status(messageResponse.status).send(messageResponse);
return;
}
try {
let decoded: RefreshTokenContents;
try {
decoded = jwt.verify(refreshToken, authKey) as RefreshTokenContents;
} catch (ex) {
return res.status(HttpStatus.FORBIDDEN).send("Invalid refresh token.");
return res.status(StatusCodes.FORBIDDEN).send("Invalid refresh token.");
}

const responseWithItem = buildResponseWithItem({
Expand All @@ -77,7 +92,11 @@ export const refreshTokenPostHandler = async (req: Request, res: Response) => {

return;
} catch (err) {
res.status(HttpStatus.INTERNAL_SERVER_ERROR).send("An unknown error occurred while generating an auth token");
const messageResponse = buildMessageResponse(
StatusCodes.INTERNAL_SERVER_ERROR,
"An unknown error occurred while generating an auth token"
);
res.status(messageResponse.status).send(messageResponse);
return;
}
};
10 changes: 5 additions & 5 deletions src/server/api/handlers/backlogItems.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// externals
import { Request, Response } from "express";
import * as core from "express-serve-static-core";
import * as HttpStatus from "http-status-codes";
import { StatusCodes } from "http-status-codes";
import { CreateOptions, FindOptions, Transaction } from "sequelize";

// libraries
Expand Down Expand Up @@ -77,7 +77,7 @@ export const backlogItemsGetHandler = async (req: Request, res: Response) => {
} else {
result = await fetchBacklogItems(params.projectId);
}
if (result.status === HttpStatus.OK) {
if (result.status === StatusCodes.OK) {
res.json(result);
} else {
res.status(result.status).json({
Expand Down Expand Up @@ -267,7 +267,7 @@ export const backlogItemsPostHandler = async (req: Request, res: Response) => {
await productBacklogItemFirstItemInserter(newItem, transaction);
} else {
const result = await productBacklogItemSubsequentItemInserter(newItem, transaction, prevBacklogItemId);
if (result.status !== HttpStatus.OK) {
if (result.status !== StatusCodes.OK) {
respondWithFailedValidation(res, result.message);
}
rolledBack = result.rolledBack;
Expand All @@ -293,8 +293,8 @@ export const backlogItemsPostHandler = async (req: Request, res: Response) => {
}
if (!rolledBack) {
await transaction.commit();
res.status(HttpStatus.CREATED).json({
status: HttpStatus.CREATED,
res.status(StatusCodes.CREATED).json({
status: StatusCodes.CREATED,
data: {
item: addedBacklogItem
}
Expand Down
10 changes: 5 additions & 5 deletions src/server/api/handlers/deleters/backlogItemPartDeleter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// externals
import * as HttpStatus from "http-status-codes";
import { StatusCodes } from "http-status-codes";
import { FindOptions, Transaction } from "sequelize";

// data access
Expand Down Expand Up @@ -37,7 +37,7 @@ export const removeUnallocatedBacklogItemPart = async (
const item = await BacklogItemPartDataModel.findOne(findItemOptions);
if (!item) {
return {
status: HttpStatus.NOT_FOUND,
status: StatusCodes.NOT_FOUND,
message: `Backlog item part "${backlogItemPartId}" was not found`
};
}
Expand All @@ -59,13 +59,13 @@ export const removeUnallocatedBacklogItemPart = async (
if (!peerItems.length) {
if (lastPartRemovalOptions === LastPartRemovalOptions.Disallow) {
return {
status: HttpStatus.BAD_REQUEST,
status: StatusCodes.BAD_REQUEST,
message: `Backlog Item Part removal resulted in last part with ID "${backlogItemPartId}" being removed`
};
}
if (!backlogItem) {
return {
status: HttpStatus.INTERNAL_SERVER_ERROR,
status: StatusCodes.INTERNAL_SERVER_ERROR,
message:
`After removing last backlog item part with ID "${backlogItemPartId}"` +
` unable to find backlog item with ID "${item.backlogitemId}"`
Expand All @@ -74,7 +74,7 @@ export const removeUnallocatedBacklogItemPart = async (
let backlogItemData = mapDbToApiBacklogItem(item);
await dbBacklogItem.destroy({ transaction });
return {
status: HttpStatus.OK,
status: StatusCodes.OK,
data: {
item: itemData
},
Expand Down
Loading

0 comments on commit e98efef

Please sign in to comment.