Skip to content

Commit afdda02

Browse files
authored
Merge pull request #38 from iFixit/feat--add-auto-approve-env-vars
Feature: Add Auto-Approve Env Vars for Group and Event Creation
2 parents 4c725c5 + dd2aeda commit afdda02

6 files changed

Lines changed: 35 additions & 23 deletions

File tree

.env.base

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ FEATURE__MATOMO_INTEGRATION=false
2626
FEATURE__WORDPRESS_INTEGRATION=false
2727
FEATURE__WIKI_INTEGRATION=false
2828
FEATURE__DISCOURSE_INTEGRATION=false
29+
FEATURE__AUTO_APPROVE_GROUPS=false
30+
FEATURE__AUTO_APPROVE_EVENTS=false
2931

3032
# =============================================================================
3133
# LOGGING CONFIGURATION

.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ FEATURE__MATOMO_INTEGRATION="$FEATURE__MATOMO_INTEGRATION"
2626
FEATURE__WORDPRESS_INTEGRATION="$FEATURE__WORDPRESS_INTEGRATION"
2727
FEATURE__WIKI_INTEGRATION="$FEATURE__WIKI_INTEGRATION"
2828
FEATURE__DISCOURSE_INTEGRATION="$FEATURE__DISCOURSE_INTEGRATION"
29+
FEATURE__AUTO_APPROVE_GROUPS="$FEATURE__AUTO_APPROVE_GROUPS"
30+
FEATURE__AUTO_APPROVE_EVENTS="$FEATURE__AUTO_APPROVE_EVENTS"
2931

3032
# =============================================================================
3133
# LOGGING CONFIGURATION

app/Http/Controllers/API/EventController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,9 @@ public function createEventv2(Request $request): JsonResponse
543543
}
544544
}
545545

546-
if ($autoapprove) {
547-
Log::info("Auto-approve event $idParty");
546+
// Only auto-approve if the feature is enabled AND the user has privileged role (Root, Admin, Host)
547+
if ($autoapprove && $user->role <= ROLE::HOST) {
548+
Log::info("Auto-approve event $idParty for user {$user->id} (role {$user->role})");
548549
Party::find($idParty)->approve();
549550
}
550551

app/Http/Controllers/API/GroupController.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Illuminate\Auth\AuthenticationException;
2828
use Illuminate\Database\QueryException;
2929
use Illuminate\Http\Request;
30+
use Illuminate\Support\Facades\Log;
3031
use Notification;
3132
use Illuminate\Validation\ValidationException;
3233

@@ -867,12 +868,29 @@ public function createGroupv2(Request $request): JsonResponse {
867868
$file->upload('image', 'image', $idGroup, env('TBL_GROUPS'), false, true, true);
868869
}
869870

870-
// Notify relevant admins.
871-
$notify_admins = Fixometer::usersWhoHavePreference('admin-moderate-group');
872-
Notification::send($notify_admins, new AdminModerationGroup([
873-
'group_name' => $name,
874-
'group_url' => url('/group/edit/'.$idGroup),
875-
]));
871+
// Check if groups should be auto-approved
872+
if (env('FEATURE__AUTO_APPROVE_GROUPS', false) && $user->role <= ROLE::RESTARTER) {
873+
// Auto-approve the group
874+
$group->update(['approved' => true]);
875+
876+
// Fire the approval event
877+
event(new \App\Events\ApproveGroup($group, $data));
878+
879+
// Notify the creator that their group was approved
880+
Notification::send($user, new \App\Notifications\GroupConfirmed([
881+
'group_name' => $name,
882+
'group_url' => url('/group/view/'.$idGroup),
883+
]));
884+
885+
Log::info("Auto-approved group: $idGroup for user {$user->id} (role {$user->role})");
886+
} else {
887+
// Notify relevant admins for moderation.
888+
$notify_admins = Fixometer::usersWhoHavePreference('admin-moderate-group');
889+
Notification::send($notify_admins, new AdminModerationGroup([
890+
'group_name' => $name,
891+
'group_url' => url('/group/edit/'.$idGroup),
892+
]));
893+
}
876894

877895
return response()->json([
878896
'id' => $idGroup,

app/Models/Group.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -427,21 +427,8 @@ public function getMaxUpdatedAtDevicesUpdatedAtAttribute()
427427

428428
public function getAutoApproveAttribute()
429429
{
430-
// A group's events are auto-approved iff all the networks that the group belongs to are set to auto-approve
431-
// events.
432-
$autoapprove = false;
433-
434-
$networks = $this->networks;
435-
436-
if ($networks && count($networks)) {
437-
$autoapprove = true;
438-
439-
foreach ($networks as $network) {
440-
$autoapprove &= $network->auto_approve_events;
441-
}
442-
}
443-
444-
return $autoapprove;
430+
// Events are auto-approved based on environment configuration
431+
return env('FEATURE__AUTO_APPROVE_EVENTS', false);
445432
}
446433

447434
public function getDistanceAttribute()

charts/restarters/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ envGroups:
233233
FEATURE__WORDPRESS_INTEGRATION: "false"
234234
FEATURE__WIKI_INTEGRATION: "false"
235235
FEATURE__DISCOURSE_INTEGRATION: "false"
236+
FEATURE__AUTO_APPROVE_GROUPS: "false"
237+
FEATURE__AUTO_APPROVE_EVENTS: "false"
236238

237239
# Logging configuration
238240
logging:

0 commit comments

Comments
 (0)