Skip to content

Feat/sse tickets#252

Draft
VitraagVigyaan wants to merge 11 commits into
mainfrom
feat/sse-tickets
Draft

Feat/sse tickets#252
VitraagVigyaan wants to merge 11 commits into
mainfrom
feat/sse-tickets

Conversation

@VitraagVigyaan
Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @VitraagVigyaan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a robust, real-time ticket management system to facilitate communication between users and administrators. It provides dedicated API endpoints for creating, viewing, and interacting with support tickets from both client and admin perspectives. The core real-time messaging functionality is powered by Server-Sent Events (SSE), allowing for instant updates as messages are exchanged. New database models (Ticket and TicketMessage) have been added to persistently store ticket information and conversation logs, enhancing the application's support capabilities.

Highlights

  • New Ticket Management System: Introduced a comprehensive system for users to create support tickets and for administrators to manage them, covering the full lifecycle from creation to resolution.
  • Real-time Communication via SSE: Implemented Server-Sent Events (SSE) for real-time streaming of ticket messages between users and administrators, ensuring live updates without constant polling for an interactive support experience.
  • Dedicated API Endpoints: Added new API routes for both client-side ticket creation, viewing, and messaging, and admin-side ticket listing, detail viewing, messaging, and status updates, ensuring clear separation of concerns and secure access.
  • New Database Models: Created Ticket and TicketMessage Sequelize models, along with their associations to the CardDb model, to persistently store ticket data and conversation history in a structured manner.
  • Socket.IO Integration: Included socket.io as a dependency and initialized a Socket.IO server, setting the foundation for potential future real-time admin functionalities, although the primary ticket messaging uses SSE.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new ticketing system with Server-Sent Events (SSE) for real-time message streaming. The implementation includes new models, controllers, routes, and tests. While the feature is well-structured, there are several critical issues that need to be addressed before merging. These include a security vulnerability with permissive CORS settings, use of insufficient randomness for generating unique ticket IDs which could lead to collisions, and several bugs that will cause runtime errors or test failures, such as a missing import and inconsistent API responses. There are also some medium-severity issues related to code cleanliness and maintainability. Additionally, socket.io is introduced but does not appear to be used by the new ticketing feature, which might indicate either incomplete work or dead code.

Comment on lines +16 to +28
await Ticket.create({
id: generateTicketId(),
issued_by: cardno,
service,
description,
os,
app_version
});

res.status(201).send({
message: 'Successfully created ticket'
});
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The API response for this endpoint is inconsistent with the tests and likely the rest of the application. The tests expect a { status: 'success', data: ... } format, but this endpoint returns { message: '...' }. This will cause tests to fail. The created ticket should also be returned in the response. This issue applies to other new endpoints in this file as well.

Suggested change
await Ticket.create({
id: generateTicketId(),
issued_by: cardno,
service,
description,
os,
app_version
});
res.status(201).send({
message: 'Successfully created ticket'
});
};
const newTicket = await Ticket.create({
id: generateTicketId(),
issued_by: cardno,
service,
description,
os,
app_version
});
res.status(201).send({
status: 'success',
data: newTicket
});
};

Comment on lines +136 to +138
res.status(201).send({
message: MSG_UPDATE_SUCCESSFUL
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The API response for this endpoint is inconsistent with the tests. It returns only a message, but the tests expect a response format of { status: 'success', data: ... }, including the newly created message. This will cause tests to fail. The response should be updated to include the status and the new message data.

  res.status(201).send({
    status: 'success',
    message: MSG_UPDATE_SUCCESSFUL,
    data: newMessage
  });

Comment on lines +167 to +169
const generateTicketId = () => {
return crypto.randomBytes(4).toString('hex').toUpperCase();
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The generateTicketId function uses crypto.randomBytes(4), which only provides 32 bits of entropy. This is insufficient for a primary key and creates a significant risk of collisions as the number of tickets grows, potentially leading to data corruption. It is highly recommended to use a more robust method for generating unique IDs, such as crypto.randomUUID().

const generateTicketId = () => {
  return crypto.randomUUID();
};

Comment on lines +2 to +8
import {
createTicket,
getTicketDetails,
addMessage,
resolveTicket,
streamTicketMessages
} from '../../controllers/client/ticket.controller.js';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The getTickets function is used in a route on line 17, but it is not imported from the controller. This will cause a ReferenceError at runtime.

Suggested change
import {
createTicket,
getTicketDetails,
addMessage,
resolveTicket,
streamTicketMessages
} from '../../controllers/client/ticket.controller.js';
import {
createTicket,
getTickets,
getTicketDetails,
addMessage,
resolveTicket,
streamTicketMessages
} from '../../controllers/client/ticket.controller.js';

Comment thread config/socket.js
Comment on lines +7 to +10
cors: {
origin: '*', // restrict later if needed
methods: ['GET', 'POST']
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The CORS configuration for socket.io is overly permissive with origin: '*'. This allows any website to connect to your socket.io server, which is a significant security risk. It is strongly recommended to restrict the origin to a specific list of allowed domains.

Suggested change
cors: {
origin: '*', // restrict later if needed
methods: ['GET', 'POST']
}
cors: {
origin: ['https://your-client-app.com', 'https://your-admin-app.com'], // TODO: Replace with actual client domains
methods: ['GET', 'POST']
}

Comment thread config/socket.js
Comment on lines +13 to +23
io.on('connection', socket => {
console.log('Admin connected:', socket.id);

socket.on('join_admin', () => {
socket.join('admins');
});

socket.on('disconnect', () => {
console.log('Disconnected:', socket.id);
});
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

console.log is used for logging. It's better to use the application-wide logger for consistency and to allow for configurable log levels and destinations in different environments. Please import and use the application's logger here.

Suggested change
io.on('connection', socket => {
console.log('Admin connected:', socket.id);
socket.on('join_admin', () => {
socket.join('admins');
});
socket.on('disconnect', () => {
console.log('Disconnected:', socket.id);
});
});
io.on('connection', socket => {
logger.info('Admin connected:', socket.id);
socket.on('join_admin', () => {
socket.join('admins');
});
socket.on('disconnect', () => {
logger.info('Disconnected:', socket.id);
});
});

Comment on lines +12 to +29
// export const getAllTickets = async (req, res) => {
// const { status, service } = req.query;
// const where = {};

// if (status) where.status = status;
// if (service) where.service = service;

// const tickets = await Ticket.findAll({
// where,
// order: [['createdAt', 'DESC']]
// });

// res.status(200).json({
// status: 'success',
// message: MSG_FETCH_SUCCESSFUL,
// data: tickets
// });
// };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This large block of commented-out code should be removed. Version control history can be used to track previous implementations if needed, and removing dead code keeps the codebase clean and easier to maintain.

Comment thread models/ticket.model.js
},
status: {
type: DataTypes.ENUM,
values: [STATUS_OPEN, STATUS_INPROGRESS, 'resolved', STATUS_CLOSED],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The status 'resolved' is hardcoded in the ENUM values. For better maintainability and consistency, it should be defined as a constant (e.g., STATUS_RESOLVED) in config/constants.js and imported here, similar to the other status values.

Suggested change
values: [STATUS_OPEN, STATUS_INPROGRESS, 'resolved', STATUS_CLOSED],
values: [STATUS_OPEN, STATUS_INPROGRESS, STATUS_RESOLVED, STATUS_CLOSED],

…r handling by removing disconnected clients on write failure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants