Skip to content

Commit

Permalink
Merge pull request #685 from TheRestartProject/RES-1936_sentry
Browse files Browse the repository at this point in the history
RES-1936 sentry
  • Loading branch information
edwh authored Dec 19, 2023
2 parents 7e64c29 + e1133d0 commit d2b9322
Show file tree
Hide file tree
Showing 64 changed files with 225 additions and 772 deletions.
126 changes: 0 additions & 126 deletions app/Console/Commands/AssignDataVolunteeringSkill.php

This file was deleted.

11 changes: 10 additions & 1 deletion app/Console/Commands/CheckTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public function handle()
// We want to scan all English translations.
$files = scandir(base_path() . '/lang/en');

$count = 0;

foreach ($files as $file) {
if ($file == '_json.php') {
// This is a special case used for data from the DB. Ignore it.
Expand All @@ -65,13 +67,17 @@ public function handle()
foreach (['fr-BE', 'fr'] as $other) {
// First we want to check if the translation is used in the code. If it's not, then we
// will want to remove it and it doesn't matter if it is not translated properly.
if (!$this->usedInCode("$group.$key")) {
if (strpos("$group.$key", 'groups.tag-') === 0) {
// This is valid - it's used in a constructed way.
} else if (!$this->usedInCode("$group.$key")) {
error_log("ERROR: translation key $group.$key not used in code so far as we can tell");
$count++;
} else if (!\Lang::has("$group.$key", $other, false)) {
// This is an error. If the translated value would be different, then we need to translate
// it. If it would be the same, then the code would work using fallbacks, but we translate
// it anyway so that this check doesn't give errors.
error_log("ERROR: translation key $group.$key not translated into $other, in English: $value");
$count++;
} else {
// Occasionally we want to check whether the translated values are the same as the English
// ones. This might either be legit (as above) or might be a cut & paste error.
Expand All @@ -80,12 +86,15 @@ public function handle()
// json_encode for comparison as it may be a string or an array.
if (json_encode($translated) == json_encode($value)) {
// error_log("ERROR translation key $group.$key in $other is the same as English, " . json_encode($value));
// $count++;
}
}
}
}
}
}

return $count;
}

