Skip to content
This repository was archived by the owner on Mar 26, 2022. It is now read-only.

Commit 2bb351a

Browse files
committed
Release Urán-3.1. Merge branch 'uran-2.x'
2 parents f0cfc7e + 81935a4 commit 2bb351a

File tree

171 files changed

+19300
-69113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+19300
-69113
lines changed

.env.travis

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
APP_NAME=Urán
2+
APP_ENV=testing
3+
APP_KEY=Something
4+
APP_DEBUG=true
5+
APP_URL=http://localhost/
6+
DB_CONNECTION=testing
7+
DB_TEST_USERNAME=root
8+
DB_TEST_PASSWORD=
9+
BCRYPT_ROUNDS=4
10+
CACHE_DRIVER=array
11+
MAIL_DRIVER=array
12+
QUEUE_CONNECTION=sync
13+
SESSION_DRIVER=array
14+
BUGSNAG_API_KEY=randkey

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/node_modules
2+
/public/css
23
/public/hot
4+
/public/js
35
/public/storage
6+
/public/mix-manifest.json
47
/storage/*.key
58
/vendor
69
.env

.travis.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
os:
2+
- linux
3+
language: php
4+
php:
5+
- 7.3
6+
services:
7+
- mysql
8+
cache:
9+
directories:
10+
- node_modules
11+
- vendor
12+
before_script:
13+
- cp .env.travis .env
14+
- sudo mysql -e 'create database homestead;'
15+
- composer self-update
16+
- composer install --prefer-source --no-interaction --dev
17+
- npm install
18+
- npm run dev
19+
- php artisan key:generate
20+
- php artisan migrate
21+
script:
22+
- php artisan test
23+
branches:
24+
only:
25+
- master
26+
- uran-2.x
27+

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ With these steps you should be able to run Mars on your machine:
2424
7. Run `vagrant up`.
2525
8. Get a console to the virtual machine with `vagrant ssh`.
2626
* In the project root (`cd /home/vagrant/mars`) run `composer install` and `php artisan migrate:fresh --seed`.
27+
* Run `npm install` to install JS related dependencies.
28+
* Run `npm run dev` to create the CSS and JS files in the `public` directory.
2729
9. The project should be running at [mars.local](http://mars.local/).
2830

2931
The MySQL database listens on port 3306 in the virtual machine, 33060 is forwarded from the host. See credentials in `.env`.
@@ -33,6 +35,13 @@ The project contains basic configuration for this IDE with the Homestead environ
3335

3436
You can even use XDebug with this setup. Turn on listening for remote debug connections in PHPStorm and use the [XDebug](https://xdebug.org) browser extension in your favourite browser.
3537

38+
### For everyday use
39+
40+
Most of the above setup is a one-time thing to do. However, whenever you start working on based on a newer version, you will have to run the following commands:
41+
42+
* `npm run dev`: In case of recent UI changes (ie. JS or CSS), this will generate the new assets from `webpack.mix.js`. For frontend developers, `npm watch` might be useful -- it does the same, but also updates on change.
43+
* `php artisan migrate:fresh --seed`: This will migrate everything from scratch (useful if you work on changes in parallel) and seeds the database.
44+
3645
## Keep it minimal
3746

3847
The main problem with Urán 1.1 was its *reinventing the wheel* strategy. Laravel provides everything we need. Use it.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
[![Build Status](https://travis-ci.com/luksan47/mars.svg?branch=uran-2.x)](https://travis-ci.com/luksan47/mars)
2+
[![StyleCI](https://github.styleci.io/repos/211704659/shield?branch=uran-2.x&style=plastic)](https://github.styleci.io/repos/211704659)
3+
14
# Mars
25

36
Mars is the [Urán 2.0](https://github.com/kovacsur10/uran) unified information system for Eötvös Collegium. It's a complete
47
rewrite, therefore comes under a new name and repository. Only a few resources are migrated from the Urán system.
58

69
## Architecture
710

8-
Urán is a Laravel based application. For more information, see the [official Laravel documentation](https://laravel.com/docs/6.x).
11+
Urán is a Laravel based application. For more information, see the [official Laravel documentation](https://laravel.com/docs).
912

1013
## Contributions
1114

app/Console/Commands.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace App\Console;
4+
5+
6+
/**
7+
* Collection of exec commands.
8+
* The commands return values accordingly in deug mode as well.
9+
*/
10+
class Commands
11+
{
12+
private static function isDebugMode()
13+
{
14+
return config('app.debug');
15+
}
16+
17+
public static function updateCompletedPrintingJobs()
18+
{
19+
if (self::isDebugMode()) {
20+
$result = [0];
21+
} else {
22+
$result = exec("lpstat -W completed -o " . config('print.printer_name') . " | awk '{print $1}'", $result);
23+
}
24+
return $result;
25+
}
26+
27+
public static function print($command)
28+
{
29+
if (self::isDebugMode()) {
30+
$job_id = 0;
31+
$result = "request id is " . config('print.printer_name') . "-" . $job_id . " (1 file(s))";
32+
} else {
33+
$result = exec($command);
34+
}
35+
return $result;
36+
}
37+
38+
public static function getPages($path)
39+
{
40+
if (self::isDebugMode()) {
41+
$result = rand(1, 10);
42+
} else {
43+
$result = exec("pdfinfo " . $path . " | grep '^Pages' | awk '{print $2}' 2>&1");
44+
}
45+
return $result;
46+
}
47+
}

