Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V5.0.x #2238

Merged
merged 2 commits into from
Feb 1, 2025
Merged

V5.0.x #2238

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
23 changes: 15 additions & 8 deletions app/Providers/TelescopeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Providers;

use App\Models\Role;
use App\Services\Helper;
use Illuminate\Support\Facades\Gate;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Telescope;
Expand Down Expand Up @@ -56,13 +57,19 @@ protected function hideSensitiveRequestDetails(): void
*/
protected function gate(): void
{
Gate::define( 'viewTelescope', function ( $user ) {
return in_array( $user->email, [
Role::namespace( Role::ADMIN )
->users()
->get( 'email' )
->toArray(),
] );
} );
if ( Helper::installed() ) {
$adminRole = Role::namespace( Role::ADMIN );
$users = collect([]);

if ( $adminRole instanceof Role ) {
$users = $adminRole->users;
}

Gate::define( 'viewTelescope', function ( $user ) use ( $users ) {
return in_array( $user->email, [
$users->map( fn( $__user ) => $__user->email )
] );
} );
}
}
}
11 changes: 7 additions & 4 deletions app/Services/ModulesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,6 @@ public function upload( UploadedFile $file ): array

$directoryName = pathinfo( $directory[0] )[ 'basename' ];
$rawFiles = Storage::disk( 'ns-modules-temp' )->allFiles( $extractionFolderName );
$module = [];

/**
* Just retrieve the files name
Expand Down Expand Up @@ -782,15 +781,19 @@ public function upload( UploadedFile $file ): array
* and if the new module is outdated
*/
if ( $existingModule = $this->get( $moduleNamespace ) ) {
if ( version_compare( $module[ 'version' ], $moduleVersion, '>=' ) ) {
if ( version_compare( $existingModule[ 'version' ], $moduleVersion, '>=' ) ) {
/**
* We're dealing with old module
*/
$this->clearTemporaryFiles();

return [
'status' => 'danger',
'message' => __( 'Unable to upload this module as it\'s older than the version installed' ),
'status' => 'error',
'message' => sprintf(
__( 'Unable to upload this module as it\'s older (%s) than the version installed (%s)' ),
$xml->version,
$existingModule[ 'version' ],
),
'module' => $existingModule,
];
}
Expand Down
2 changes: 1 addition & 1 deletion config/nexopos.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* This is the core version of NexoPOS. This is used to displays on the
* dashboard and to ensure a compatibility with the modules.
*/
'version' => '5.3.4',
'version' => '5.3.5',

/**
* --------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion routes/api/customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
Route::post( 'customers/search', [ CustomersController::class, 'searchCustomer' ] )->name( ns()->routeName( 'ns-api.customers.search' ) )->middleware( NsRestrictMiddleware::arguments( 'nexopos.read.customers' ) );
Route::post( 'customers/coupons/{coupon}', [ CustomersController::class, 'loadCoupons' ] )->middleware( NsRestrictMiddleware::arguments( 'nexopos.read.customers' ) );
Route::post( 'customers/{customer}/crud/account-history', [ CustomersController::class, 'recordAccountHistory' ] )->middleware( NsRestrictMiddleware::arguments( 'nexopos.customers.manage-account-history' ) );
Route::put( 'customers/{customer}/crud/{accountHistory}/account-history', [ CustomersController::class, 'updateAccountHistory' ] )->middleware( NsRestrictMiddleware::arguments( 'nexopos.customers.manage-account-history' ) );
Route::put( 'customers/{customer}', [ CustomersController::class, 'put' ] )->middleware( NsRestrictMiddleware::arguments( 'nexopos.update.customers' ) );

Route::post( 'customers/{customer}/account-history', [ CustomersController::class, 'accountTransaction' ] )->middleware( NsRestrictMiddleware::arguments( 'nexopos.customers.manage-account-history' ) );
Expand Down
64 changes: 62 additions & 2 deletions tests/Feature/UploadModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function test_module_system()
*/
$moduleService = app()->make( ModulesService::class );

$name = str_replace( '.', '', $this->faker->text( 10 ) );
$name = str_replace( '.', '', $this->faker->text( 10 ) . Str::random(5) );
$config = [
'namespace' => ucwords( Str::camel( $name ) ),
'name' => $name,
Expand Down Expand Up @@ -90,12 +90,72 @@ public function test_module_system()
$response->assertRedirect( ns()->route( 'ns.dashboard.modules-list' ) );

/**
* Step 7 : We'll re-delete the uploaded module
* Step 7: We'll upload an old version of the same module
* and make sure it fails.
*
* We'll first create a copy of the zip file and edit the config.xml file that is witin
*/
$zipFilePath = $result[ 'path' ];
$content = file_get_contents( $zipFilePath );
$newZipFilePath = storage_path( 'temporary-files/' . Str::random( 20 ) . '.zip' );
file_put_contents( $newZipFilePath, $content );

/**
* let's now edit the config.xml file within that zip file
*/
$zip = new \ZipArchive();
$zip->open( $newZipFilePath );
$configXml = $zip->getFromName( $config[ 'namespace' ] . '/config.xml' );
$configXml = str_replace( '<version>1.0</version>', '<version>0.1</version>', $configXml );
$zip->addFromString( $config[ 'namespace' ] . '/config.xml', $configXml );
$zip->close();

/**
* We'll now attempt to upload that zip file
*/
$response = $this->withSession( $this->app[ 'session' ]->all() )
->withHeader( 'Accept', 'text/html' )
->post( '/api/modules', [
'module' => UploadedFile::fake()->createWithContent( 'module.zip', file_get_contents( $newZipFilePath ) ),
] );

$response->assertRedirect( '/dashboard/modules/upload' );
$response->assertSessionHasErrors( 'module' );

/**
* Step 9: We'll edit the config.xml and change the version to a greater version
*/
$zip = new \ZipArchive();
$zip->open( $newZipFilePath );
$configXml = $zip->getFromName( $config[ 'namespace' ] . '/config.xml' );
$configXml = str_replace( '<version>0.1</version>', '<version>2.0</version>', $configXml );
$zip->addFromString( $config[ 'namespace' ] . '/config.xml', $configXml );
$zip->close();

/**
* We'll now attempt to upload that zip file
*/
$response = $this->withSession( $this->app[ 'session' ]->all() )
->withHeader( 'Accept', 'text/html' )
->post( '/api/modules', [
'module' => UploadedFile::fake()->createWithContent( 'module.zip', file_get_contents( $newZipFilePath ) ),
] );

$response->assertRedirect( ns()->route( 'ns.dashboard.modules-list' ) );

/**
* Step 8 : We'll re-delete the uploaded module
*/
$moduleService->delete( $config[ 'namespace' ] );
$moduleService->load();
$module = $moduleService->get( $config[ 'namespace' ] );

$this->assertTrue( $module === false, 'The uploaded module wasn\'t deleted' );

/**
* We'll clean up the created zip files
*/
unlink( $zipFilePath );
unlink( $newZipFilePath );
}
}