deckhearth/components/PermissionIndicator.js
Randall Stillwell b917972f5e 🔄 Simplified Permission Model & UX Improvements
🎯 Cleaner Permission System:
- Collections are private/invite-only by default
- Public toggle only controls community visibility (not edit permissions)
- Simplified to: Creator + Invited Collaborators can edit, everyone else view-only
- Only creator can delete collections

📝 UI/UX Enhancements:
- Changed 'Invite User' to 'Invite Collaborator' with clearer messaging
- Replaced visibility dropdown with clean public/private toggle
- Updated role descriptions: 'Collaborator' (editor) and 'Viewer'
- Default invitation role is now 'editor' (collaborator)
- Added explanatory text about collaboration purpose

🔐 Permission Logic Updates:
- Public collections: visible in community but invite-only editing
- Private collections: hidden from community, invite-only editing
- Removed complex visibility states (invite-only/private distinction)
- Updated permission middleware for simplified model

📧 Email Template Updates:
- Clearer role descriptions in invitation emails
- Focus on collaboration and card management permissions
- Removed owner role from invitation options

🗄️ Database Schema Updates:
- Updated APIs to use is_public boolean instead of visibility enum
- Maintained backward compatibility with existing data
- Simplified permission checking logic

The system now has a much cleaner UX: collections are collaborative workspaces that can optionally be made visible to the community! 🚀
2025-07-25 10:29:45 -05:00

155 lines
5 KiB
JavaScript

import { useState } from 'react';
export default function PermissionIndicator({ userRole, isPublic, showTooltip = true }) {
const [showDetails, setShowDetails] = useState(false);
const getRoleInfo = (role) => {
switch (role) {
case 'owner':
return {
icon: '👑',
label: 'Owner',
color: '#f59e0b',
permissions: ['View', 'Edit', 'Delete', 'Manage Users', 'Change Visibility']
};
case 'editor':
return {
icon: '✏️',
label: 'Editor',
color: '#10b981',
permissions: ['View', 'Edit', 'Add/Remove Cards']
};
case 'viewer':
return {
icon: '👁️',
label: 'Viewer',
color: '#6b7280',
permissions: ['View Only']
};
default:
return {
icon: '🔒',
label: 'No Access',
color: '#ef4444',
permissions: []
};
}
};
const getVisibilityInfo = (isPublic) => {
if (isPublic) {
return {
icon: '🌍',
label: 'Public',
color: '#10b981',
description: 'Visible in community, invite-only editing'
};
} else {
return {
icon: '🔒',
label: 'Private',
color: '#6b7280',
description: 'Hidden from community, invite-only editing'
};
}
};
const roleInfo = getRoleInfo(userRole);
const visibilityInfo = getVisibilityInfo(isPublic);
return (
<div className="flex items-center space-x-2">
{/* Role Badge */}
{userRole && (
<div className="relative">
<div
className="flex items-center space-x-1 px-2 py-1 rounded-full text-xs font-medium cursor-pointer"
style={{
backgroundColor: `${roleInfo.color}20`,
color: roleInfo.color,
border: `1px solid ${roleInfo.color}40`
}}
onMouseEnter={() => showTooltip && setShowDetails(true)}
onMouseLeave={() => setShowDetails(false)}
>
<span>{roleInfo.icon}</span>
<span>{roleInfo.label}</span>
</div>
{/* Role Tooltip */}
{showDetails && showTooltip && (
<div
className="absolute bottom-full left-0 mb-2 p-3 rounded-lg shadow-lg z-10 min-w-48"
style={{ backgroundColor: 'var(--bg-secondary)', border: '1px solid var(--border)' }}
>
<div className="text-sm font-medium mb-2" style={{ color: 'var(--text-primary)' }}>
{roleInfo.icon} {roleInfo.label} Permissions:
</div>
<ul className="text-xs space-y-1" style={{ color: 'var(--text-secondary)' }}>
{roleInfo.permissions.map((permission, index) => (
<li key={index} className="flex items-center space-x-1">
<span className="text-green-500"></span>
<span>{permission}</span>
</li>
))}
</ul>
</div>
)}
</div>
)}
{/* Visibility Badge */}
{isPublic !== undefined && (
<div className="relative">
<div
className="flex items-center space-x-1 px-2 py-1 rounded-full text-xs font-medium cursor-pointer"
style={{
backgroundColor: `${visibilityInfo.color}20`,
color: visibilityInfo.color,
border: `1px solid ${visibilityInfo.color}40`
}}
onMouseEnter={() => showTooltip && setShowDetails(true)}
onMouseLeave={() => setShowDetails(false)}
>
<span>{visibilityInfo.icon}</span>
<span>{visibilityInfo.label}</span>
</div>
{/* Visibility Tooltip */}
{showDetails && showTooltip && (
<div
className="absolute bottom-full right-0 mb-2 p-3 rounded-lg shadow-lg z-10 min-w-48"
style={{ backgroundColor: 'var(--bg-secondary)', border: '1px solid var(--border)' }}
>
<div className="text-sm font-medium mb-1" style={{ color: 'var(--text-primary)' }}>
{visibilityInfo.icon} {visibilityInfo.label}
</div>
<p className="text-xs" style={{ color: 'var(--text-secondary)' }}>
{visibilityInfo.description}
</p>
</div>
)}
</div>
)}
</div>
);
}
// Utility component for inline permission checks
export function CanEdit({ userRole, children }) {
const canEdit = ['owner', 'editor'].includes(userRole);
return canEdit ? children : null;
}
export function CanManage({ userRole, children }) {
const canManage = userRole === 'owner';
return canManage ? children : null;
}
export function PermissionGate({ userRole, requiredRole, children, fallback = null }) {
const roleHierarchy = { viewer: 1, editor: 2, owner: 3 };
const userLevel = roleHierarchy[userRole] || 0;
const requiredLevel = roleHierarchy[requiredRole] || 0;
return userLevel >= requiredLevel ? children : fallback;
}