mirror of
https://codeberg.org/likwid/likwid.git
synced 2026-06-25 15:37:42 +00:00
Verified changes: - rename backend/.sqlx/query-92461256ad7b62764b2bd75674ccbfc11df6648d6d856e3e68fc80801457c555.json -> backend/.sqlx/query-277e2cb84c2809b3077e36083e61a348d439578815db96969d524ccbb3f83816.json - delete backend/.sqlx/query-3d9153f242fa24637d71a4b4f0a76edee15892248acb6b281ffdbab11a4bff0f.json - add backend/.sqlx/query-683446d56fc5fbb31800fda950adf0e80fcb3769fc4e32c396ac246b038eb6d1.json - add backend/.sqlx/query-6a09254b2c257b9d281177cc012b9e85aab46b843ce5b58720743463051227fe.json - add backend/.sqlx/query-6f4895e8ee8fd91b4266d36e0e60088e54e843b17af24b6f7381831b179bef40.json - add backend/.sqlx/query-7704c0adfa1399b3f95db1fff2f8b83ac7c10efcff1ff52da930c72c71cac614.json - rename backend/.sqlx/query-a903d88370faa52169ffd4ec6a54a789ee4a6173fe84aca0ef8dedaa46b1f93c.json -> backend/.sqlx/query-786d22de6313d554e95069d020362b4880f40187cb022d94126df9ced0f3f162.json - delete backend/.sqlx/query-957b131c5ae23e306fe4634db068c611122ae61057c805c82413fb69ed015c58.json - rename backend/.sqlx/query-cc97b910b8afcfd348d5fe69f7e75862ddd7e31680e46a61170a467b64cdf547.json -> backend/.sqlx/query-ca0137d7aa900603770ccc69ef628d6505fea09a24414d34141691f032e1f8f2.json - add backend/.sqlx/query-fbd1e5ae4d4bf826df698eed56170cbb980e205b8d7ac4e27409f807680c7034.json - add backend/migrations/20260215211500_approve_community_defaults.sql - modify backend/src/api/communities.rs - modify backend/src/api/settings.rs - modify frontend/src/pages/admin/settings.astro - modify frontend/src/pages/communities/[slug]/settings.astro Diffstat: - 15 files changed, 416 insertions(+), 114 deletions(-)
57 lines
1.8 KiB
PL/PgSQL
57 lines
1.8 KiB
PL/PgSQL
-- Ensure approved communities inherit instance defaults
|
|
-- Applies instance default visibility and initializes community_settings with instance defaults
|
|
|
|
CREATE OR REPLACE FUNCTION approve_community(
|
|
p_pending_id UUID,
|
|
p_reviewer_id UUID
|
|
) RETURNS UUID AS $$
|
|
DECLARE
|
|
v_pending pending_communities%ROWTYPE;
|
|
v_community_id UUID;
|
|
v_default_visibility VARCHAR(20);
|
|
v_default_plugin_policy VARCHAR(20);
|
|
v_default_moderation_mode VARCHAR(20);
|
|
BEGIN
|
|
-- Get pending community
|
|
SELECT * INTO v_pending FROM pending_communities WHERE id = p_pending_id AND status = 'pending';
|
|
IF NOT FOUND THEN
|
|
RAISE EXCEPTION 'Pending community not found or already processed';
|
|
END IF;
|
|
|
|
SELECT default_community_visibility,
|
|
default_plugin_policy,
|
|
default_moderation_mode
|
|
INTO v_default_visibility,
|
|
v_default_plugin_policy,
|
|
v_default_moderation_mode
|
|
FROM instance_settings
|
|
LIMIT 1;
|
|
|
|
-- Create the community
|
|
INSERT INTO communities (name, slug, description, settings, created_by, is_active)
|
|
VALUES (
|
|
v_pending.name,
|
|
v_pending.slug,
|
|
v_pending.description,
|
|
jsonb_build_object('visibility', v_default_visibility),
|
|
v_pending.requested_by,
|
|
true
|
|
)
|
|
RETURNING id INTO v_community_id;
|
|
|
|
-- Add requester as admin
|
|
INSERT INTO community_members (community_id, user_id, role)
|
|
VALUES (v_community_id, v_pending.requested_by, 'admin');
|
|
|
|
INSERT INTO community_settings (community_id, moderation_mode, plugin_policy)
|
|
VALUES (v_community_id, v_default_moderation_mode, v_default_plugin_policy)
|
|
ON CONFLICT DO NOTHING;
|
|
|
|
-- Mark as approved
|
|
UPDATE pending_communities
|
|
SET status = 'approved', reviewed_by = p_reviewer_id, reviewed_at = NOW()
|
|
WHERE id = p_pending_id;
|
|
|
|
RETURN v_community_id;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|