Skip to content

Commit

Permalink
Merge pull request #2238 from Blair2004/v5.0.x
Browse files Browse the repository at this point in the history
V5.0.x
  • Loading branch information
Blair2004 authored Feb 1, 2025
2 parents 610e265 + 04d5e40 commit d2a762b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 16 deletions.
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 );
}
}

0 comments on commit d2a762b

Please sign in to comment.