private function usedInCode($key) {
Expand Down
48 changes: 28 additions & 20 deletions app/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use OwenIt\Auditing\Contracts\Auditable;
use Cache;

class Device extends Model implements Auditable
{
Expand Down Expand Up @@ -430,43 +431,50 @@ public static function getItemTypes()
// used by the item types.
//
// MAX is used to suppress errors when SQL mode is not set to ONLY_FULL_GROUP_BY.
$types = DB::select(DB::raw("
//
// This is slow and the results don't change much, so we use a cache.
if (Cache::has('item_types')) {
$types = Cache::get('item_types');
} else {
$types = DB::select(DB::raw("
SELECT TRIM(item_type) AS item_type,
MAX(powered) AS powered,
MAX(idcategories) AS idcategories,
MAX(categoryname) AS categoryname
FROM (SELECT DISTINCT s.*
FROM (SELECT DISTINCT s.*
FROM (SELECT TRIM(item_type) AS item_type,
MAX(powered) AS powered,
MAX(idcategories) AS idcategories,
categories.name AS categoryname,
COUNT(*) AS count
FROM devices
INNER JOIN categories
ON devices.category = categories.idcategories
WHERE item_type IS NOT NULL
GROUP BY categoryname,
categories.name AS categoryname,
COUNT(*) AS count
FROM devices
INNER JOIN categories
ON devices.category = categories.idcategories
WHERE item_type IS NOT NULL
GROUP BY categoryname,
UPPER(item_type)) s
JOIN (SELECT TRIM(item_type) AS item_type,
MAX(count) AS maxcount
MAX(count) AS maxcount
FROM (SELECT TRIM(item_type) AS item_type,
MAX(powered) AS powered,
MAX(idcategories) AS idcategories,
categories.name AS categoryname,
COUNT(*) AS count
FROM devices
INNER JOIN categories
ON devices.category =
categories.idcategories
WHERE item_type IS NOT NULL
GROUP BY categoryname,
categories.name AS categoryname,
COUNT(*) AS count
FROM devices
INNER JOIN categories
ON devices.category =
categories.idcategories
WHERE item_type IS NOT NULL
GROUP BY categoryname,
UPPER(item_type)) s
GROUP BY UPPER(s.item_type)) AS m
ON UPPER(s.item_type) = UPPER(m.item_type)
AND s.count = m.maxcount) t
AND s.count = m.maxcount) t
GROUP BY UPPER(t.item_type)
HAVING LENGTH(item_type) > 0
"));
"));
\Cache::put('item_types', $types, 24 * 3600);
}

return $types;
}
Expand Down
37 changes: 0 additions & 37 deletions app/Helpers/Fixometer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ public static function hasRole($user, $role)
return false;
}

public static function barChartValue($portion, $total)
{
if ((int) $portion > 0) {
return round((($portion / $total) * 100), 2) - 15;
}

return -15;
}

public static function featureIsEnabled($feature)
{
return $feature === true;
Expand Down Expand Up @@ -188,34 +179,6 @@ public static function userHasDeletePartyPermission($partyId, $userId = null)
return false;
}

public static function userCanApproveEvent($eventId, $userId = null, $groupId = null)
{
if (is_null($userId)) {
$userId = Auth::user()->id;
}
$user = User::find($userId);

if (self::hasRole($user, 'Administrator')) {
return true;
}

if (self::hasRole($user, 'NetworkCoordinator')) {
if ($groupId) {
$group = Group::find($groupId);
} else {
$group = Party::find($eventId)->theGroup;
}

foreach ($group->networks as $network) {
if ($network->coordinators->contains($user)) {
return true;
}
}
}

return false;
}

public static function userHasEditEventsDevicesPermission($partyId, $userId = null)
{
if (is_null($userId)) {
Expand Down
7 changes: 1 addition & 6 deletions app/Http/Controllers/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ public function view($groupid)

if ((isset($groupid) && is_numeric($groupid)) || in_array($groupid, $gids)) {
$group = Group::where('idgroups', $groupid)->first();
} elseif (count($groups)) {
$group = $groups[0];
unset($groups[0]);
}

if (! $group) {
Expand Down Expand Up @@ -666,15 +663,13 @@ public function getJoinGroup($group_id)
}
}

// TODO: This is not currently used, so far as I can tell, even though it's referenced from a route. But
// something like this ought to exist, for when we Vue-ify the group edit page.
public function imageUpload(Request $request, $id)
{
try {
if (isset($_FILES) && ! empty($_FILES)) {
$existing_image = Fixometer::hasImage($id, 'groups', true);
if (! empty($existing_image)) {
Fixometer::removeImage($id, env('TBL_GROUPS'), $existing_image[0]);
Fixometer::removeImage($id, 'groups', $existing_image[0]);
}
$file = new FixometerFile;
$file->upload('file', 'image', $id, env('TBL_GROUPS'), false, true, true);
Expand Down
20 changes: 10 additions & 10 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1102,18 +1102,18 @@ public function getUserMenus(Request $request)
$items['Users'] = route('users');
$items['Roles'] = route('roles');
$items[Lang::get('networks.general.networks')] = route('networks.index');
}

if ($user->hasPermission('verify-translation-access')) {
$items['Translations'] = url('/translations/view/admin');
}
if ($user->hasPermission('verify-translation-access')) {
$items['Translations'] = url('/translations/view/admin');
}

if ($user->hasRole('NetworkCoordinator')) {
if (count($user()->networks) == 1) {
$network = Auth::user()->networks->first();
$items[Lang::get('networks.general.particular_network', ['networkName' => $network->name])] = route('networks.show', $network->id);
} else {
$items[Lang::get('networks.general.networks')] = route('networks.index');
}
if ($user->hasRole('NetworkCoordinator')) {
if (count($user->networks) == 1) {
$network = Auth::user()->networks->first();
$items[Lang::get('networks.general.particular_network', ['networkName' => $network->name])] = route('networks.show', $network->id);
} else {
$items[Lang::get('networks.general.networks')] = route('networks.index');
}
}

Expand Down
Loading

0 comments on commit d2b9322

Please sign in to comment.