mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
Refactor profile screen and organize project structure
- Extract ProfileScreen and components to features/profile - Move shared hooks and stores to top-level - Add RLS policies for admin permissions - Add RELEASING.md guide - Update .gitignore
This commit is contained in:
1 parent
df4c4d486b
commit
8f8c6e401d
79 files changed
+6689
-4944
No files matched your search
@@ -0,0 +1,59 @@
|
||||
-- Function to check for specific permission
|
||||
CREATE OR REPLACE FUNCTION has_permission(check_permission TEXT)
|
||||
RETURNS BOOLEAN
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = 'public'
|
||||
AS $$
|
||||
DECLARE
|
||||
v_role admin_role;
|
||||
v_permissions JSONB;
|
||||
BEGIN
|
||||
SELECT role, permissions INTO v_role, v_permissions
|
||||
FROM public.admin_users
|
||||
WHERE user_id = auth.uid();
|
||||
|
||||
IF v_role IS NULL THEN
|
||||
RETURN FALSE;
|
||||
END IF;
|
||||
|
||||
IF v_role = 'super_admin' THEN
|
||||
RETURN TRUE;
|
||||
END IF;
|
||||
|
||||
-- Check if permissions array contains the required permission
|
||||
-- Using the @> operator to check if the JSON array contains the value
|
||||
IF v_permissions IS NULL THEN
|
||||
RETURN FALSE;
|
||||
END IF;
|
||||
|
||||
RETURN v_permissions @> jsonb_build_array(check_permission);
|
||||
END;
|
||||
$$;
|
||||
|
||||
-- Update RLS policies to use permissions
|
||||
|
||||
-- Profiles
|
||||
CREATE POLICY "Admins with view_users permission can view all profiles"
|
||||
ON profiles FOR SELECT
|
||||
USING (has_permission('view_users'));
|
||||
|
||||
-- Messages
|
||||
CREATE POLICY "Admins with view_chats permission can view all messages"
|
||||
ON messages FOR SELECT
|
||||
USING (has_permission('view_chats'));
|
||||
|
||||
-- Responses
|
||||
CREATE POLICY "Admins with view_responses permission can view all responses"
|
||||
ON responses FOR SELECT
|
||||
USING (has_permission('view_responses'));
|
||||
|
||||
-- Matches
|
||||
CREATE POLICY "Admins with view_matches permission can view all matches"
|
||||
ON matches FOR SELECT
|
||||
USING (has_permission('view_matches'));
|
||||
|
||||
-- Audit Logs
|
||||
CREATE POLICY "Admins with view_audit_logs permission can view audit logs"
|
||||
ON audit_logs FOR SELECT
|
||||
USING (has_permission('view_audit_logs'));
|
||||
@@ -0,0 +1,9 @@
|
||||
-- Add RLS policies for feedback
|
||||
|
||||
CREATE POLICY "Admins with manage_feedback permission can view all feedback"
|
||||
ON feedback FOR SELECT
|
||||
USING (has_permission('manage_feedback'));
|
||||
|
||||
CREATE POLICY "Admins with manage_feedback permission can update all feedback"
|
||||
ON feedback FOR UPDATE
|
||||
USING (has_permission('manage_feedback'));
|
||||
@@ -0,0 +1,17 @@
|
||||
-- Add RLS policies for redemption codes
|
||||
|
||||
CREATE POLICY "Admins with manage_codes permission can view redemption codes"
|
||||
ON redemption_codes FOR SELECT
|
||||
USING (has_permission('manage_codes'));
|
||||
|
||||
CREATE POLICY "Admins with manage_codes permission can insert redemption codes"
|
||||
ON redemption_codes FOR INSERT
|
||||
WITH CHECK (has_permission('manage_codes'));
|
||||
|
||||
CREATE POLICY "Admins with manage_codes permission can update redemption codes"
|
||||
ON redemption_codes FOR UPDATE
|
||||
USING (has_permission('manage_codes'));
|
||||
|
||||
CREATE POLICY "Admins with manage_codes permission can delete redemption codes"
|
||||
ON redemption_codes FOR DELETE
|
||||
USING (has_permission('manage_codes'));
|
||||
Reference in new issue
Block a user