Skip to content

Commit

Permalink
Merge pull request #1408 from AgID/develop
Browse files Browse the repository at this point in the history
Consolidation in master
  • Loading branch information
pdavide authored May 19, 2022
2 parents 23b0018 + 3340d5f commit 111bb25
Show file tree
Hide file tree
Showing 29 changed files with 2,434 additions and 2,379 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public function suspend(Request $request, PublicAdministration $publicAdministra
throw new InvalidUserStatusException('Invited users cannot be suspended.');
}

//NOTE: super admin are allowed to suspend the last active administrator of a public administration
// NOTE: super admin are allowed to suspend the last active administrator of a public administration
if ($isApiRequest || optional($request->user())->cannot(UserPermission::ACCESS_ADMIN_AREA)) {
$validator = validator($request->all())->after([$this, 'validateNotLastActiveAdministrator']);
if ($validator->fails()) {
Expand Down
7 changes: 7 additions & 0 deletions app/Http/Controllers/WidgetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ class WidgetsController extends Controller
{
use HasRoleAwareUrls;

/**
* Analytics Service.
*
* @var AnalyticsService
*/
protected $analyticsService;

/**
* Default constructor.
*/
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Requests/LogFilteringRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public function rules(): array
'start_time' => 'sometimes|required|date_format:H:i',
'end_date' => 'required_with:end_time|date_format:d/m/Y|after_or_equal:start_date',
'end_time' => 'sometimes|required|date_format:H:i',
//NOTE: can't force public administration existence
// NOTE: can't force public administration existence
// since Public Administration purge force delete it
// See: ProcessPendingWebsites:handle()
'ipa_code' => 'sometimes|required|max:25',
//NOTE: can't force website existence
// NOTE: can't force website existence
// since Website purge force delete it
// See: ProcessPendingWebsites:handle()
'website_id' => 'sometimes|required|max:50',
Expand Down
3 changes: 2 additions & 1 deletion app/Jobs/MonitorWebsitesTracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function handle(): void
// Check:
// - visits the last 24 hours
// - website created at least 'archive_expire' days before
//NOTE: Matomo report contains information for all the requested days, regardless of when the website was created
// NOTE: Matomo report contains information for all the requested days, regardless of when the website was created
// TODO: Needs rework to verify the data archived and reported by Matomo
if (0 === $analyticsService->getLiveVisits($website->analytics_id, 1440) && Carbon::now()->subDays($intervalArchive)->greaterThanOrEqualTo($website->created_at)) {
$visits = $analyticsService->getSiteLastDaysVisits($website->analytics_id, $intervalArchive);

Expand Down
4 changes: 2 additions & 2 deletions app/Jobs/UpdateClosedBetaWhitelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UpdateClosedBetaWhitelist extends ProcessWebhookJob
*/
public const CLOSED_BETA_WHITELIST_KEY = 'closed-beta-whitelist';

//NOTE: DON'T USE $webhookCall field because it's not initialized!
// NOTE: DON'T USE $webhookCall field because it's not initialized!

/**
* Whitelisted ipa codes array.
Expand All @@ -41,7 +41,7 @@ class UpdateClosedBetaWhitelist extends ProcessWebhookJob
*/
public function __construct(?WebhookCall $webhookCall = null)
{
//NOTE: no parent constructor call since
// NOTE: no parent constructor call since
// database persistence is not wanted
// and no migration has been scheduled
$this->payload = $webhookCall->payload ?? null;
Expand Down
12 changes: 6 additions & 6 deletions app/Listeners/PublicAdministrationEventsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function onRegistered(PublicAdministrationRegistered $event): void
$publicAdministration = $event->getPublicAdministration();
$user = $event->getUser();

//Notify registering user
// Notify registering user
$user->sendPublicAdministrationRegisteredNotification($publicAdministration);

if ($publicAdministration->rtd_mail) {
//Notify RTD
// Notify RTD
$publicAdministration->sendPublicAdministrationRegisteredNotificationToRTD();
}

Expand All @@ -64,14 +64,14 @@ public function onActivated(PublicAdministrationActivated $event): void
$publicAdministration = $event->getPublicAdministration();

try {
//NOTE: if RollUp Reporting plugin isn't installed on remote Analytics Service,
// NOTE: if RollUp Reporting plugin isn't installed on remote Analytics Service,
// a CommandErrorException is expected to be thrown
$publicAdministration->registerRollUp();
} catch (Exception $exception) {
report($exception);
}

//Notify user (this user is also the only public administration administrator)
// Notify user (this user is also the only public administration administrator)
$user = $publicAdministration->users()->first();
$user->sendPublicAdministrationActivatedNotification($publicAdministration);

Expand Down Expand Up @@ -111,7 +111,7 @@ public function onUpdated(PublicAdministrationUpdated $event): void
$publicAdministration = $event->getPublicAdministration();

if (Arr::has($event->getUpdates(), 'rtd_mail')) {
//Notify new RTD
// Notify new RTD
$publicAdministration->sendPublicAdministrationUpdatedRTD();
}

Expand Down Expand Up @@ -151,7 +151,7 @@ public function onNotFoundInIpa(PublicAdministrationNotFoundInIpa $event): void
*/
public function onPrimaryWebsiteUpdated(PublicAdministrationPrimaryWebsiteUpdated $event): void
{
//TODO: decidere come gestire i cambiamenti del sito istituzionale su IPA
// TODO: decidere come gestire i cambiamenti del sito istituzionale su IPA
$publicAdministration = $event->getPublicAdministration();
logger()->warning(
'Public Administration ' . $publicAdministration->info . ' primary website was changed in IPA index [' . e($event->getNewURL()) . '].',
Expand Down
22 changes: 11 additions & 11 deletions app/Listeners/UserEventsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function onRegistered(Registered $event): void
{
$this->updateUsersIndex($event->user);

//NOTE: user isn't connected to any Public Administration yet
// NOTE: user isn't connected to any Public Administration yet
logger()->notice(
'New user registered: ' . $event->user->uuid,
[
Expand Down Expand Up @@ -79,7 +79,7 @@ public function onInvited(UserInvited $event): void
// Notify the user only if is already confirmed otherwise is notified by classic invitation
$user->sendPublicAdministrationInvitedNotification($publicAdministration);
}
//Notify public administration administrators
// Notify public administration administrators
$publicAdministration->sendUserInvitedNotificationToAdministrators($user);
}
logger()->notice(
Expand Down Expand Up @@ -114,10 +114,10 @@ public function onActivated(UserActivated $event): void
$user = $event->getUser();
$publicAdministration = $event->getPublicAdministration();

//Notify user
// Notify user
$user->sendActivatedNotification($publicAdministration);

//Notify public administration administrators
// Notify public administration administrators
$publicAdministration->sendUserActivatedNotificationToAdministrators($user);

logger()->notice(
Expand All @@ -139,7 +139,7 @@ public function onUpdated(UserUpdated $event): void
{
$user = $event->getUser();

//Update Redisearch websites index
// Update Redisearch websites index
$this->updateUsersIndex($user);

if (!$event->isOnlyLastAccessDirty()) {
Expand Down Expand Up @@ -220,7 +220,7 @@ public function onWebsiteAccessChanged(UserWebsiteAccessChanged $event): void
$website = $event->getWebsite();
$accessType = $event->getAccessType();

//Notify public administration administrators (currently disabled - TODO: verify if really needed)
// Notify public administration administrators (currently disabled - TODO: verify if really needed)
// $website->publicAdministration->sendWebsiteAccessChangedNotificationToAdministrators($user);

logger()->notice(
Expand Down Expand Up @@ -279,10 +279,10 @@ public function onSuspended(UserSuspended $event): void
{
$user = $event->getUser();
$publicAdministration = $event->getPublicAdministration();
//Notify user
// Notify user
$user->sendSuspendedNotification($publicAdministration);

//Notify public administration administrators
// Notify public administration administrators
$user->publicAdministrationsWithSuspended()->each(function (PublicAdministration $publicAdministration) use ($user) {
$publicAdministration->sendUserSuspendedNotificationToAdministrators($user);
});
Expand All @@ -307,10 +307,10 @@ public function onReactivated(UserReactivated $event): void
$user = $event->getUser();
$publicAdministration = $event->getPublicAdministration();

//Notify user
// Notify user
$user->sendReactivatedNotification($publicAdministration);

//Notify public administration administrators
// Notify public administration administrators
$user->publicAdministrations()->each(function (PublicAdministration $publicAdministration) use ($user) {
$publicAdministration->sendUserReactivatedNotificationToAdministrators($user);
});
Expand Down Expand Up @@ -371,7 +371,7 @@ public function onPasswordReset(PasswordReset $event): void
{
$user = $event->user;

//Notify user
// Notify user
$user->sendPasswordChangedNotification();

logger()->notice('Password successfully changed for user ' . $user->uuid,
Expand Down
32 changes: 16 additions & 16 deletions app/Listeners/WebsiteEventsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public function onAdded(WebsiteAdded $event): void
}

if (!$website->type->is(WebsiteType::INSTITUTIONAL)) {
//Notify the registering user
// Notify the registering user
$user->sendWebsiteAddedNotification($website);
}

//Notify public administration administrators
// Notify public administration administrators
$website->publicAdministration->sendWebsiteAddedNotificationToAdministrators($website, $user);

//Update Redisearch websites index
// Update Redisearch websites index
$this->updateWebsitesIndex($website);

logger()->notice(
Expand All @@ -84,11 +84,11 @@ public function onActivated(WebsiteActivated $event): void

$publicAdministration = $website->publicAdministration;

//Notify public administration administrators
// Notify public administration administrators
$publicAdministration->sendWebsiteActivatedNotificationToAdministrators($website);

if ($publicAdministration->rtd_mail) {
//Notify RTD
// Notify RTD
$publicAdministration->sendWebsiteActivatedNotificationToRTD($website);
}

Expand All @@ -107,7 +107,7 @@ public function onActivated(WebsiteActivated $event): void
report($exception);
}

//NOTE: primary websites are added to roll up report
// NOTE: primary websites are added to roll up report
// by "public administration activated" event handler
if (!$website->type->is(WebsiteType::INSTITUTIONAL)) {
try {
Expand All @@ -127,7 +127,7 @@ public function onUpdated(WebsiteUpdated $event): void
{
$website = $event->getWebsite();

//Update Redisearch websites index
// Update Redisearch websites index
$this->updateWebsitesIndex($website);

logger()->notice('Website ' . $website->info . ' updated',
Expand Down Expand Up @@ -167,7 +167,7 @@ public function onWebsiteUrlChanged(WebsiteUrlChanged $event): void
{
$website = $event->getWebsite();

//Notify public administration administrators
// Notify public administration administrators
$website->publicAdministration->sendWebsiteUrlChangedNotificationToAdministrators($website);

logger()->notice(
Expand All @@ -189,7 +189,7 @@ public function onArchiving(WebsiteArchiving $event): void
{
$website = $event->getWebsite();

//Notify public administration administrators
// Notify public administration administrators
$website->publicAdministration->sendWebsiteArchivingNotificationToAdministrators($website, $event->getDaysLeft());

logger()->notice(
Expand All @@ -213,7 +213,7 @@ public function onArchived(WebsiteArchived $event): void
$manual = $event->isManual();
$reason = $manual ? 'manually' : 'due to inactivity';

//Notify public administration administrators
// Notify public administration administrators
$website->publicAdministration->sendWebsiteArchivedNotificationToAdministrators($website, $manual);

logger()->notice(
Expand All @@ -235,7 +235,7 @@ public function onUnarchived(WebsiteUnarchived $event): void
{
$website = $event->getWebsite();

//Notify public administration administrators
// Notify public administration administrators
$website->publicAdministration->sendWebsiteUnarchivedNotificationToAdministrators($website);

logger()->notice(
Expand All @@ -257,7 +257,7 @@ public function onPurging(WebsitePurging $event): void
{
$website = $event->getWebsite();

//Notify public administration administrators
// Notify public administration administrators
$website->publicAdministration->sendWebsitePurgingNotificationToAdministrators($website);

logger()->notice(
Expand All @@ -282,15 +282,15 @@ public function onPurged(WebsitePurged $event): void
$websiteInfo = '"' . e($website->name) . '" [' . $website->slug . ']';
$publicAdministration = json_decode($event->getPublicAdministrationJson());

//NOTE: for primary websites use PublicAdministrationPurged
// NOTE: for primary websites use PublicAdministrationPurged
// event to notify administrators
if (WebsiteType::INSTITUTIONAL !== $website->type) {
//Notify public administration administrators
// Notify public administration administrators
$publicAdministration = PublicAdministration::findByIpaCode($publicAdministration->ipa_code);
$publicAdministration->sendWebsitePurgedNotificationToAdministrators($website);
}

//NOTE: toJson: relationship attributes are snake_case
// NOTE: toJson: relationship attributes are snake_case
logger()->notice(
'Website ' . $websiteInfo . ' purged',
[
Expand Down Expand Up @@ -346,7 +346,7 @@ public function onPrimaryWebsiteNotTracking(PrimaryWebsiteNotTracking $event): v
{
$website = $event->getWebsite();

//Notify public administration administrators
// Notify public administration administrators
$website->publicAdministration->sendPrimaryWebsiteNotTrackingNotificationToAdministrators();

logger()->notice(
Expand Down
7 changes: 6 additions & 1 deletion app/Services/MatomoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public function getAllSitesId(): array
$params = [
'method' => 'SitesManager.getAllSitesId',
'token_auth' => $this->tokenAuth,
'filter_limit' => '-1',
];

return $this->apiCall($params);
Expand Down Expand Up @@ -380,6 +381,7 @@ public function getUsersLogin(): array
$params = [
'method' => 'UsersManager.getUsersLogin',
'token_auth' => $this->tokenAuth,
'filter_limit' => '-1',
];

return $this->apiCall($params);
Expand Down Expand Up @@ -462,6 +464,7 @@ public function getLiveVisits(string $idSite, int $minutes): int
*
* @return int the total reported website visits
*/
// TODO: Needs rework to verify that the requested range is available
public function getSiteTotalVisitsFrom(string $idSite, string $from): int
{
$params = [
Expand Down Expand Up @@ -512,6 +515,7 @@ public function getSiteLastMonthVisits(string $idSite): int
*
* @return array the list of days with the number of visits
*/
// TODO: Needs rework to verify the validity of the date parameter format
public function getSiteLastDaysVisits(string $idSite, int $days): array
{
$params = [
Expand Down Expand Up @@ -564,7 +568,7 @@ public function getAllSegments(): array
$params = [
'method' => 'SegmentEditor.getAll',
'token_auth' => $this->tokenAuth,
'filter_limit' => -1,
'filter_limit' => '-1',
];

return $this->apiCall($params);
Expand Down Expand Up @@ -635,6 +639,7 @@ public function getCountriesInSegmentInMonth(string $idSite, string $date, strin
'date' => $date,
'segment' => $segment,
'token_auth' => $this->tokenAuth,
'filter_limit' => '-1',
];

return $this->apiCall($params);
Expand Down
2 changes: 1 addition & 1 deletion app/Traits/ActivatesWebsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function activate(Website $website): void
$pendingUser->retract(UserRole::REGISTERED);
$pendingUser->assign(UserRole::ADMIN);

//NOTE: don't use HasWebsitePermissions since this trait is shared with batch jobs
// NOTE: don't use HasWebsitePermissions since this trait is shared with batch jobs
Bouncer::allow($pendingUser)->to(UserPermission::READ_ANALYTICS, $website);
Bouncer::allow($pendingUser)->to(UserPermission::MANAGE_ANALYTICS, $website);
Bouncer::disallow($pendingUser)->to(UserPermission::NO_ACCESS, $website);
Expand Down
Loading

0 comments on commit 111bb25

Please sign in to comment.