app/Console/Kernel.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class Kernel extends ConsoleKernel
2424
*/
2525
protected function schedule(Schedule $schedule)
2626
{
27-
// $schedule->command('inspire')
28-
// ->hourly();
27+
$schedule->call(EventTrigger::listen)->hourly();
2928
}
3029

3130
/**

app/EventTrigger.php

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use App\Http\Controllers\SecretariatController;
6+
use Carbon\Carbon;
7+
use Illuminate\Database\Eloquent\Model;
8+
use Illuminate\Support\Facades\Log;
9+
10+
/**
11+
* This class implements the logic of triggering certain (recurring) events (eg. automatic status changes)
12+
* when we reach a given datetime. The triggers will fire a signal that we handle accordingly.
13+
* Members of this models should not get created through the site. It is stored in the database
14+
* so the dates can be changed on the run, everything else should be static.
15+
* The handlers of each signal will do one or two things:
16+
* - Runs the function/does the changes relvant to the event.
17+
* - (only recurring events) Updates the trigger date.
18+
*/
19+
class EventTrigger extends Model
20+
{
21+
public $timestamps = false;
22+
public $incrementing = false;
23+
protected $primaryKey = 'signal';
24+
protected $fillable = [
25+
'name', 'data', 'date', 'signal', 'comment',
26+
];
27+
28+
protected $casts = [
29+
'date' => 'datetime',
30+
];
31+
32+
// Signal for setting the default activation date to the next semester.
33+
const INTERNET_ACTIVATION_SIGNAL = 0;
34+
// Signal for notifying the students to make a statement regarding their status
35+
// in the next semester.
36+
const SEND_STATUS_STATEMENT_REQUEST = 1;
37+
// Deadline for the above signal; when triggered, everyone who did not make a
38+
// statement will be set to inactive.
39+
const DEACTIVATE_STATUS_SIGNAL = 2;
40+
const SIGNALS = [
41+
self::INTERNET_ACTIVATION_SIGNAL,
42+
self::SEND_STATUS_STATEMENT_REQUEST,
43+
self::DEACTIVATE_STATUS_SIGNAL,
44+
];
45+
46+
public static function listen()
47+
{
48+
$now = Carbon::now();
49+
$events = EventTrigger::where('date', '<=', $now)
50+
->where('date', '>', $now->subHours(1));
51+
foreach ($events as $event) {
52+
$event->handleSignal();
53+
}
54+
55+
return $events;
56+
}
57+
58+
/* Getters */
59+
60+
public static function internetActivationDeadline()
61+
{
62+
return self::find(self::INTERNET_ACTIVATION_SIGNAL)->data;
63+
}
64+
65+
public static function statementRequestDate()
66+
{
67+
return self::find(self::SEND_STATUS_STATEMENT_REQUEST)->date;
68+
}
69+
70+
public static function statementDeadline()
71+
{
72+
return self::find(self::DEACTIVATE_STATUS_SIGNAL)->date;
73+
}
74+
75+
/* Handlers which are fired when the set date is reached. */
76+
77+
public function handleSignal()
78+
{
79+
switch ($this->signal) {
80+
case self::INTERNET_ACTIVATION_SIGNAL:
81+
$this->handleInternetActivationSignal();
82+
break;
83+
case self::SEND_STATUS_STATEMENT_REQUEST:
84+
$this->handleSendStatusStatementRequest();
85+
break;
86+
case self::DEACTIVATE_STATUS_SIGNAL:
87+
$this->deactivateStatus();
88+
break;
89+
default:
90+
Log::warning('Event Trigger got undefined signal: '.$this->signal);
91+
break;
92+
}
93+
94+
return $this;
95+
}
96+
97+
private function handleInternetActivationSignal()
98+
{
99+
$months_to_add = Semester::current()->isSpring() ? 7 : 5;
100+
$current_date = Carbon::instance($this->date);
101+
$current_data = Carbon::parse($this->data);
102+
$this->update([
103+
// Update the new trigger date
104+
'date' => $current_date->addMonth($months_to_add),
105+
// Update the new activation deadline
106+
'data' => $current_data->addMonth($months_to_add),
107+
]);
108+
}
109+
110+
private function handleSendStatusStatementRequest()
111+
{
112+
$months_to_add = Semester::current()->isSpring() ? 7 : 5;
113+
$current_date = Carbon::instance($this->date);
114+
115+
// Triggering the event
116+
SecretariatController::sendStatementMail();
117+
118+
$this->update([
119+
// Update the new trigger date
120+
'date' => $current_date->addMonth($months_to_add),
121+
]);
122+
}
123+
124+
private function deactivateStatus()
125+
{
126+
$months_to_add = Semester::current()->isSpring() ? 7 : 5;
127+
$current_date = Carbon::instance($this->date);
128+
129+
// Triggering the event
130+
SecretariatController::finalizeStatements();
131+
132+
$this->update([
133+
// Update the new trigger date
134+
'date' => $current_date->addMonth($months_to_add),
135+
]);
136+
}
137+
}

