Clean up unused permissions, take user to first page/component they can access
This commit is contained in:
@@ -2,10 +2,14 @@ CREATE TABLE users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR(255) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
email VARCHAR UNIQUE,
|
||||
is_admin BOOLEAN DEFAULT FALSE,
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
last_login TIMESTAMP WITH TIME ZONE,
|
||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
-- Function to update the updated_at timestamp
|
||||
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
||||
RETURNS TRIGGER AS $$
|
||||
@@ -18,14 +22,6 @@ $$ language 'plpgsql';
|
||||
-- Sequence and defined type for users table if not exists
|
||||
CREATE SEQUENCE IF NOT EXISTS users_id_seq;
|
||||
|
||||
-- Update users table with new fields
|
||||
ALTER TABLE "public"."users"
|
||||
ADD COLUMN IF NOT EXISTS "email" varchar UNIQUE,
|
||||
ADD COLUMN IF NOT EXISTS "is_admin" boolean DEFAULT FALSE,
|
||||
ADD COLUMN IF NOT EXISTS "is_active" boolean DEFAULT TRUE,
|
||||
ADD COLUMN IF NOT EXISTS "last_login" timestamp with time zone,
|
||||
ADD COLUMN IF NOT EXISTS "updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP;
|
||||
|
||||
-- Create permissions table
|
||||
CREATE TABLE IF NOT EXISTS "public"."permissions" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
@@ -58,8 +54,7 @@ CREATE TRIGGER update_permissions_updated_at
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_updated_at_column();
|
||||
|
||||
-- Insert default permissions by page
|
||||
-- Core page access permissions
|
||||
-- Insert default permissions by page - only the ones used in application
|
||||
INSERT INTO permissions (name, code, description, category) VALUES
|
||||
('Dashboard Access', 'access:dashboard', 'Can access the Dashboard page', 'Pages'),
|
||||
('Products Access', 'access:products', 'Can access the Products page', 'Pages'),
|
||||
@@ -73,52 +68,14 @@ INSERT INTO permissions (name, code, description, category) VALUES
|
||||
('AI Validation Debug Access', 'access:ai_validation_debug', 'Can access the AI Validation Debug page', 'Pages')
|
||||
ON CONFLICT (code) DO NOTHING;
|
||||
|
||||
-- Granular permissions for Products
|
||||
INSERT INTO permissions (name, code, description, category) VALUES
|
||||
('View Products', 'view:products', 'Can view product listings', 'Products'),
|
||||
('Create Products', 'create:products', 'Can create new products', 'Products'),
|
||||
('Edit Products', 'edit:products', 'Can edit product details', 'Products'),
|
||||
('Delete Products', 'delete:products', 'Can delete products', 'Products')
|
||||
ON CONFLICT (code) DO NOTHING;
|
||||
|
||||
-- Granular permissions for Categories
|
||||
INSERT INTO permissions (name, code, description, category) VALUES
|
||||
('View Categories', 'view:categories', 'Can view categories', 'Categories'),
|
||||
('Create Categories', 'create:categories', 'Can create new categories', 'Categories'),
|
||||
('Edit Categories', 'edit:categories', 'Can edit categories', 'Categories'),
|
||||
('Delete Categories', 'delete:categories', 'Can delete categories', 'Categories')
|
||||
ON CONFLICT (code) DO NOTHING;
|
||||
|
||||
-- Granular permissions for Vendors
|
||||
INSERT INTO permissions (name, code, description, category) VALUES
|
||||
('View Vendors', 'view:vendors', 'Can view vendors', 'Vendors'),
|
||||
('Create Vendors', 'create:vendors', 'Can create new vendors', 'Vendors'),
|
||||
('Edit Vendors', 'edit:vendors', 'Can edit vendors', 'Vendors'),
|
||||
('Delete Vendors', 'delete:vendors', 'Can delete vendors', 'Vendors')
|
||||
ON CONFLICT (code) DO NOTHING;
|
||||
|
||||
-- Granular permissions for Purchase Orders
|
||||
INSERT INTO permissions (name, code, description, category) VALUES
|
||||
('View Purchase Orders', 'view:purchase_orders', 'Can view purchase orders', 'Purchase Orders'),
|
||||
('Create Purchase Orders', 'create:purchase_orders', 'Can create new purchase orders', 'Purchase Orders'),
|
||||
('Edit Purchase Orders', 'edit:purchase_orders', 'Can edit purchase orders', 'Purchase Orders'),
|
||||
('Delete Purchase Orders', 'delete:purchase_orders', 'Can delete purchase orders', 'Purchase Orders')
|
||||
ON CONFLICT (code) DO NOTHING;
|
||||
|
||||
-- User management permissions
|
||||
INSERT INTO permissions (name, code, description, category) VALUES
|
||||
('View Users', 'view:users', 'Can view user accounts', 'Users'),
|
||||
('Create Users', 'create:users', 'Can create user accounts', 'Users'),
|
||||
('Edit Users', 'edit:users', 'Can modify user accounts', 'Users'),
|
||||
('Delete Users', 'delete:users', 'Can delete user accounts', 'Users'),
|
||||
('Manage Permissions', 'manage:permissions', 'Can assign permissions to users', 'Users')
|
||||
ON CONFLICT (code) DO NOTHING;
|
||||
|
||||
-- System permissions
|
||||
-- Settings section permissions
|
||||
INSERT INTO permissions (name, code, description, category) VALUES
|
||||
('Run Calculations', 'run:calculations', 'Can trigger system calculations', 'System'),
|
||||
('Import Data', 'import:data', 'Can import data into the system', 'System'),
|
||||
('System Settings', 'edit:system_settings', 'Can modify system settings', 'System')
|
||||
('Data Management', 'settings:data_management', 'Access to the Data Management settings section', 'Settings'),
|
||||
('Stock Management', 'settings:stock_management', 'Access to the Stock Management settings section', 'Settings'),
|
||||
('Performance Metrics', 'settings:performance_metrics', 'Access to the Performance Metrics settings section', 'Settings'),
|
||||
('Calculation Settings', 'settings:calculation_settings', 'Access to the Calculation Settings section', 'Settings'),
|
||||
('Template Management', 'settings:templates', 'Access to the Template Management settings section', 'Settings'),
|
||||
('User Management', 'settings:user_management', 'Access to the User Management settings section', 'Settings')
|
||||
ON CONFLICT (code) DO NOTHING;
|
||||
|
||||
-- Set any existing users as admin
|
||||
|
||||
Reference in New Issue
Block a user