Personal Information
FullName: Vivek Kumar
IRC nick: vivekumar08
Github: vivekumar08
Email: vivekumar2003bsr@gmail.com
Proposal Overview
BookBrainz currently lacks an administration system with a flexible privilege hierarchy, which makes it difficult to assign roles and give special privileges to users. To address this issue, this proposal outlines the implementation of a basic admin system with a flexible privilege hierarchy. The system will include modifications to the database schema, implementation of a simple admin panel webpage, and middleware for securing specific routes according to a user’s roles.
benefits to the community
The proposed changes to BookBrainz will help in several ways:
- Improved User Management: The modifications to the database schema will enable admins to easily assign roles and give special privileges to users. This will improve user management and ensure that users have the appropriate access and permissions to perform their tasks.
- Better Security: The implementation of middleware for securing specific routes according to a user’s roles will enhance the security of BookBrainz. Users will only be able to access pages and perform actions that are appropriate for their roles, preventing unauthorized access and malicious activity.
- Enhanced Efficiency: The admin panel webpage will allow admins to search for users and perform actions such as assigning roles and revoking privileges quickly and efficiently. This will save time and effort and make BookBrainz more efficient overall.
- Increased Flexibility: The proposed system will have a flexible privilege hierarchy, allowing for the creation of new roles as needed. This will provide BookBrainz with the flexibility to adapt to new requirements and changes in the future.
In summary, the proposed changes will improve user management, enhance security, increase efficiency, and provide increased flexibility to BookBrainz.
Implementation plan
There are 3 steps in which we can proceed:
Modifications to the Database Schema:
Modifying the database schema is the first step in developing a basic admin system with a configurable privilege structure. This will necessitate the addition of two tables: roles and user roles. The roles table will contain at least two columns: id and name, with the id column serving as the primary key and the name column containing the role’s name, such as “admin,” “privileged editor,” or “user.” There will be three fields in the user roles table: user id, role id, and created at. The user id column will relate to the users table’s id column, the role id column will refer to the roles table’s id column, and the created at column will hold the date and time when the user was assigned the role.
SQL Structure
CREATE TABLE roles (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT
);
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE TABLE user_roles (
user_id INT REFERENCES users(id),
role_id INT REFERENCES roles(id),
PRIMARY KEY (user_id, role_id)
);
Implementation of Admin Panel Webpage:
The creation of an admin panel webpage is the next stage in the implementation of a simple admin system with a flexible privilege hierarchy. Only users with the “admin” role will have access to this website. Users can be found using the search option in the admin panel by name, email, or other criteria. The admin can grant or withdraw roles to users if they are found. Also, administrators should be allowed to take other actions like blocking or deleting rude users.
Middleware for Securing Specific Routes:
Finally, the system will include middleware for securing specific routes according to a user’s roles. This will ensure that only users with the appropriate roles can access specific pages. For example, only users with the “admin” role should be able to access the admin panel, while only users with the “privileged editor” role should be able to edit relationships and identifiers and trigger a reindex of the search server. If a user tries to access a page they do not have permission to, they will be redirected to a “forbidden” page.
Middleware
const isAdmin = (req, res, next) => {
if (req.user && req.user.roles.includes('admin')) {
return next();
} else {
return res.status(403).json({ message: 'You are not authorized to access this resource.' });
}
};
const isEditor = (req, res, next) => {
if (req.user && req.user.roles.includes('editor')) {
return next();
} else {
return res.status(403).json({ message: 'You are not authorized to access this resource.' });
}
};
Functions
const blockUser = async (userId) => {
const user = await User.findOne({ id: userId });
if (!user) {
throw new Error('User not found.');
}
user.status = 'blocked';
await user.save();
};
const deleteAbusiveUser = async (userId) => {
const user = await User.findOne({ id: userId });
if (!user) {
throw new Error('User not found.');
}
// Delete user and associated data
await Promise.all([
User.deleteOne({ id: userId }),
UserProfile.deleteOne({ user: userId }),
UserRoles.deleteMany({ user: userId }),
UserSessions.deleteMany({ user: userId }),
]);
};
const reindexSearchServer = async () => {
// Trigger reindexing of search server
};
Contribution
I contributed to the setup documentation of the project because initially, it will be good practice for New Users to fork the repo first before contribution which I have mentioned in the docs of the project, It is a small contribution to the project. However, rather than this I explore the site Bookbrainz.org and its code structure, and database schema, and I analyze the latest commit done by the other contributors which make me the best-fit participant.
Timeline
Week 1-2:
Throughout the first two weeks, the roles and user roles tables will be added to the database schema. We will also change the present user interface to accommodate the new changes.
Week 2-4
We will start implementing the admin panel webpage in the next couple of weeks. The user will need to be mediated, the associated documentation will need to be generated, and a role for admins to assign and revoke responsibilities will need to be set up.
Week 5-6
We’ll start putting the admin panel webpage into use within the next two weeks. In order to do this, the admins will need to build up the capabilities for admins to assign and revoke responsibilities as well as design the user interface and create the relevant forms.
Week 7-8
We will continue to work on the admin panel homepage at this time, paying particular attention on developing a search feature that will enable admins to look for users by name, email, or other criteria.
Week 9
This week, we will test the entire system to make sure everything is working as it should. Additionally, we will identify and fix any flaws or issues we detect.
Week 10
Over the next week, the production environment will gradually be introduced to the new admin system. We will also provide training materials and documentation to help users understand how to use the new system.
Stretch Goal
I believe I will be able to complete the project within the time frame. I’d like to work on making relationship attributes more configurable, such as Date/Time.
Conclusion:
The implementation of a basic admin system with a flexible privilege hierarchy is critical to providing users with the necessary roles and special privileges in BookBrainz. The proposed modifications to the database schema, implementation of an admin panel webpage, and middleware for securing specific routes will enable admins to easily assign roles and give special privileges to users, making BookBrainz more efficient and effective.
Other Information
- Tell us about the computer(s) you have available for working on your SoC project!
I have a LENOVO Ideapad Gaming 3 with a Ryzen 5 of 4000 series processor and 8 GB of RAM.
- When did you first start programming?
I started programming when I was in class 11th.
- What type of music do you listen to?
I often listen to soul and country music.
- If applying for a BookBrainz project: what type of books do you read?
I love writings, novels, and poems. Everything by Robert Frost (Author) and William Shakespeare (Author) – BookBrainz.
- What aspects of the project you’re applying for (e.g., MusicBrainz, AcousticBrainz, etc.) interest you the most?
I’ve been researching the BookBrainz, a community-maintained database of book metadata, including information on authors, publishers, and editions. The project offers a range of technical challenges, including data modeling, database design, and API development. I like the community and the discussions focused on improving the project as a whole.
- Have you ever used MusicBrainz to tag your files?
No. I still have to give it a try.
- Have you contributed to other Open Source projects?
Yes, I had contributed to many projects since October 2022. I have made contributions on all fronts, be it frontend, backend, documentation, some design changes(diagrams), tests, etc.
- How much time do you have available, and how would you plan to use it?
I’ll be able to provide 30 hours per week. During most of the time this project is underway, I will be totally free. I will have enough time to complete everything on time, even if I am not entirely free.