diff --git a/app/Console/Commands/ConfirmUser.php b/app/Console/Commands/ConfirmUser.php index daeb24e..a907e0e 100644 --- a/app/Console/Commands/ConfirmUser.php +++ b/app/Console/Commands/ConfirmUser.php @@ -39,7 +39,9 @@ class ConfirmUser extends Command public function handle() { $u = User::resolve($this->argument('user')); - $u->update('confirmed', true); + $u->update(['confirmed' => true]); $this->info("User #$u->id with e-mail $u->email and handle @$u->name was confirmed."); + + dd($u); } } diff --git a/app/Http/Controllers/TableController.php b/app/Http/Controllers/TableController.php index c9b2568..60e21d8 100644 --- a/app/Http/Controllers/TableController.php +++ b/app/Http/Controllers/TableController.php @@ -189,12 +189,19 @@ class TableController extends Controller // Preparing data to insert into the Rows table $rowsData = null; try { - $rowsData = array_map(function ($row) use ($columns) { - if (count($row) == 0 || count($row)==1&&$row[0]=='') return null; + $grid_range = Row::allocateGRIDs(count($rowTable)); + $grid_cnt = $grid_range[0]; + + $rowsData = array_map(function ($row) use ($columns, &$grid_cnt) { + if (count($row) == 0 || count($row) == 1 && $row[0] == '') return null; if (count($row) != count($columns)) { throw new NotApplicableException("All rows must have " . count($columns) . " fields."); } - $parsed = []; + + $parsed = [ + '_grid' => $grid_cnt++ + ]; + foreach ($row as $i => $val) { $key = $columns[$i]->name; if (strlen($val) > 255) { diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 749392b..a4689cf 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -2,6 +2,13 @@ namespace App\Http; +use App\Http\Middleware\ActivatedAccount; +use App\Http\Middleware\EncryptCookies; +use App\Http\Middleware\RedirectIfAuthenticated; +use App\Http\Middleware\ThrottleIfNotDebug; +use App\Http\Middleware\TrimStrings; +use App\Http\Middleware\TrustProxies; +use App\Http\Middleware\VerifyCsrfToken; use Illuminate\Foundation\Http\Kernel as HttpKernel; class Kernel extends HttpKernel @@ -16,9 +23,9 @@ class Kernel extends HttpKernel protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, - \App\Http\Middleware\TrimStrings::class, + TrimStrings::class, \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, - \App\Http\Middleware\TrustProxies::class, + TrustProxies::class, ]; /** @@ -29,12 +36,12 @@ class Kernel extends HttpKernel protected $middlewareGroups = [ 'web' => [ 'throttle:120,15', // try to prevent people refresh-spamming the server to game table visit counts - \App\Http\Middleware\EncryptCookies::class, + EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, // \Illuminate\Session\Middleware\AuthenticateSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, - \App\Http\Middleware\VerifyCsrfToken::class, + VerifyCsrfToken::class, 'bindings', ], @@ -52,14 +59,14 @@ class Kernel extends HttpKernel * @var array */ protected $routeMiddleware = [ - 'activated' => \App\Http\Middleware\ActivatedAccount::class, + 'activated' => ActivatedAccount::class, 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, - 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, + 'guest' => RedirectIfAuthenticated::class, 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, - 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, + 'throttle' => ThrottleIfNotDebug::class, ]; } diff --git a/app/Http/Middleware/ThrottleIfNotDebug.php b/app/Http/Middleware/ThrottleIfNotDebug.php new file mode 100644 index 0000000..721b27e --- /dev/null +++ b/app/Http/Middleware/ThrottleIfNotDebug.php @@ -0,0 +1,19 @@ +data->_grid; + } + + public function setGridAttribute($value) { + $this->data->_grid = $value; + } + + /** + * Allocate a single Global Row ID, application-unique. + * + * GRIDs are used to uniquely identify existing or proposed new rows, + * and are preserved after row modifications, to ensure change proposals have + * a clear target. + * + * @return int + */ + public static function allocateGRID() + { + return \DB::selectOne("SELECT nextval('global_row_id_seq') AS grid;")->grid; + } + + /** + * Allocate a block of Global Row IDs, application-unique. + * + * @see Row::allocateGRID() + * + * @return int[] first and last + */ + public static function allocateGRIDs($count) + { + $last = \DB::selectOne("SELECT multi_nextval('global_row_id_seq', ?) AS last_grid;", [$count])->last_grid; + return [$last - $count + 1, $last]; + } } diff --git a/app/Models/User.php b/app/Models/User.php index 7a88274..ccc61ef 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -62,7 +62,7 @@ class User extends BaseModel implements * @var array */ protected $fillable = [ - 'name', 'title', 'email', 'password', 'bio', 'website' + 'name', 'title', 'email', 'password', 'bio', 'website', 'confirmed' ]; /** @@ -183,6 +183,10 @@ class User extends BaseModel implements } else { $u = static::where('email', $ident)->first(); + + if (!$u) { + $u = static::where('name', $ident)->first(); + } } if (!$u) throw new NotExistException("No user found matching \"$ident\""); diff --git a/app/Tables/Column.php b/app/Tables/Column.php index a8c41a0..1b32bc3 100644 --- a/app/Tables/Column.php +++ b/app/Tables/Column.php @@ -57,6 +57,10 @@ class Column implements JsonSerializable $this->title = $b->title; $this->type = $b->type; + if ($this->name == '_grid') { // global row ID + throw new NotApplicableException("_grid is a reserved column name."); + } + if (!in_array($this->type, self::colTypes)) { throw new NotApplicableException("\"$this->type\" is not a valid column type."); } diff --git a/database/migrations/2018_08_01_204822_add_row_sequence_generator.php b/database/migrations/2018_08_01_204822_add_row_sequence_generator.php new file mode 100644 index 0000000..6493881 --- /dev/null +++ b/database/migrations/2018_08_01_204822_add_row_sequence_generator.php @@ -0,0 +1,54 @@ +bindings as $i=>$binding) $b[$i] = "'$binding'"; Log::debug('SQL: ' . preg_replace_array('/\\?/', $b, $query->sql)); diff --git a/resources/views/table/_action-buttons.blade.php b/resources/views/table/_action-buttons.blade.php index 8cdfe37..f026f42 100644 --- a/resources/views/table/_action-buttons.blade.php +++ b/resources/views/table/_action-buttons.blade.php @@ -10,25 +10,26 @@ @sr(Table actions) {{-- Disabled until implemented --}} -@if(true) @if(guest() || !user()->confirmed || user()->ownsTable($table)) + {{-- Guest, unconfirmed, or a table owner --}} {{-- Passive fork buttons with counter --}} - {{ $table->forks_count ?: '–' }}  - @icon(fa-code-fork, sr:Forks) + @icon(fa-code-fork, sr:Forks)  + {{ $table->forks_count ?: '–' }} {{-- Passive favourite buttons with counter --}} - {{ $table->favourites_count ?: '–' }}  - @icon(fa-star, sr:Favourites) + @icon(fa-star, sr:Favourites)  + {{ $table->favourites_count ?: '–' }} @else + {{-- Logged in and does not own the table --}} {{-- Active fork button | counter --}}
@@ -55,7 +56,6 @@ @icon(fa-star-o, sr:Favourite) @endif - {{ $table->favourites_count ?: '–' }} @@ -67,8 +67,8 @@ {{-- Comments button with counter --}} - {{ $table->comments_count ?: '–' }}  - @icon(fa-comment, sr:Comments) + @icon(fa-comment, sr:Comments)  + {{ $table->comments_count ?: '–' }} {{-- Active proposals button | counter --}} @@ -77,22 +77,25 @@ data-toggle="tooltip" data-placement="top"> @icon(fa-inbox fa-pr, sr:Change Proposals){{ $table->proposals_count ?: '–' }} - @if(user()->ownsTable($table)) - - @icon(fa-pencil, sr:Draft Change) - - @else - - @icon(fa-pencil, sr:Propose Change) - - @endif + @auth + @if(user()->ownsTable($table)) + {{-- Table owner logged in --}} + + @icon(fa-pencil, sr:Draft Change) + + @else + {{-- Not a table owner --}} + + @icon(fa-pencil, sr:Propose Change) + + @endif + @endauth
-@endif - - @if(user() && user()->ownsTable($table)) + @if(authed() && user()->ownsTable($table)) + {{-- Table opts menu for table owner --}} @icon(fa-wrench, sr:Table Options) diff --git a/resources/views/table/_rows.blade.php b/resources/views/table/_rows.blade.php index c1cd7c9..019a4f4 100644 --- a/resources/views/table/_rows.blade.php +++ b/resources/views/table/_rows.blade.php @@ -4,12 +4,13 @@ @php /** @var object[] $columns */ - /** @var \App\Models\Row[]|array[][] $rows */ + /** @var \App\Models\Row[] $rows */ @endphp + @foreach($columns as $col) @endforeach @@ -18,8 +19,9 @@ @foreach($rows as $row) + @foreach($columns as $col) - + @endforeach @endforeach
#GRID{{ $col->title }}
{{ $row->data->_grid }}{{ $row['data']->{$col->name} }}{{ $row->data->{$col->name} }}