Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.base
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ FEATURE__MATOMO_INTEGRATION=false
FEATURE__WORDPRESS_INTEGRATION=false
FEATURE__WIKI_INTEGRATION=false
FEATURE__DISCOURSE_INTEGRATION=false
FEATURE__AUTO_APPROVE_GROUPS=false
FEATURE__AUTO_APPROVE_EVENTS=false

# =============================================================================
# LOGGING CONFIGURATION
Expand Down
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ FEATURE__MATOMO_INTEGRATION="$FEATURE__MATOMO_INTEGRATION"
FEATURE__WORDPRESS_INTEGRATION="$FEATURE__WORDPRESS_INTEGRATION"
FEATURE__WIKI_INTEGRATION="$FEATURE__WIKI_INTEGRATION"
FEATURE__DISCOURSE_INTEGRATION="$FEATURE__DISCOURSE_INTEGRATION"
FEATURE__AUTO_APPROVE_GROUPS="$FEATURE__AUTO_APPROVE_GROUPS"
FEATURE__AUTO_APPROVE_EVENTS="$FEATURE__AUTO_APPROVE_EVENTS"

# =============================================================================
# LOGGING CONFIGURATION
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/API/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,9 @@ public function createEventv2(Request $request): JsonResponse
}
}

if ($autoapprove) {
Log::info("Auto-approve event $idParty");
// Only auto-approve if the feature is enabled AND the user has privileged role (Root, Admin, Host)
if ($autoapprove && $user->role <= ROLE::HOST) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably right, but funky lol. I would have assumed ROOT was a higher level than HOST. But I'm assuming they are just numbers starting with 1 for highest permission.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I'm assuming they are just numbers starting with 1 for highest permission.

Correct

const ROOT = 1;
const ADMINISTRATOR = 2;
const HOST = 3;
const RESTARTER = 4;
const GUSET = 5;
const NETWORK_COORDINATOR = 6;

Log::info("Auto-approve event $idParty for user {$user->id} (role {$user->role})");
Party::find($idParty)->approve();
}

Expand Down
30 changes: 24 additions & 6 deletions app/Http/Controllers/API/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Illuminate\Auth\AuthenticationException;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Notification;
use Illuminate\Validation\ValidationException;

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

// Notify relevant admins.
$notify_admins = Fixometer::usersWhoHavePreference('admin-moderate-group');
Notification::send($notify_admins, new AdminModerationGroup([
'group_name' => $name,
'group_url' => url('/group/edit/'.$idGroup),
]));
// Check if groups should be auto-approved
if (env('FEATURE__AUTO_APPROVE_GROUPS', false) && $user->role <= ROLE::RESTARTER) {
// Auto-approve the group
$group->update(['approved' => true]);

// Fire the approval event
event(new \App\Events\ApproveGroup($group, $data));

// Notify the creator that their group was approved
Notification::send($user, new \App\Notifications\GroupConfirmed([
'group_name' => $name,
'group_url' => url('/group/view/'.$idGroup),
]));

Log::info("Auto-approved group: $idGroup for user {$user->id} (role {$user->role})");
} else {
// Notify relevant admins for moderation.
$notify_admins = Fixometer::usersWhoHavePreference('admin-moderate-group');
Notification::send($notify_admins, new AdminModerationGroup([
'group_name' => $name,
'group_url' => url('/group/edit/'.$idGroup),
]));
}

return response()->json([
'id' => $idGroup,
Expand Down
17 changes: 2 additions & 15 deletions app/Models/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,21 +427,8 @@ public function getMaxUpdatedAtDevicesUpdatedAtAttribute()

public function getAutoApproveAttribute()
{
// A group's events are auto-approved iff all the networks that the group belongs to are set to auto-approve
// events.
$autoapprove = false;

$networks = $this->networks;

if ($networks && count($networks)) {
$autoapprove = true;

foreach ($networks as $network) {
$autoapprove &= $network->auto_approve_events;
}
}

return $autoapprove;
// Events are auto-approved based on environment configuration
return env('FEATURE__AUTO_APPROVE_EVENTS', false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If FEATURE__AUTO_APPROVE_EVENTS is false, do we want to keep the previous behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole network feature is similar to multiple instances of Restarters.

We don't really use the Network feature so having to check the group on all networks would not apply for us.

}

public function getDistanceAttribute()
Expand Down
2 changes: 2 additions & 0 deletions charts/restarters/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ envGroups:
FEATURE__WORDPRESS_INTEGRATION: "false"
FEATURE__WIKI_INTEGRATION: "false"
FEATURE__DISCOURSE_INTEGRATION: "false"
FEATURE__AUTO_APPROVE_GROUPS: "false"
FEATURE__AUTO_APPROVE_EVENTS: "false"

# Logging configuration
logging:
Expand Down