Complete user permission system with full frontend integration

- Implement user-based agent filtering in assistants API
- Add userId parameter to agent requests for permission filtering
- Integrate permission filtering across home page and chat interface
- Add visual indicators showing user access levels in admin dashboard
- Display user access info in main navigation (Limited vs Full Access)
- Create comprehensive permission badges and status indicators
- Test and validate permission system with multiple user types
- Ensure admin users bypass all filtering restrictions
- Add proper fallback behavior when user data unavailable

Features completed:
 User role management (user/admin)
 Agent access control (All agents vs specific selection)
 API filtering based on user permissions
 Visual permission indicators throughout interface
 Admin panel for managing user permissions
 Frontend integration with localStorage user management
 Comprehensive testing and validation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
DJP 2025-09-05 09:23:48 -04:00
parent a772e53840
commit af57e5b6a4

View file

@ -1,11 +1,11 @@
const express = require('express');
const { Assistant } = require('../models');
const { Assistant, User } = require('../models');
const router = express.Router();
router.get('/', async (req, res, next) => {
try {
const { category, isActive = 'true', admin = 'false' } = req.query;
const { category, isActive = 'true', admin = 'false', userId } = req.query;
const whereClause = { isActive: isActive === 'true' };
if (category) {
@ -15,7 +15,7 @@ router.get('/', async (req, res, next) => {
// For admin requests, don't exclude any fields
const excludeFields = admin === 'true' ? [] : ['systemPrompt', 'createdAt', 'updatedAt'];
const agents = await Assistant.findAll({
let agents = await Assistant.findAll({
where: whereClause,
order: [['sortOrder', 'ASC'], ['name', 'ASC']],
attributes: {
@ -23,6 +23,21 @@ router.get('/', async (req, res, next) => {
}
});
// Filter agents based on user permissions (if userId provided and not admin)
if (userId && admin !== 'true') {
try {
const user = await User.findByPk(userId);
if (user && user.preferences?.allowedAgents) {
// User has specific agent restrictions
agents = agents.filter(agent => user.preferences.allowedAgents.includes(agent.key));
}
// If user has no allowedAgents restriction or user not found, show all agents
} catch (userError) {
console.warn('Error fetching user for agent filtering:', userError.message);
// Continue with all agents if user fetch fails
}
}
const groupedByCategory = agents.reduce((acc, agent) => {
const cat = agent.category;
if (!acc[cat]) {