Sindbad~EG File Manager
-- ====================================================================
-- CREATE TEST USERS FOR ACCESS CONTROL TESTING
-- Run this SQL to create test accounts at each access level
-- ====================================================================
-- Password for all test users: Test@2025
-- 1. ASSEMBLY ADMIN TEST USER
-- Can see only their specific assembly
INSERT INTO users (
username,
email,
password_hash,
full_name,
access_level,
area_id,
district_id,
assembly_id,
is_superuser,
is_active
) VALUES (
'assembly_admin',
'assembly.admin@test.com',
'$2y$10$YourHashedPasswordHere', -- Replace with actual hash for Test@2025
'Assembly Admin Test',
'assembly',
(SELECT id FROM areas LIMIT 1), -- Get first area
(SELECT id FROM districts LIMIT 1), -- Get first district
(SELECT id FROM assemblies LIMIT 1), -- Get first assembly
0,
1
);
-- 2. DISTRICT ADMIN TEST USER
-- Can see all assemblies in their district
INSERT INTO users (
username,
email,
password_hash,
full_name,
access_level,
area_id,
district_id,
assembly_id,
is_superuser,
is_active
) VALUES (
'district_admin',
'district.admin@test.com',
'$2y$10$YourHashedPasswordHere', -- Replace with actual hash for Test@2025
'District Admin Test',
'district',
(SELECT id FROM areas LIMIT 1), -- Get first area
(SELECT id FROM districts LIMIT 1), -- Get first district
NULL, -- District admin not tied to specific assembly
0,
1
);
-- 3. AREA ADMIN TEST USER
-- Can see all districts and assemblies in their area
INSERT INTO users (
username,
email,
password_hash,
full_name,
access_level,
area_id,
district_id,
assembly_id,
is_superuser,
is_active
) VALUES (
'area_admin',
'area.admin@test.com',
'$2y$10$YourHashedPasswordHere', -- Replace with actual hash for Test@2025
'Area Admin Test',
'area',
(SELECT id FROM areas LIMIT 1), -- Get first area
NULL, -- Area admin not tied to specific district
NULL, -- Area admin not tied to specific assembly
0,
1
);
-- 4. VERIFY EXISTING SUPERUSER
-- Superusers should already exist, but verify
SELECT
id,
username,
email,
full_name,
access_level,
is_superuser,
area_id,
district_id,
assembly_id
FROM users
WHERE is_superuser = 1 OR access_level = 'superuser';
-- ====================================================================
-- ALTERNATIVE: Create users with PHP password_hash
-- ====================================================================
-- Run this PHP script separately to generate proper password hashes:
--
-- <?php
-- require_once 'config/config.php';
--
-- $db = Database::getInstance()->getConnection();
-- $password = 'Test@2025';
-- $hash = password_hash($password, PASSWORD_BCRYPT);
--
-- // Assembly Admin
-- $stmt = $db->prepare("
-- INSERT INTO users (username, email, password_hash, full_name, access_level,
-- area_id, district_id, assembly_id, is_superuser, is_active)
-- SELECT 'assembly_admin', 'assembly.admin@test.com', :hash, 'Assembly Admin Test',
-- 'assembly', a.id, d.id, asm.id, 0, 1
-- FROM areas a
-- CROSS JOIN districts d
-- CROSS JOIN assemblies asm
-- LIMIT 1
-- ");
-- $stmt->execute(['hash' => $hash]);
--
-- // District Admin
-- $stmt = $db->prepare("
-- INSERT INTO users (username, email, password_hash, full_name, access_level,
-- area_id, district_id, assembly_id, is_superuser, is_active)
-- SELECT 'district_admin', 'district.admin@test.com', :hash, 'District Admin Test',
-- 'district', a.id, d.id, NULL, 0, 1
-- FROM areas a
-- CROSS JOIN districts d
-- LIMIT 1
-- ");
-- $stmt->execute(['hash' => $hash]);
--
-- // Area Admin
-- $stmt = $db->prepare("
-- INSERT INTO users (username, email, password_hash, full_name, access_level,
-- area_id, district_id, assembly_id, is_superuser, is_active)
-- SELECT 'area_admin', 'area.admin@test.com', :hash, 'Area Admin Test',
-- 'area', a.id, NULL, NULL, 0, 1
-- FROM areas a
-- LIMIT 1
-- ");
-- $stmt->execute(['hash' => $hash]);
--
-- echo "Test users created successfully!";
-- ?>
-- ====================================================================
-- VERIFICATION QUERIES
-- ====================================================================
-- Check all users and their access levels
SELECT
id,
username,
email,
full_name,
access_level,
is_superuser,
CASE
WHEN is_superuser = 1 THEN 'ALL'
WHEN area_id IS NOT NULL AND district_id IS NULL THEN CONCAT('Area: ', (SELECT area_name FROM areas WHERE id = users.area_id))
WHEN district_id IS NOT NULL AND assembly_id IS NULL THEN CONCAT('District: ', (SELECT district_name FROM districts WHERE id = users.district_id))
WHEN assembly_id IS NOT NULL THEN CONCAT('Assembly: ', (SELECT assembly_name FROM assemblies WHERE id = users.assembly_id))
ELSE 'No Scope'
END as access_scope,
is_active
FROM users
ORDER BY
CASE access_level
WHEN 'superuser' THEN 1
WHEN 'area' THEN 2
WHEN 'district' THEN 3
WHEN 'assembly' THEN 4
ELSE 5
END;
-- ====================================================================
-- TEST DATA DISTRIBUTION
-- Show data distribution across locations
-- ====================================================================
-- Members per Assembly
SELECT
a.assembly_name,
d.district_name,
ar.area_name,
COUNT(m.id) as member_count
FROM assemblies a
LEFT JOIN districts d ON a.district_id = d.id
LEFT JOIN areas ar ON d.area_id = ar.id
LEFT JOIN members m ON m.assembly_id = a.id
GROUP BY a.id, d.id, ar.id
ORDER BY ar.area_name, d.district_name, a.assembly_name;
-- Events per Assembly
SELECT
a.assembly_name,
d.district_name,
COUNT(e.id) as event_count
FROM assemblies a
LEFT JOIN districts d ON a.district_id = d.id
LEFT JOIN events e ON e.assembly_id = a.id
GROUP BY a.id, d.id
ORDER BY d.district_name, a.assembly_name;
-- Programs per Assembly
SELECT
a.assembly_name,
d.district_name,
COUNT(p.id) as program_count
FROM assemblies a
LEFT JOIN districts d ON a.district_id = d.id
LEFT JOIN programs p ON p.assembly_id = a.id
GROUP BY a.id, d.id
ORDER BY d.district_name, a.assembly_name;
-- ====================================================================
-- CLEANUP (if needed)
-- Run this to remove test users
-- ====================================================================
-- DELETE FROM users WHERE username IN ('assembly_admin', 'district_admin', 'area_admin');
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists