mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-09-13 13:57:34 -04:00
fix(sales): gate per-record endpoints behind reports_sales grant (REDACTED) Cashiers holding only the base `sales` grant could reach per-sale endpoints (getRow, getEdit, postSave, getReceipt, getInvoice, getSendPdf, getSendReceipt) that require `reports_sales`. getManage() enforced this at the list level, but individual endpoints did not re-check. Regression tests added. Auth: - Introduce `IsLoggedIn` filter to centralize login checks across controllers - Replace custom `AccessDeniedRedirectException` with built-in `RedirectException` Employees: - Add `DISALLOW_PASSWORD_CHANGE` and `DISALLOW_GRANT_CHANGE` env vars to restrict credential and permission changes in locked-down environments - Extract `hasGrantsChanged()` to streamline `postSave` Refactor: - Rename snake_case variables to camelCase in Sales, Items, and Employees controllers for PSR-12 compliance - Use explicit `db_connect()` for transaction clarity in Items controller Fixes: - SMTP config entries fall back to defaults via null coalescing - Migration uses `DROP FOREIGN KEY` instead of `DROP CONSTRAINT` - Password hash upgrade only sets session on successful `hash_version` update - Correct lang key for unknown error in Module model Language: - Translate `error_grant_change_disallowed` / `error_password_change_disallowed` across all 44 supported locales with => alignment matching en reference - Fix "cannot be deleted" messages and misc typos across ~15 language files Tests: - Bootstrap seeder only once in ItemsCsvImportTest; close connection after - Restore `DISALLOW_GRANT_CHANGE` in teardown to prevent side effects - Use `uniqid()` for test user data to avoid collisions Signed-off-by: 17935339+objecttothis@users.noreply.github.com
60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class Migration_Initial_Schema extends Migration
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Perform a migration step.
|
|
* Only runs on fresh installs - skips if database already has tables.
|
|
*
|
|
* For testing: CI4's DatabaseTestTrait with $refresh=true handles table
|
|
* cleanup/creation automatically. This migration only loads initial schema
|
|
* on fresh databases where no application tables exist.
|
|
*/
|
|
public function up(): void
|
|
{
|
|
// Check if core application tables exist (existing install)
|
|
// Note: migrations table may exist even on fresh DB due to migration tracking
|
|
$tables = $this->db->listTables();
|
|
|
|
// Check for a core application table, not just migrations table
|
|
foreach ($tables as $table) {
|
|
// Strip prefix if present for comparison
|
|
$tableName = str_replace($this->db->getPrefix(), '', $table);
|
|
if (in_array($tableName, ['app_config', 'items', 'employees', 'people'])) {
|
|
// Database already populated - skip initial schema
|
|
// This is an existing installation upgrading from older version
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Fresh install - load initial schema
|
|
helper('migration');
|
|
executeScript(APPPATH . 'Database/Migrations/sqlscripts/initial_schema.sql');
|
|
}
|
|
|
|
/**
|
|
* Revert a migration step.
|
|
* Cannot revert initial schema - would lose all data.
|
|
*/
|
|
public function down(): void
|
|
{
|
|
// Cannot safely revert initial schema
|
|
// Would require dropping all tables which would lose all data
|
|
$this->db->query('SET FOREIGN_KEY_CHECKS = 0');
|
|
|
|
foreach ($this->db->listTables() as $table) {
|
|
$this->db->query('DROP TABLE IF EXISTS `' . $table . '`');
|
|
}
|
|
|
|
$this->db->query('SET FOREIGN_KEY_CHECKS = 1');
|
|
}
|
|
} |