app/Exceptions/Handler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace App\Exceptions;
44

5-
use Exception;
65
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
6+
use Throwable;
77

88
class Handler extends ExceptionHandler
99
{
@@ -32,7 +32,7 @@ class Handler extends ExceptionHandler
3232
* @param \Exception $exception
3333
* @return void
3434
*/
35-
public function report(Exception $exception)
35+
public function report(Throwable $exception)
3636
{
3737
parent::report($exception);
3838
}
@@ -44,7 +44,7 @@ public function report(Exception $exception)
4444
* @param \Exception $exception
4545
* @return \Illuminate\Http\Response
4646
*/
47-
public function render($request, Exception $exception)
47+
public function render($request, Throwable $exception)
4848
{
4949
return parent::render($request, $exception);
5050
}

app/Http/Controllers/Admin/RegistrationsController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public function accept(Request $request)
2424
{
2525
User::findOrFail($request->user_id)->update(['verified' => true]);
2626

27-
return redirect()->route('admin.registrations');
27+
return redirect()->back()->with('message', __('general.successful_modification'));
2828
}
2929

3030
public function reject(Request $request)
3131
{
3232
User::findOrFail($request->user_id)->delete();
3333

34-
return redirect()->route('admin.registrations');
34+
return redirect()->back()->with('message', __('general.successful_modification'));
3535
}
3636

3737
public function show(Request $request)

0 commit comments

Comments
 (0)