Merge branch 'develop'
This commit is contained in:
79
app/Console/Commands/CountVotes.php
Normal file → Executable file
79
app/Console/Commands/CountVotes.php
Normal file → Executable file
@@ -1,5 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright © 2020 Miguel Nogueira
|
||||
*
|
||||
* This file is part of Raspberry Staff Manager.
|
||||
*
|
||||
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Raspberry Staff Manager is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Application;
|
||||
@@ -43,28 +62,23 @@ class CountVotes extends Command
|
||||
$eligibleApps = Application::where('applicationStatus', 'STAGE_PEERAPPROVAL')->get();
|
||||
$pbar = $this->output->createProgressBar($eligibleApps->count());
|
||||
|
||||
if($eligibleApps->isEmpty())
|
||||
{
|
||||
if ($eligibleApps->isEmpty()) {
|
||||
$this->error('𐄂 There are no applications that need to be processed.');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($eligibleApps as $application)
|
||||
{
|
||||
foreach ($eligibleApps as $application) {
|
||||
$votes = $application->votes;
|
||||
$voteCount = $application->votes->count();
|
||||
|
||||
$positiveVotes = 0;
|
||||
$negativeVotes = 0;
|
||||
|
||||
if ($voteCount > 5)
|
||||
{
|
||||
$this->info('Counting votes for application ID ' . $application->id);
|
||||
foreach ($votes as $vote)
|
||||
{
|
||||
switch ($vote->allowedVoteType)
|
||||
{
|
||||
if ($voteCount > 5) {
|
||||
$this->info('Counting votes for application ID '.$application->id);
|
||||
foreach ($votes as $vote) {
|
||||
switch ($vote->allowedVoteType) {
|
||||
case 'VOTE_APPROVE':
|
||||
$positiveVotes++;
|
||||
break;
|
||||
@@ -74,7 +88,7 @@ class CountVotes extends Command
|
||||
}
|
||||
}
|
||||
|
||||
$this->info('Total votes for application ID ' . $application->id . ': ' . $voteCount);
|
||||
$this->info('Total votes for application ID '.$application->id.': '.$voteCount);
|
||||
$this->info('Calculating criteria...');
|
||||
$negativeVotePercent = floor(($negativeVotes / $voteCount) * 100);
|
||||
$positiveVotePercent = floor(($positiveVotes / $voteCount) * 100);
|
||||
@@ -83,54 +97,43 @@ class CountVotes extends Command
|
||||
|
||||
$this->table([
|
||||
'% of approval votes',
|
||||
'% of denial votes'
|
||||
'% of denial votes',
|
||||
], [ // array of arrays, e.g. rows
|
||||
[
|
||||
$positiveVotePercent . "%",
|
||||
$negativeVotePercent . "%"
|
||||
]
|
||||
$positiveVotePercent.'%',
|
||||
$negativeVotePercent.'%',
|
||||
],
|
||||
]);
|
||||
|
||||
if ($pollResult)
|
||||
{
|
||||
$this->info('✓ Dispatched promotion event for applicant ' . $application->user->name);
|
||||
if (!$this->option('dryrun'))
|
||||
{
|
||||
if ($pollResult) {
|
||||
$this->info('✓ Dispatched promotion event for applicant '.$application->user->name);
|
||||
if (! $this->option('dryrun')) {
|
||||
$application->response->vacancy->vacancyCount -= 1;
|
||||
$application->response->vacancy->save();
|
||||
|
||||
event(new ApplicationApprovedEvent(Application::find($application->id)));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$this->warn('Dry run: Event won\'t be dispatched');
|
||||
}
|
||||
|
||||
$pbar->advance();
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
if (!$this->option('dryrun'))
|
||||
{
|
||||
} else {
|
||||
if (! $this->option('dryrun')) {
|
||||
event(new ApplicationDeniedEvent(Application::find($application->id)));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->warn('Dry run: Event won\'t be dispatched');
|
||||
}
|
||||
|
||||
$pbar->advance();
|
||||
$this->error('𐄂 Applicant ' . $application->user->name . ' does not meet vote criteria (Majority)');
|
||||
$this->error('𐄂 Applicant '.$application->user->name.' does not meet vote criteria (Majority)');
|
||||
}
|
||||
} else {
|
||||
$this->warn('Application ID'.$application->id.' did not have enough votes for processing (min 5)');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->warn("Application ID" . $application->id . " did not have enough votes for processing (min 5)");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$pbar->finish();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
140
app/Console/Commands/CreateUser.php
Executable file
140
app/Console/Commands/CreateUser.php
Executable file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright © 2020 Miguel Nogueira
|
||||
*
|
||||
* This file is part of Raspberry Staff Manager.
|
||||
*
|
||||
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Raspberry Staff Manager is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Facades\UUID;
|
||||
use App\Profile;
|
||||
use App\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class CreateUser extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'users:create';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Creates an application user. Seeding the database is for testing environments, so use this command in production for your first admin user.';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
do {
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
system('cls');
|
||||
} else {
|
||||
system('clear');
|
||||
}
|
||||
|
||||
$this->info('Welcome to the user account creation wizard. If you just installed the application, we recommend you create your first admin user here. If you don\'t, you won\'t gain admin privileges after creating an account in the web interface.');
|
||||
$this->info('We\'ll ask some questions to get you started.');
|
||||
|
||||
$username = $this->ask('Username');
|
||||
do {
|
||||
$password = $this->secret('Password');
|
||||
$password_confirm = $this->secret('Confirm Password');
|
||||
|
||||
if ($password === $password_confirm) {
|
||||
$password = Hash::make($password);
|
||||
$matches = true;
|
||||
} else {
|
||||
$this->error('Password doesn\'t match. Please try again.');
|
||||
$matches = false;
|
||||
}
|
||||
} while (! $matches);
|
||||
|
||||
$email = $this->ask('E-mail address');
|
||||
$name = $this->ask('First/Last Name');
|
||||
|
||||
do {
|
||||
try {
|
||||
$uuid = UUID::toUUID($this->ask('Minecraft username (Must be a valid Premium account)'));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error($e->getMessage());
|
||||
$hasError = true;
|
||||
}
|
||||
|
||||
if (isset($hasError)) {
|
||||
$continue = true;
|
||||
} else {
|
||||
$continue = false;
|
||||
}
|
||||
unset($hasError);
|
||||
} while ($continue);
|
||||
|
||||
$this->info('Please check if these details are correct: ');
|
||||
$this->info('Username: '.$username);
|
||||
$this->info('Email: '.$email);
|
||||
$this->info('Name: '.$name);
|
||||
} while (! $this->confirm('Create user now? You can go back to correct any details.'));
|
||||
|
||||
$user = User::create([
|
||||
'uuid' => $uuid,
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'username' => $username,
|
||||
'originalIP' => '127.0.0.1',
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
if ($user) {
|
||||
$user->assignRole('admin', 'reviewer', 'user', 'hiringManager');
|
||||
Profile::create([
|
||||
'profileShortBio' => 'Random data '.rand(0, 1000),
|
||||
'profileAboutMe' => 'Random data '.rand(0, 1000),
|
||||
'socialLinks' => '[]',
|
||||
'avatarPreference' => 'gravatar',
|
||||
'userID' => $user->id,
|
||||
]);
|
||||
|
||||
$this->info('Account created! You may now login at '.route('login').'. Enjoy the app!');
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
$this->error('There was an unknown problem creating the user. There might have been errors above. Please try again.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
82
app/Console/Commands/MakeFile.php
Executable file
82
app/Console/Commands/MakeFile.php
Executable file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright © 2020 Miguel Nogueira
|
||||
*
|
||||
* This file is part of Raspberry Staff Manager.
|
||||
*
|
||||
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Raspberry Staff Manager is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Faker\Factory;
|
||||
use Faker\Generator;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class MakeFile extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'files:make {count : How many test files to generate}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generates test files for the TeamFile model. Use in conjunction with it\'s factory.';
|
||||
|
||||
/**
|
||||
* The faker instance used to obtain dummy text.
|
||||
*
|
||||
* @var Generator
|
||||
*/
|
||||
private $faker;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->faker = Factory::create();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$count = $this->argument('count');
|
||||
$this->info('Creating '.$this->argument('count').' files!');
|
||||
|
||||
for ($max = 1; $max < $count; $max++) {
|
||||
Storage::disk('local')->put('factory_files/testfile_'.rand(0, 5000).'.txt', $this->faker->paragraphs(40, true));
|
||||
}
|
||||
|
||||
$this->info('Finished creating files! They will be randomly picked by the factory.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
43
app/Console/Commands/SetEnv.php
Normal file → Executable file
43
app/Console/Commands/SetEnv.php
Normal file → Executable file
@@ -1,9 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright © 2020 Miguel Nogueira
|
||||
*
|
||||
* This file is part of Raspberry Staff Manager.
|
||||
*
|
||||
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Raspberry Staff Manager is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use GeoSot\EnvEditor\Facades\EnvEditor;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class SetEnv extends Command
|
||||
{
|
||||
@@ -37,20 +56,16 @@ class SetEnv extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$path = base_path('/.env');
|
||||
$key = $this->argument('key');
|
||||
$value = $this->argument('value');
|
||||
$path = base_path('/.env');
|
||||
$key = $this->argument('key');
|
||||
$value = $this->argument('value');
|
||||
|
||||
if (file_exists($path)) {
|
||||
EnvEditor::editKey($key, $value);
|
||||
} else {
|
||||
$this->error('Cannot update a file that doesn\'t exist! Please create .env first.');
|
||||
|
||||
|
||||
if (file_exists($path))
|
||||
{
|
||||
EnvEditor::editKey($key, $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error('Cannot update a file that doesn\'t exist! Please create .env first.');
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user