mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
Add streaks, scheduled releases, and notification settings
- Couple streaks with milestone notifications - Scheduled pack releases with admin UI - Notification preferences screen - Refactored profile settings screens - Partner activity notifications
This commit is contained in:
1 parent
12f312421b
commit
494ed17fe2
82 files changed
+4189
-725
No files matched your search
@@ -0,0 +1,58 @@
|
||||
|
||||
-- Create a function that admins with gift_premium permission can use to gift premium
|
||||
-- This bypasses RLS issues by using SECURITY DEFINER and checking permissions internally
|
||||
CREATE OR REPLACE FUNCTION admin_gift_premium(
|
||||
target_user_id UUID,
|
||||
expires_at_param TIMESTAMPTZ DEFAULT NULL
|
||||
)
|
||||
RETURNS UUID
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
AS $$
|
||||
DECLARE
|
||||
v_subscription_id UUID;
|
||||
v_caller_role admin_role;
|
||||
v_caller_permissions JSONB;
|
||||
BEGIN
|
||||
-- Check if caller has permission
|
||||
SELECT role, permissions INTO v_caller_role, v_caller_permissions
|
||||
FROM admin_users
|
||||
WHERE user_id = auth.uid();
|
||||
|
||||
-- Must be super_admin OR have gift_premium permission
|
||||
IF v_caller_role IS NULL THEN
|
||||
RAISE EXCEPTION 'Access denied: not an admin user';
|
||||
END IF;
|
||||
|
||||
IF v_caller_role != 'super_admin' AND NOT (v_caller_permissions @> '["gift_premium"]'::jsonb) THEN
|
||||
RAISE EXCEPTION 'Access denied: missing gift_premium permission';
|
||||
END IF;
|
||||
|
||||
-- Insert the subscription
|
||||
INSERT INTO subscriptions (
|
||||
user_id,
|
||||
revenuecat_app_user_id,
|
||||
product_id,
|
||||
status,
|
||||
store,
|
||||
purchased_at,
|
||||
expires_at
|
||||
) VALUES (
|
||||
target_user_id,
|
||||
'admin_grant',
|
||||
'admin_premium',
|
||||
'active',
|
||||
'manual',
|
||||
NOW(),
|
||||
expires_at_param
|
||||
)
|
||||
RETURNING id INTO v_subscription_id;
|
||||
|
||||
RETURN v_subscription_id;
|
||||
END;
|
||||
$$;
|
||||
|
||||
-- Grant execute permission to authenticated users (the function checks permissions internally)
|
||||
GRANT EXECUTE ON FUNCTION admin_gift_premium(UUID, TIMESTAMPTZ) TO authenticated;
|
||||
;
|
||||
Reference in new issue
Block a user