Compare commits

..

8 Commits

Author SHA1 Message Date
Florian Sorg 8c8ef56f73 change link color 2023-07-20 00:38:11 +02:00
Florian Sorg 5b710daaff reset primary color to dark theme default 2023-07-19 23:00:57 +02:00
Florian Sorg 9f0e992bf1 let body background scroll
prevents layout bug in firefox android
2023-07-19 22:46:34 +02:00
Luca a03f60af5e Set body min-height to 100vh 2023-07-07 19:40:35 +02:00
Luca 00fe216dc1 Remove `fixed` from bottom background 2023-07-07 19:30:09 +02:00
Luca f2dc5c8a63 Update symfony/http-foundation due to bug in IpUtils 2023-07-06 00:55:55 +02:00
Florian Sorg ec59c1e567 make IGER theme default 2023-07-04 20:51:03 +02:00
Florian Sorg 24fee1a646 add IGER 2023 theme 2023-07-04 20:36:46 +02:00
460 changed files with 11569 additions and 21743 deletions

View File

@ -27,8 +27,6 @@ max_line_length = unset
indent_size = 2
[*.js]
indent_size = 2
max_line_length = unset
quote_type = single
[{LICENSE,db/*.sql}]

View File

@ -1,10 +1,17 @@
{
"parser": "@babel/eslint-parser",
"extends": ["plugin:editorconfig/all", "prettier"],
"plugins": ["editorconfig"],
"extends": [ "plugin:editorconfig/all" ],
"plugins": [ "editorconfig" ],
"rules": {
"prefer-arrow-callback": "error",
"prefer-template": "error",
"no-var": "error"
"no-var": "error",
"quotes": [
"error",
"single",
{
"avoidEscape": true
}
]
}
}

View File

@ -113,14 +113,7 @@ generate-version:
before_script:
- apk add -q git
script:
- >
VERSION="$(\
git describe --exact-match --tags HEAD 2> /dev/null\
|| (\
(git describe --abbrev=0 --tags | tr -d '\n')\
&& echo "-${CI_COMMIT_REF_NAME}+${CI_PIPELINE_ID}.${CI_COMMIT_SHORT_SHA}"\
)\
)"
- VERSION="$(git describe --abbrev=0 --tags)-${CI_COMMIT_REF_NAME}+${CI_PIPELINE_ID}.${CI_COMMIT_SHORT_SHA}"
- echo "${VERSION}"
- echo -n "${VERSION}" > storage/app/VERSION
@ -162,15 +155,6 @@ yarn lint:
- apk add --no-cache git
- yarn lint
translations lint:
image: alpine
stage: prepare
before_script:
- apk add gettext
script:
- find resources/lang -type f -name '*.po' -exec sh -c 'msgfmt "${1%.*}.po" -o"${1%.*}.mo"' shell {} \;
- '[[ $(find resources/lang -type f -name "*.po" | wc -l) == $(find resources/lang -type f -name "*.mo" | wc -l) ]]'
#
# Build
#
@ -193,7 +177,6 @@ build-image:
- composer validate
- yarn check
- yarn lint
- translations lint
- generate-version
dependencies:
- generate-version
@ -239,7 +222,6 @@ test:
--coverage-text --coverage-html "${HOMEDIR}/coverage/"
--log-junit "${HOMEDIR}/unittests.xml"
after_script:
- sed -i 's~/var/www/~~' unittests.xml
- '"${DOCROOT}/bin/migrate" down'
dump-database:
@ -260,9 +242,6 @@ dump-database:
- cd "${DOCROOT}"
- ./bin/migrate
script:
- >-
mysql -h "${MYSQL_HOST}" -u "${MYSQL_USER}" -p"${MYSQL_PASSWORD}" "${MYSQL_DATABASE}"
-e 'UPDATE users SET api_key="" WHERE name="admin"'
- >-
mysqldump -h "${MYSQL_HOST}" -u "${MYSQL_USER}" -p"${MYSQL_PASSWORD}" "${MYSQL_DATABASE}"
> "${HOMEDIR}/initial-install.sql"
@ -452,8 +431,7 @@ deploy:
GIT_STRATEGY: none
when: manual
script:
- TARGETS=all,ingress,pvc,certificate
- kubectl -n "${KUBE_NAMESPACE}" delete $TARGETS -l app=$CI_PROJECT_PATH_SLUG -l environment=$CI_ENVIRONMENT_SLUG
- kubectl delete all,ingress,pvc -l app=$CI_PROJECT_PATH_SLUG -l environment=$CI_ENVIRONMENT_SLUG
deploy-k8s-review:
<<: *deploy_k8s

View File

@ -13,14 +13,10 @@ Please ensure that your pull requests follow the [PSR-12](https://www.php-fig.or
You can check that by running
```bash
composer run phpcs
# with docker
docker exec engelsystem_dev-es_workspace-1 composer run phpcs
```
You may auto fix reported issues by running
```bash
composer run phpcbf
# with docker
docker exec engelsystem_dev-es_workspace-1 composer run phpcbf
```
## Pre-commit hooks
@ -72,7 +68,7 @@ docker compose exec es_workspace yarn build
docker compose exec -e THEMES=0,1 es_workspace yarn build
# Update the translation files
docker compose exec es_workspace find /var/www/resources/lang -type f -name '*.po' -exec sh -c 'msgfmt "${1%.*}.po" -o"${1%.*}.mo"' shell {} \;
docker compose exec es_workspace find /var/www/resources/lang -type f -name '*.po' -exec sh -c 'file="{}"; msgfmt "${file%.*}.po" -o "${file%.*}.mo"' \;
# Run the migrations
docker compose exec es_workspace bin/migrate
@ -88,11 +84,6 @@ docker compose exec es_workspace yarn build:watch
docker compose exec -e THEMES=0,1 es_workspace yarn build:watch
```
It might also be useful to have an interactive database interface for which a phpMyAdmin instance can be startet at [http://localhost:8888](http://localhost:8888).
```bash
docker compose --profile dev up
```
## Localhost
You can find your local Engelsystem on [http://localhost:5080](http://localhost:5080).
@ -123,7 +114,7 @@ The following instructions explain how to get, build and run the latest Engelsys
```
* Generate translation files
```bash
find resources/lang/ -type f -name '*.po' -exec sh -c 'msgfmt "${1%.*}.po" -o"${1%.*}.mo"' shell {} \;
find resources/lang/ -type f -name '*.po' -exec sh -c 'file="{}"; msgfmt "${file%.*}.po" -o "${file%.*}.mo"' \;
```
## Testing

View File

@ -28,8 +28,6 @@ The Engelsystem may be installed manually or by using the provided [docker setup
* MySQL-Server >= 5.7.8 or MariaDB-Server >= 10.2.2
* Webserver, i.e. lighttpd, nginx, or Apache
From previous experience, 2 cores and 2GB ram are roughly enough for up to 1000 Angels (~700 arrived + 500 arrived but not working) during an event.
### Download
* Go to the [Releases](https://github.com/engelsystem/engelsystem/releases) page and download the latest stable release file.
* Extract the files to your webroot and continue with the directions for configurations and setup.
@ -42,14 +40,7 @@ From previous experience, 2 cores and 2GB ram are roughly enough for up to 1000
* Recommended: Directory Listing should be disabled.
* There must be a MySQL database set up with a user who has full rights to that database.
* If necessary, create a `config/config.php` to override values from `config/config.default.php`.
* To disable/remove values from the following lists, set the value of the entry to `null`:
* `themes`
* `tshirt_sizes`
* `headers`
* `header_items`
* `footer_items`
* `locales`
* `contact_options`
* To edit values from the `footer_items`, `themes`, `locales`, `tshirt_sizes` or `headers` lists, directly modify the `config/config.default.php` file or rename it to `config/config.php`.
* To import the database, the `bin/migrate` script has to be run. If you can't execute scripts, you can use the `initial-install.sql` file from the release zip.
* In the browser, login with credentials `admin` : `asdfasdf` and change the password.
@ -79,8 +70,8 @@ cd docker
docker compose up -d
```
#### Set Up / Migrate Database
Create the Database Schema (on a fresh install) or import database changes to migrate it to the newest version
#### Migrate
Import database changes to migrate it to the newest version
```bash
cd docker
docker compose exec es_server bin/migrate

View File

@ -1,16 +0,0 @@
# Security Policy
## Reporting a Vulnerability
If you want to contact us directly regarding a security concern, please write an e-mail to contact@engelsystem.de and explain your findings.
Thank you!
## Use of external reporting / bug bounty services
We kindly ask you to not use any external reporting / bug bounty service. We do not collaborate with any external service and experiences in the past showed that these services usually add a lot of unnecessary overhead.
Please send security critical bug reports to contact@engelsystem.de.
If you feel like we are not reacting fast enough (generally no more than 14 days should go by until an initial response; This is a volunteer project mostly used internally after all), please feel free to go for full disclosure via our github issue tracker, and tag the issue there by creating a title prefixed with [SECURITY].
If you find a critical vulnerability that warrants a CVE, we will also take care of issuing a CVE without any bug bounty platform having to be involved.

View File

@ -3,24 +3,10 @@
# immediate exit after an error
set -e
testing() {
echo
echo "🔎 Checking ${1}"
}
testing 'JS & CSS 🎨'
yarn check
yarn lint
testing 'PHP ⚙️'
composer validate
composer phpcs
composer phpstan
./vendor/bin/phpunit
testing 'translations 🗺️'
find resources/lang -type f -name '*.po' -exec sh -c 'msgfmt "${1%.*}.po" -o"${1%.*}.mo"' shell {} \;
[ "$(find resources/lang -type f -name '*.po' | wc -l)" -eq "$(find resources/lang -type f -name '*.mo' | wc -l)" ]
find resources/lang -type f -name '*.mo' -exec rm {} \;
echo '✅ Done 🎉'

View File

@ -35,40 +35,38 @@
"ext-pdo": "*",
"ext-simplexml": "*",
"ext-xml": "*",
"doctrine/dbal": "^3.7",
"doctrine/dbal": "^3.5",
"erusev/parsedown": "^1.7",
"gettext/gettext": "^5.7",
"gettext/translator": "^1.2",
"guzzlehttp/guzzle": "^7.8",
"illuminate/container": "^10.38",
"illuminate/database": "^10.38",
"illuminate/support": "^10.38",
"league/oauth2-client": "^2.7",
"league/openapi-psr7-validator": "^0.21",
"gettext/translator": "^1.1",
"guzzlehttp/guzzle": "^7.5",
"illuminate/container": "^9.43",
"illuminate/database": "^9.43",
"illuminate/support": "^9.43",
"league/oauth2-client": "^2.6",
"nikic/fast-route": "^1.3",
"nyholm/psr7": "^1.8",
"nyholm/psr7": "^1.5",
"psr/container": "^2.0",
"psr/http-message": "^1.1",
"psr/http-server-middleware": "^1.0",
"psr/log": "^3.0",
"rcrowe/twigbridge": "^0.14.1",
"rcrowe/twigbridge": "^0.14.0",
"respect/validation": "^1.1",
"symfony/http-foundation": "^6.4",
"symfony/mailer": "^6.4",
"symfony/psr-http-message-bridge": "^2.3",
"twig/twig": "^3.8",
"vlucas/phpdotenv": "^5.6"
"symfony/http-foundation": "^6.2",
"symfony/mailer": "^6.2",
"symfony/psr-http-message-bridge": "^2.1",
"twig/twig": "^3.4",
"vlucas/phpdotenv": "^5.5"
},
"require-dev": {
"dms/phpunit-arraysubset-asserts": "^0.5",
"fakerphp/faker": "^1.23",
"dms/phpunit-arraysubset-asserts": "^0.4",
"fakerphp/faker": "^1.20",
"fig/log-test": "^1.1",
"filp/whoops": "^2.15",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.6",
"slevomat/coding-standard": "^8.14",
"squizlabs/php_codesniffer": "^3.8",
"symfony/var-dumper": "^6.4"
"filp/whoops": "^2.14",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^9.5",
"slevomat/coding-standard": "^8.6",
"squizlabs/php_codesniffer": "^3.7",
"symfony/var-dumper": "^6.2"
},
"autoload": {
"psr-4": {

2480
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,7 @@ return [
\Engelsystem\Renderer\TwigServiceProvider::class,
\Engelsystem\Middleware\RouteDispatcherServiceProvider::class,
\Engelsystem\Middleware\RequestHandlerServiceProvider::class,
\Engelsystem\Middleware\SessionHandlerServiceProvider::class,
\Engelsystem\Http\Validation\ValidationServiceProvider::class,
\Engelsystem\Http\RedirectServiceProvider::class,
@ -37,7 +38,6 @@ return [
\Engelsystem\Http\HttpClientServiceProvider::class,
\Engelsystem\Helpers\DumpServerServiceProvider::class,
\Engelsystem\Helpers\UuidServiceProvider::class,
\Engelsystem\Controllers\Api\UsesAuthServiceProvider::class,
],
// Application middleware
@ -50,11 +50,9 @@ return [
\Engelsystem\Middleware\SetLocale::class,
\Engelsystem\Middleware\ETagHandler::class,
\Engelsystem\Middleware\AddHeaders::class,
\Engelsystem\Middleware\TrimInput::class,
// The application code
\Engelsystem\Middleware\ErrorHandler::class,
\Engelsystem\Middleware\ApiRouteHandler::class,
\Engelsystem\Middleware\VerifyCsrfToken::class,
\Engelsystem\Middleware\RouteDispatcher::class,
\Engelsystem\Middleware\SessionHandler::class,
@ -76,15 +74,12 @@ return [
'message.created' => \Engelsystem\Events\Listener\Messages::class . '@created',
'news.created' => \Engelsystem\Events\Listener\News::class . '@created',
'news.updated' => \Engelsystem\Events\Listener\News::class . '@updated',
'oauth2.login' => \Engelsystem\Events\Listener\OAuth2::class . '@login',
'shift.deleting' => [
\Engelsystem\Events\Listener\Shifts::class . '@deletingCreateWorklogs',
\Engelsystem\Events\Listener\Shifts::class . '@deletingSendEmails',
'shift.entry.deleting' => [
\Engelsystem\Events\Listener\Shift::class . '@deletedEntryCreateWorklog',
\Engelsystem\Events\Listener\Shift::class . '@deletedEntrySendEmail',
],
'shift.updating' => \Engelsystem\Events\Listener\Shifts::class . '@updatedSendEmail',
],
];

View File

@ -26,42 +26,25 @@ return [
'environment' => env('ENVIRONMENT', 'production'),
// Application URL and base path to use instead of the auto-detected one
'url' => env('APP_URL'),
'url' => env('APP_URL', null),
// Header links
// Available link placeholders: %lang%
// To disable a header_item in the config.php, you can set its value to null
'header_items' => [
// Name can be a translation string, permission is a engelsystem privilege
// 'Name' => 'URL',
// 'Name' => ['URL', 'permission'],
//'Foo' => ['https://foo.bar/batz-%lang%.html', 'logout'], // Permission: for logged-in users
//'Foo' => 'https://foo.bar/batz-%lang%.html',
],
// Footer links
// To disable a footer item in the config.php, you can set its value to null
'footer_items' => [
// Name can be a translation string, permission is a engelsystem privilege
// 'Name' => 'URL',
// 'Name' => ['URL', 'permission'],
// URL to the angel faq and job description
'faq.faq' => [env('FAQ_URL', '/faq'), 'faq.view'],
'FAQ' => env('FAQ_URL', '/faq'),
// Contact email address, linked on every page
'Contact' => env('CONTACT_EMAIL', 'mailto:ticket@c3heaven.de'),
],
// Other ways to ask the heaven
// Multiple contact options / links are possible, analogue to footer_items
'contact_options' => [
// E-mail address
'general.email' => env('CONTACT_EMAIL', 'mailto:ticket@c3heaven.de'),
],
// Text displayed on the FAQ page, rendered as markdown
'faq_text' => env('FAQ_TEXT'),
'faq_text' => env('FAQ_TEXT', null),
// Link to documentation/help
'documentation_url' => env('DOCUMENTATION_URL', 'https://engelsystem.de/doc/'),
@ -79,20 +62,17 @@ return [
'host' => env('MAIL_HOST', 'localhost'),
'port' => env('MAIL_PORT', 587),
// If tls transport encryption should be used
'tls' => env('MAIL_TLS'),
'tls' => env('MAIL_TLS', null),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => env('MAIL_SENDMAIL', '/usr/sbin/sendmail -bs'),
],
// Your privacy@ contact address
'privacy_email' => env('PRIVACY_EMAIL'),
// Show opt in to save some personal data after the event on user profile and registration pages
'enable_email_goodie' => (bool) env('ENABLE_EMAIL_GOODIE', true),
# Your privacy@ contact address
'privacy_email' => env('PRIVACY_EMAIL', null),
// Initial admin password
'setup_admin_password' => env('SETUP_ADMIN_PASSWORD'),
'setup_admin_password' => env('SETUP_ADMIN_PASSWORD', null),
'oauth' => [
// '[name]' => [config]
@ -149,18 +129,11 @@ return [
],
// Default theme, 1=style1.css
'theme' => env('THEME', 1),
'theme' => env('THEME', 16),
// Supported themes
// To disable a theme in the config.php, you can set its value to null
'themes' => [
17 => [
'name' => 'Engelsystem 37c3 (2023)',
'type' => 'dark',
'navbar_classes' => 'navbar-dark',
],
16 => [
'name' => 'Engelsystem cccamp23 (2023)',
'name' => 'Engelsystem IGER 2023',
'type' => 'dark',
'navbar_classes' => 'navbar-dark',
],
@ -256,28 +229,12 @@ return [
// Users are able to sign up
'registration_enabled' => (bool) env('REGISTRATION_ENABLED', true),
// URL to external registration page, used on login page
'external_registration_url' => env('EXTERNAL_REGISTRATION_URL'),
// Required user fields
'required_user_fields' => [
'pronoun' => (bool) env('PRONOUN_REQUIRED', false),
'firstname' => (bool) env('FIRSTNAME_REQUIRED', false),
'lastname' => (bool) env('LASTNAME_REQUIRED', false),
'tshirt_size' => (bool) env('TSHIRT_SIZE_REQUIRED', true),
'mobile' => (bool) env('MOBILE_REQUIRED', false),
'dect' => (bool) env('DECT_REQUIRED', false),
],
// Only arrived angels can sign up for shifts
'signup_requires_arrival' => (bool) env('SIGNUP_REQUIRES_ARRIVAL', false),
// Whether newly-registered user should automatically be marked as arrived
'autoarrive' => (bool) env('ANGEL_AUTOARRIVE', false),
// Supporters of an angeltype can promote other angels of the angeltype to supporter
'supporters_can_promote' => (bool) env('SUPPORTERS_CAN_PROMOTE', false),
// Only allow shift signup this number of hours in advance
// Setting this to 0 disables the feature
'signup_advance_hours' => env('SIGNUP_ADVANCE_HOURS', 0),
@ -303,8 +260,9 @@ return [
// The minimum length for passwords
'min_password_length' => env('PASSWORD_MINIMUM_LENGTH', 8),
// Whether the login and registration via password should be enabled (login will be hidden)
// This is useful when using oauth, disabling it also disables normal registration without oauth
// Whether the Password field should be enabled on registration.
// This is useful when using oauth, disabling it also disables normal
// registration without oauth.
'enable_password' => (bool) env('ENABLE_PASSWORD', true),
// Whether the DECT field should be enabled
@ -315,7 +273,7 @@ return [
// Regular expression describing a FALSE username.
// Per default usernames must only contain alphanumeric chars, "-", "_" or ".".
'username_regex' => (string) env('USERNAME_REGEX', '/([^\p{L}\p{N}_.-]+)/ui'),
'username_regex' => (string) env('USERNAME_REGEX', '/([^\p{L}\p{N}\-_.]+)/ui'),
// Enables first name and last name
'enable_user_name' => (bool) env('ENABLE_USER_NAME', false),
@ -330,9 +288,6 @@ return [
// Enables the planned arrival/leave date
'enable_planned_arrival' => (bool) env('ENABLE_PLANNED_ARRIVAL', true),
// Whether force active should be enabled
'enable_force_active' => (bool) env('ENABLE_FORCE_ACTIVE', true),
// Resembles the Goodie Type. There are three options:
// 'none' => no goodie at all
// 'goodie' => a goodie which has no sizing options
@ -351,12 +306,11 @@ return [
// Local timezone
'timezone' => env('TIMEZONE', 'Europe/Berlin'),
// Multiply 'night shifts' and freeloaded shifts (start or end between 2 and 8 exclusive) by 2 in goodie score
// Goodies must be enabled to use this feature
// Multiply 'night shifts' and freeloaded shifts (start or end between 2 and 6 exclusive) by 2
'night_shifts' => [
'enabled' => (bool) env('NIGHT_SHIFTS', true), // Disable to weigh every shift the same
'start' => env('NIGHT_SHIFTS_START', 2), // Starting from hour
'end' => env('NIGHT_SHIFTS_END', 8), // Ends at (without including) hour
'start' => env('NIGHT_SHIFTS_START', 2),
'end' => env('NIGHT_SHIFTS_END', 6),
'multiplier' => env('NIGHT_SHIFTS_MULTIPLIER', 2),
],
@ -366,20 +320,10 @@ return [
'shifts_per_voucher' => env('SHIFTS_PER_VOUCHER', 0),
'hours_per_voucher' => env('HOURS_PER_VOUCHER', 2),
// 'Y-m-d' formatted
'voucher_start' => env('VOUCHER_START') ?: null,
'voucher_start' => env('VOUCHER_START', null) ?: null,
],
// Enables Driving License
'driving_license_enabled' => (bool) env('DRIVING_LICENSE_ENABLED', true),
# Instruction in accordance with § 43 Para. 1 of the German Infection Protection Act (IfSG)
'ifsg_enabled' => (bool) env('IFSG_ENABLED', false),
# Instruction only onsite in accordance with § 43 Para. 1 of the German Infection Protection Act (IfSG)
'ifsg_light_enabled' => env('IFSG_LIGHT_ENABLED', false) && env('IFSG_ENABLED', false),
// Available locales in /resources/lang/
// To disable a locale in the config.php, you can set its value to null
'locales' => [
'de_DE' => 'Deutsch',
'en_US' => 'English',
@ -388,31 +332,21 @@ return [
// The default locale to use
'default_locale' => env('DEFAULT_LOCALE', 'en_US'),
// Available T-Shirt sizes
// To disable a t-shirt size in the config.php, you can set its value to null
// Available T-Shirt sizes, set value to null if not available
'tshirt_sizes' => [
'S' => 'Small Straight-Cut',
'S-F' => 'Small Fitted-Cut',
'S-G' => 'Small Fitted-Cut',
'M' => 'Medium Straight-Cut',
'M-F' => 'Medium Fitted-Cut',
'M-G' => 'Medium Fitted-Cut',
'L' => 'Large Straight-Cut',
'L-F' => 'Large Fitted-Cut',
'L-G' => 'Large Fitted-Cut',
'XL' => 'XLarge Straight-Cut',
'XL-F' => 'XLarge Fitted-Cut',
'XL-G' => 'XLarge Fitted-Cut',
'2XL' => '2XLarge Straight-Cut',
'3XL' => '3XLarge Straight-Cut',
'4XL' => '4XLarge Straight-Cut',
],
// T-shirt Size-Guide link
'tshirt_link' => env('TSHIRT_LINK'),
// Whether to show the current day of the event (-2, -1, 0, 1, 2…) in footer and on the dashboard.
// The event start date has to be set for it to appear.
'enable_show_day_of_event' => (bool) env('ENABLE_SHOW_DAY_OF_EVENT', false),
// If true there will be a day 0 (-1, 0, 1…). If false there won't (-1, 1…)
'event_has_day0' => (bool) env('EVENT_HAS_DAY0', true),
'metrics' => [
// User work buckets in seconds
'work' => [1 * 60 * 60, 1.5 * 60 * 60, 2 * 60 * 60, 3 * 60 * 60, 5 * 60 * 60, 10 * 60 * 60, 20 * 60 * 60],
@ -441,16 +375,11 @@ return [
// Add additional headers
'add_headers' => (bool) env('ADD_HEADERS', true),
// Predefined headers
// To disable a header in the config.php, you can set its value to null
'headers' => [
'X-Content-Type-Options' => 'nosniff',
'X-Frame-Options' => 'sameorigin',
'Referrer-Policy' => 'strict-origin-when-cross-origin',
'Content-Security-Policy' =>
'default-src \'self\'; '
. ' style-src \'self\' \'unsafe-inline\'; '
. 'img-src \'self\' data:;',
'Content-Security-Policy' => 'default-src \'self\' \'unsafe-inline\' \'unsafe-eval\'; img-src \'self\' data:;',
'X-XSS-Protection' => '1; mode=block',
'Feature-Policy' => 'autoplay \'none\'',
//'Strict-Transport-Security' => 'max-age=7776000',

View File

@ -8,8 +8,6 @@ use FastRoute\RouteCollector;
// Pages
$route->get('/', 'HomeController@index');
$route->get('/register', 'RegistrationController@view');
$route->post('/register', 'RegistrationController@save');
$route->get('/credits', 'CreditsController@index');
$route->get('/health', 'HealthController@index');
@ -40,24 +38,7 @@ $route->addGroup(
$route->post('/theme', 'SettingsController@saveTheme');
$route->get('/language', 'SettingsController@language');
$route->post('/language', 'SettingsController@saveLanguage');
$route->get('/certificates', 'SettingsController@certificate');
$route->post('/certificates/ifsg', 'SettingsController@saveIfsgCertificate');
$route->post('/certificates/driving', 'SettingsController@saveDrivingLicense');
$route->get('/api', 'SettingsController@api');
$route->post('/api', 'SettingsController@apiKeyReset');
$route->get('/oauth', 'SettingsController@oauth');
$route->get('/sessions', 'SettingsController@sessions');
$route->post('/sessions', 'SettingsController@sessionsDelete');
}
);
// User admin settings
$route->addGroup(
'/users/{user_id:\d+}',
function (RouteCollector $route): void {
$route->get('/certificates', 'Admin\\UserSettingsController@certificate');
$route->post('/certificates/ifsg', 'Admin\\UserSettingsController@saveIfsgCertificate');
$route->post('/certificates/driving', 'Admin\\UserSettingsController@saveDrivingLicense');
}
);
@ -81,11 +62,6 @@ $route->addGroup('/angeltypes', function (RouteCollector $route): void {
$route->get('/about', 'AngelTypesController@about');
});
// Shifts
$route->addGroup('/shifts', function (RouteCollector $route): void {
$route->get('/random', 'ShiftsController@random');
});
// News
$route->get('/meetings', 'NewsController@meetings');
$route->addGroup(
@ -125,42 +101,7 @@ $route->addGroup(
);
// API
$route->addGroup(
'/api',
function (RouteCollector $route): void {
$route->get('', 'Api\IndexController@index');
$route->addGroup(
'/v0-beta',
function (RouteCollector $route): void {
$route->addRoute(['OPTIONS'], '[/{resource:.+}]', 'Api\IndexController@options');
$route->get('', 'Api\IndexController@indexV0');
$route->get('/openapi', 'Api\IndexController@openApiV0');
$route->get('/info', 'Api\IndexController@info');
$route->get('/angeltypes', 'Api\AngelTypeController@index');
$route->get('/angeltypes/{angeltype_id:\d+}/shifts', 'Api\ShiftsController@entriesByAngeltype');
$route->get('/locations', 'Api\LocationsController@index');
$route->get('/locations/{location_id:\d+}/shifts', 'Api\ShiftsController@entriesByLocation');
$route->get('/news', 'Api\NewsController@index');
$route->get('/users/{user_id:(?:\d+|self)}', 'Api\UsersController@user');
$route->get('/users/{user_id:(?:\d+|self)}/angeltypes', 'Api\AngelTypeController@ofUser');
$route->get('/users/{user_id:(?:\d+|self)}/shifts', 'Api\ShiftsController@entriesByUser');
$route->addRoute(
['POST', 'PUT', 'DELETE', 'PATCH'],
'/[{resource:.+}]',
'Api\IndexController@notImplemented'
);
$route->get('/[{resource:.+}]', 'Api\IndexController@notFound');
}
);
$route->get('/[{resource:.+}]', 'Api\IndexController@notFound');
}
);
$route->get('/api[/{resource:.+}]', 'ApiController@index');
// Feeds
$route->get('/atom', 'FeedController@atom');
@ -197,32 +138,11 @@ $route->addGroup(
$route->addGroup(
'/schedule',
function (RouteCollector $route): void {
$route->get('', 'Admin\\ScheduleController@index');
$route->get('/edit[/{schedule_id:\d+}]', 'Admin\\ScheduleController@edit');
$route->post('/edit[/{schedule_id:\d+}]', 'Admin\\ScheduleController@save');
$route->get('/load/{schedule_id:\d+}', 'Admin\\ScheduleController@loadSchedule');
$route->post('/import/{schedule_id:\d+}', 'Admin\\ScheduleController@importSchedule');
}
);
// Shifts
$route->addGroup(
'/shifts',
function (RouteCollector $route): void {
$route->get('/history', 'Admin\\ShiftsController@history');
$route->post('/history', 'Admin\\ShiftsController@deleteTransaction');
}
);
// Shift types
$route->addGroup(
'/shifttypes',
function (RouteCollector $route): void {
$route->get('', 'Admin\\ShiftTypesController@index');
$route->post('', 'Admin\\ShiftTypesController@delete');
$route->get('/{shift_type_id:\d+}', 'Admin\\ShiftTypesController@view');
$route->get('/edit[/{shift_type_id:\d+}]', 'Admin\\ShiftTypesController@edit');
$route->post('/edit[/{shift_type_id:\d+}]', 'Admin\\ShiftTypesController@save');
$route->get('', 'Admin\\Schedule\\ImportSchedule@index');
$route->get('/edit[/{schedule_id:\d+}]', 'Admin\\Schedule\\ImportSchedule@edit');
$route->post('/edit[/{schedule_id:\d+}]', 'Admin\\Schedule\\ImportSchedule@save');
$route->get('/load/{schedule_id:\d+}', 'Admin\\Schedule\\ImportSchedule@loadSchedule');
$route->post('/import/{schedule_id:\d+}', 'Admin\\Schedule\\ImportSchedule@importSchedule');
}
);
@ -237,14 +157,14 @@ $route->addGroup(
}
);
// Locations
// Rooms
$route->addGroup(
'/locations',
'/rooms',
function (RouteCollector $route): void {
$route->get('', 'Admin\\LocationsController@index');
$route->post('', 'Admin\\LocationsController@delete');
$route->get('/edit[/{location_id:\d+}]', 'Admin\\LocationsController@edit');
$route->post('/edit[/{location_id:\d+}]', 'Admin\\LocationsController@save');
$route->get('', 'Admin\\RoomsController@index');
$route->post('', 'Admin\\RoomsController@delete');
$route->get('/edit[/{room_id:\d+}]', 'Admin\\RoomsController@edit');
$route->post('/edit[/{room_id:\d+}]', 'Admin\\RoomsController@save');
}
);
@ -252,12 +172,12 @@ $route->addGroup(
$route->addGroup(
'/user/{user_id:\d+}',
function (RouteCollector $route): void {
// Goodies
// Shirts
$route->addGroup(
'/goodie',
function (RouteCollector $route): void {
$route->get('', 'Admin\\UserGoodieController@editGoodie');
$route->post('', 'Admin\\UserGoodieController@saveGoodie');
$route->get('', 'Admin\\UserShirtController@editShirt');
$route->post('', 'Admin\\UserShirtController@saveShirt');
}
);

View File

@ -24,11 +24,9 @@ class AngelTypeFactory extends Factory
'restricted' => $this->faker->boolean(),
'requires_driver_license' => $this->faker->boolean(),
'requires_ifsg_certificate' => $this->faker->boolean(),
'shift_self_signup' => $this->faker->boolean(),
'no_self_signup' => $this->faker->boolean(),
'show_on_dashboard' => $this->faker->boolean(),
'hide_register' => $this->faker->boolean(),
'hide_on_shift_view' => $this->faker->boolean(),
];
}
}

View File

@ -16,12 +16,12 @@ class NewsFactory extends Factory
public function definition(): array
{
return [
'title' => $this->faker->text(50),
'text' => $this->faker->realText(),
'is_meeting' => $this->faker->boolean(),
'is_pinned' => $this->faker->boolean(.1),
'is_highlighted' => $this->faker->boolean(.1),
'user_id' => User::factory(),
'title' => $this->faker->text(50),
'text' => $this->faker->realText(),
'is_meeting' => $this->faker->boolean(),
'is_pinned' => $this->faker->boolean(.1),
'is_important' => $this->faker->boolean(.1),
'user_id' => User::factory(),
];
}
}

View File

@ -1,30 +0,0 @@
<?php
declare(strict_types=1);
namespace Database\Factories\Engelsystem\Models;
use Engelsystem\Models\OAuth;
use Engelsystem\Models\User\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class OAuthFactory extends Factory
{
/** @var class-string */
protected $model = OAuth::class; // phpcs:ignore
/**
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'user_id' => User::factory(),
'provider' => $this->faker->unique()->word(),
'identifier' => $this->faker->unique()->word(),
'access_token' => $this->faker->unique()->word(),
'refresh_token' => $this->faker->unique()->word(),
'expires_at' => $this->faker->dateTimeInInterval('+5 days', '+3 months')->format('Y-m-d'),
];
}
}

View File

@ -4,13 +4,13 @@ declare(strict_types=1);
namespace Database\Factories\Engelsystem\Models;
use Engelsystem\Models\Location;
use Engelsystem\Models\Room;
use Illuminate\Database\Eloquent\Factories\Factory;
class LocationFactory extends Factory
class RoomFactory extends Factory
{
/** @var string */
protected $model = Location::class; // phpcs:ignore
protected $model = Room::class; // phpcs:ignore
public function definition(): array
{
@ -18,7 +18,6 @@ class LocationFactory extends Factory
'name' => $this->faker->unique()->firstName(),
'map_url' => $this->faker->url(),
'description' => $this->faker->text(),
'dect' => $this->faker->optional()->numberBetween(1000, 9999),
];
}
}

View File

@ -1,24 +0,0 @@
<?php
declare(strict_types=1);
namespace Database\Factories\Engelsystem\Models;
use Engelsystem\Models\Session;
use Engelsystem\Models\User\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class SessionFactory extends Factory
{
/** @var string */
protected $model = Session::class; // phpcs:ignore
public function definition(): array
{
return [
'id' => $this->faker->lexify('????????????????????????????????'),
'payload' => $this->faker->text(100),
'user_id' => $this->faker->optional()->passthrough(User::factory()),
];
}
}

View File

@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Database\Factories\Engelsystem\Models\Shifts;
use Engelsystem\Models\AngelType;
use Engelsystem\Models\Location;
use Engelsystem\Models\Room;
use Engelsystem\Models\Shifts\NeededAngelType;
use Engelsystem\Models\Shifts\Shift;
use Illuminate\Database\Eloquent\Factories\Factory;
@ -17,12 +17,11 @@ class NeededAngelTypeFactory extends Factory
public function definition(): array
{
$type = $this->faker->numberBetween(0, 2);
$forRoom = $this->faker->boolean();
return [
'location_id' => $type == 0 ? Location::factory() : null,
'shift_id' => $type == 1 ? null : Shift::factory(),
'shift_type_id' => $type == 2 ? null : Shift::factory(),
'room_id' => $forRoom ? Room::factory() : null,
'shift_id' => $forRoom ? null : Shift::factory(),
'angel_type_id' => AngelType::factory(),
'count' => $this->faker->numberBetween(1, 5),
];

View File

@ -18,7 +18,6 @@ class ScheduleFactory extends Factory
'name' => $this->faker->unique()->words(4, true),
'url' => $this->faker->parse('https://{{safeEmailDomain}}/{{slug}}.xml'),
'shift_type' => $this->faker->numberBetween(1, 5),
'needed_from_shift_type' => $this->faker->boolean(.2),
'minutes_before' => 15,
'minutes_after' => 15,
];

View File

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Database\Factories\Engelsystem\Models\Shifts;
use Engelsystem\Models\Location;
use Engelsystem\Models\Room;
use Engelsystem\Models\Shifts\Shift;
use Engelsystem\Models\Shifts\ShiftType;
use Engelsystem\Models\User\User;
@ -25,7 +25,7 @@ class ShiftFactory extends Factory
'start' => $start,
'end' => $this->faker->dateTimeInInterval($start, '+3 hours'),
'shift_type_id' => ShiftType::factory(),
'location_id' => Location::factory(),
'room_id' => Room::factory(),
'transaction_id' => $this->faker->optional()->uuid(),
'created_by' => User::factory(),
'updated_by' => $this->faker->optional(.3)->boolean() ? User::factory() : null,

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Database\Factories\Engelsystem\Models\User;
use Engelsystem\Models\User\Contact;
use Engelsystem\Models\User\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class ContactFactory extends Factory
@ -16,7 +15,6 @@ class ContactFactory extends Factory
public function definition(): array
{
return [
'user_id' => User::factory(),
'dect' => $this->faker->optional()->numberBetween(1000, 9999),
'email' => $this->faker->unique()->optional()->safeEmail(),
'mobile' => $this->faker->optional(.2)->phoneNumber(),

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Database\Factories\Engelsystem\Models\User;
use Engelsystem\Models\User\License;
use Engelsystem\Models\User\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class LicenseFactory extends Factory
@ -21,30 +20,14 @@ class LicenseFactory extends Factory
$drive_12t = $drive_7_5t && $this->faker->boolean(.3);
$drive_forklift = ($drive_car && $this->faker->boolean(.1))
|| ($drive_12t && $this->faker->boolean(.7));
$drive_confirmed = $this->faker->boolean(0.5) && (
$drive_car
|| $drive_3_5t
|| $drive_7_5t
|| $drive_12t
|| $drive_forklift
);
$ifsg_certificate = $this->faker->boolean(0.1);
$ifsg_certificate_light = $this->faker->boolean(0.5) && !$ifsg_certificate;
$ifsg_confirmed = $this->faker->boolean(0.5) && ($ifsg_certificate || $ifsg_certificate_light);
return [
'user_id' => User::factory(),
'has_car' => $drive_car && $this->faker->boolean(.7),
'drive_forklift' => $drive_forklift,
'drive_car' => $drive_car,
'drive_3_5t' => $drive_3_5t,
'drive_7_5t' => $drive_7_5t,
'drive_12t' => $drive_12t,
'drive_confirmed' => $drive_confirmed,
'ifsg_certificate' => $ifsg_certificate,
'ifsg_certificate_light' => $ifsg_certificate_light,
'ifsg_confirmed' => $ifsg_confirmed,
'has_car' => $drive_car && $this->faker->boolean(.7),
'drive_forklift' => $drive_forklift,
'drive_car' => $drive_car,
'drive_3_5t' => $drive_3_5t,
'drive_7_5t' => $drive_7_5t,
'drive_12t' => $drive_12t,
];
}
}

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Database\Factories\Engelsystem\Models\User;
use Engelsystem\Models\User\PasswordReset;
use Engelsystem\Models\User\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class PasswordResetFactory extends Factory
@ -16,7 +15,6 @@ class PasswordResetFactory extends Factory
public function definition(): array
{
return [
'user_id' => User::factory(),
'token' => bin2hex(random_bytes(16)),
];
}

View File

@ -6,7 +6,6 @@ namespace Database\Factories\Engelsystem\Models\User;
use Carbon\Carbon;
use Engelsystem\Models\User\PersonalData;
use Engelsystem\Models\User\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class PersonalDataFactory extends Factory
@ -20,7 +19,6 @@ class PersonalDataFactory extends Factory
$departure = $this->faker->optional()->dateTimeThisMonth('2 weeks');
return [
'user_id' => User::factory(),
'first_name' => $this->faker->optional(.7)->firstName(),
'last_name' => $this->faker->optional()->lastName(),
'pronoun' => $this->faker->optional(.3)->pronoun(),

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Database\Factories\Engelsystem\Models\User;
use Engelsystem\Models\User\Settings;
use Engelsystem\Models\User\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class SettingsFactory extends Factory
@ -16,12 +15,11 @@ class SettingsFactory extends Factory
public function definition(): array
{
return [
'user_id' => User::factory(),
'language' => $this->faker->locale(),
'theme' => $this->faker->numberBetween(1, 20),
'email_human' => $this->faker->boolean(),
'email_messages' => $this->faker->boolean(),
'email_goodie' => $this->faker->boolean(),
'email_goody' => $this->faker->boolean(),
'email_shiftinfo' => $this->faker->boolean(),
'email_news' => $this->faker->boolean(),
'mobile_show' => $this->faker->boolean(),

View File

@ -6,7 +6,6 @@ namespace Database\Factories\Engelsystem\Models\User;
use Carbon\Carbon;
use Engelsystem\Models\User\State;
use Engelsystem\Models\User\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class StateFactory extends Factory
@ -19,13 +18,11 @@ class StateFactory extends Factory
$arrival = $this->faker->optional()->dateTimeThisMonth();
return [
'user_id' => User::factory(),
'arrived' => (bool) $arrival,
'arrival_date' => $arrival ? Carbon::instance($arrival) : null,
'user_info' => $this->faker->optional(.1)->text(),
'active' => $this->faker->boolean(.3),
'force_active' => $this->faker->boolean(.1),
'got_goodie' => $this->faker->boolean(),
'got_shirt' => $this->faker->boolean(),
'got_voucher' => $this->faker->numberBetween(0, 10),
];
}

View File

@ -19,7 +19,6 @@ class UserFactory extends Factory
'password' => crypt(random_bytes(16), '$1$salt$'),
'email' => $this->faker->unique()->safeEmail(),
'api_key' => bin2hex(random_bytes(32)),
'updated_at' => $this->faker->dateTimeInInterval('-3 months', 'now'),
];
}
}

802
db/install.sql Normal file
View File

@ -0,0 +1,802 @@
-- phpMyAdmin SQL Dump
-- version 4.5.2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Erstellungszeit: 27. Sep 2016 um 17:48
-- Server-Version: 10.1.10-MariaDB
-- PHP-Version: 7.0.4
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Datenbank: `engelsystem`
--
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `AngelTypes`
--
DROP TABLE IF EXISTS `AngelTypes`;
CREATE TABLE `AngelTypes` (
`id` int(11) NOT NULL,
`name` varchar(50) NOT NULL DEFAULT '',
`restricted` int(1) NOT NULL,
`description` text NOT NULL,
`requires_driver_license` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `EventConfig`
--
DROP TABLE IF EXISTS `EventConfig`;
CREATE TABLE `EventConfig` (
`event_name` varchar(255) DEFAULT NULL,
`buildup_start_date` int(11) DEFAULT NULL,
`event_start_date` int(11) DEFAULT NULL,
`event_end_date` int(11) DEFAULT NULL,
`teardown_end_date` int(11) DEFAULT NULL,
`event_welcome_msg` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `GroupPrivileges`
--
DROP TABLE IF EXISTS `GroupPrivileges`;
CREATE TABLE `GroupPrivileges` (
`id` int(11) NOT NULL,
`group_id` int(11) NOT NULL,
`privilege_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Daten für Tabelle `GroupPrivileges`
--
INSERT INTO `GroupPrivileges` (`id`, `group_id`, `privilege_id`) VALUES
(85, -7, 10),
(87, -7, 18),
(86, -7, 21),
(216, -6, 5),
(212, -6, 6),
(207, -6, 7),
(211, -6, 12),
(208, -6, 13),
(210, -6, 14),
(214, -6, 16),
(209, -6, 21),
(213, -6, 28),
(206, -6, 31),
(215, -6, 33),
(257, -6, 38),
(219, -5, 14),
(221, -5, 25),
(220, -5, 33),
(241, -4, 5),
(238, -4, 14),
(240, -4, 16),
(237, -4, 19),
(242, -4, 25),
(235, -4, 27),
(239, -4, 28),
(236, -4, 32),
(218, -4, 39),
(258, -3, 31),
(247, -2, 3),
(246, -2, 4),
(255, -2, 8),
(252, -2, 9),
(254, -2, 11),
(248, -2, 15),
(251, -2, 17),
(256, -2, 24),
(253, -2, 26),
(245, -2, 30),
(244, -2, 34),
(249, -2, 35),
(243, -2, 36),
(250, -2, 37),
(88, -1, 1),
(23, -1, 2),
(24, -1, 5);
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `Groups`
--
DROP TABLE IF EXISTS `Groups`;
CREATE TABLE `Groups` (
`Name` varchar(35) NOT NULL,
`UID` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Daten für Tabelle `Groups`
--
INSERT INTO `Groups` (`Name`, `UID`) VALUES
('6-Developer', -7),
('5-Bürokrat', -6),
('4-Team Coordinator', -5),
('3-Shift Coordinator', -4),
('Shirt-Manager', -3),
('2-Engel', -2),
('1-Gast', -1);
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `LogEntries`
--
DROP TABLE IF EXISTS `LogEntries`;
CREATE TABLE `LogEntries` (
`id` int(11) NOT NULL,
`timestamp` int(11) NOT NULL,
`nick` text NOT NULL,
`message` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `Messages`
--
DROP TABLE IF EXISTS `Messages`;
CREATE TABLE `Messages` (
`id` int(11) NOT NULL,
`Datum` int(11) NOT NULL,
`SUID` int(11) NOT NULL DEFAULT '0',
`RUID` int(11) NOT NULL DEFAULT '0',
`isRead` char(1) NOT NULL DEFAULT 'N',
`Text` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Fuers interen Communikationssystem';
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `NeededAngelTypes`
--
DROP TABLE IF EXISTS `NeededAngelTypes`;
CREATE TABLE `NeededAngelTypes` (
`id` int(11) NOT NULL,
`room_id` int(11) DEFAULT NULL,
`shift_id` int(11) DEFAULT NULL,
`angel_type_id` int(11) NOT NULL,
`count` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `News`
--
DROP TABLE IF EXISTS `News`;
CREATE TABLE `News` (
`ID` int(11) NOT NULL,
`Datum` int(11) NOT NULL,
`Betreff` varchar(150) NOT NULL DEFAULT '',
`Text` text NOT NULL,
`UID` int(11) NOT NULL DEFAULT '0',
`Treffen` tinyint(4) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `NewsComments`
--
DROP TABLE IF EXISTS `NewsComments`;
CREATE TABLE `NewsComments` (
`ID` bigint(11) NOT NULL,
`Refid` int(11) NOT NULL DEFAULT '0',
`Datum` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`Text` text NOT NULL,
`UID` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `Privileges`
--
DROP TABLE IF EXISTS `Privileges`;
CREATE TABLE `Privileges` (
`id` int(11) NOT NULL,
`name` varchar(128) NOT NULL,
`desc` varchar(1024) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Daten für Tabelle `Privileges`
--
INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES
(1, 'start', 'Startseite für Gäste/Nicht eingeloggte User'),
(2, 'login', 'Logindialog'),
(3, 'news', 'Anzeigen der News-Seite'),
(4, 'logout', 'User darf sich ausloggen'),
(5, 'register', 'Einen neuen Engel registerieren'),
(6, 'admin_rooms', 'Räume administrieren'),
(7, 'admin_angel_types', 'Engel Typen administrieren'),
(8, 'user_settings', 'User profile settings'),
(9, 'user_messages', 'Writing and reading messages from user to user'),
(10, 'admin_groups', 'Manage usergroups and their rights'),
(11, 'user_questions', 'Let users ask questions'),
(12, 'admin_questions', 'Answer user''s questions'),
(13, 'admin_faq', 'Edit FAQs'),
(14, 'admin_news', 'Administrate the news section'),
(15, 'news_comments', 'User can comment news'),
(16, 'admin_user', 'Administrate the angels'),
(17, 'user_meetings', 'Lists meetings (news)'),
(18, 'admin_language', 'Translate the system'),
(19, 'admin_log', 'Display recent changes'),
(20, 'user_wakeup', 'User wakeup-service organization'),
(21, 'admin_import', 'Import rooms and shifts from pentabarf'),
(22, 'credits', 'View credits'),
(23, 'faq', 'View FAQ'),
(24, 'user_shifts', 'Signup for shifts'),
(25, 'user_shifts_admin', 'Signup other angels for shifts.'),
(26, 'user_myshifts', 'Allow angels to view their own shifts and cancel them.'),
(27, 'admin_arrive', 'Mark angels when they arrive.'),
(28, 'admin_shifts', 'Create shifts'),
(30, 'ical', 'iCal shift export'),
(31, 'admin_active', 'Mark angels as active and if they got a t-shirt.'),
(32, 'admin_free', 'Show a list of free/unemployed angels.'),
(33, 'admin_user_angeltypes', 'Confirm restricted angel types'),
(34, 'atom', ' Atom news export'),
(35, 'shifts_json_export', 'Export shifts in JSON format'),
(36, 'angeltypes', 'View angeltypes'),
(37, 'user_angeltypes', 'Join angeltypes.'),
(38, 'shifttypes', 'Administrate shift types'),
(39, 'admin_event_config', 'Allow editing event config');
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `Questions`
--
DROP TABLE IF EXISTS `Questions`;
CREATE TABLE `Questions` (
`QID` bigint(20) NOT NULL,
`UID` int(11) NOT NULL DEFAULT '0',
`Question` text NOT NULL,
`AID` int(11) DEFAULT NULL,
`Answer` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Fragen und Antworten';
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `Room`
--
DROP TABLE IF EXISTS `Room`;
CREATE TABLE `Room` (
`RID` int(11) NOT NULL,
`Name` varchar(35) NOT NULL DEFAULT '',
`Man` text,
`FromPentabarf` char(1) NOT NULL DEFAULT 'N',
`show` char(1) NOT NULL DEFAULT 'Y',
`Number` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Daten für Tabelle `Room`
--
INSERT INTO `Room` (`RID`, `Name`, `Man`, `FromPentabarf`, `show`, `Number`) VALUES
(1, 'Testraum', NULL, '', 'Y', 0);
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `ShiftEntry`
--
DROP TABLE IF EXISTS `ShiftEntry`;
CREATE TABLE `ShiftEntry` (
`id` int(11) NOT NULL,
`SID` int(11) NOT NULL DEFAULT '0',
`TID` int(11) NOT NULL DEFAULT '0',
`UID` int(11) NOT NULL DEFAULT '0',
`Comment` text,
`freeload_comment` text,
`freeloaded` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `Shifts`
--
DROP TABLE IF EXISTS `Shifts`;
CREATE TABLE `Shifts` (
`SID` int(11) NOT NULL,
`title` text,
`shifttype_id` int(11) NOT NULL,
`start` int(11) NOT NULL,
`end` int(11) NOT NULL,
`RID` int(11) NOT NULL DEFAULT '0',
`URL` text,
`PSID` int(11) DEFAULT NULL,
`created_by_user_id` int(11) DEFAULT NULL,
`created_at_timestamp` int(11) NOT NULL,
`edited_by_user_id` int(11) DEFAULT NULL,
`edited_at_timestamp` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `ShiftTypes`
--
DROP TABLE IF EXISTS `ShiftTypes`;
CREATE TABLE `ShiftTypes` (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`angeltype_id` int(11) DEFAULT NULL,
`description` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Daten für Tabelle `ShiftTypes`
--
INSERT INTO `ShiftTypes` (`id`, `name`, `angeltype_id`, `description`) VALUES
(4, 'Schichttyp1', NULL, '');
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `User`
--
DROP TABLE IF EXISTS `User`;
CREATE TABLE `User` (
`UID` int(11) NOT NULL,
`Nick` varchar(23) NOT NULL DEFAULT '',
`Name` varchar(23) DEFAULT NULL,
`Vorname` varchar(23) DEFAULT NULL,
`Alter` int(4) DEFAULT NULL,
`Telefon` varchar(40) DEFAULT NULL,
`DECT` varchar(5) DEFAULT NULL,
`Handy` varchar(40) DEFAULT NULL,
`email` varchar(123) DEFAULT NULL,
`email_shiftinfo` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'User wants to be informed by mail about changes in his shifts',
`jabber` varchar(200) DEFAULT NULL,
`Size` varchar(4) DEFAULT NULL,
`Passwort` varchar(128) DEFAULT NULL,
`password_recovery_token` varchar(32) DEFAULT NULL,
`Gekommen` tinyint(4) NOT NULL DEFAULT '0',
`Aktiv` tinyint(4) NOT NULL DEFAULT '0',
`force_active` tinyint(1) NOT NULL,
`Tshirt` tinyint(4) DEFAULT '0',
`color` tinyint(4) DEFAULT '10',
`Sprache` char(64) NOT NULL,
`Menu` char(1) NOT NULL DEFAULT 'L',
`lastLogIn` int(11) NOT NULL,
`CreateDate` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`Art` varchar(30) DEFAULT NULL,
`kommentar` text,
`Hometown` varchar(255) NOT NULL DEFAULT '',
`api_key` varchar(32) NOT NULL,
`got_voucher` int(11) NOT NULL,
`arrival_date` int(11) DEFAULT NULL,
`planned_arrival_date` int(11) NOT NULL,
`planned_departure_date` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Daten für Tabelle `User`
--
INSERT INTO `User` (`UID`, `Nick`, `Name`, `Vorname`, `Alter`, `Telefon`, `DECT`, `Handy`, `email`, `email_shiftinfo`, `jabber`, `Size`, `Passwort`, `password_recovery_token`, `Gekommen`, `Aktiv`, `force_active`, `Tshirt`, `color`, `Sprache`, `Menu`, `lastLogIn`, `CreateDate`, `Art`, `kommentar`, `Hometown`, `api_key`, `got_voucher`, `arrival_date`, `planned_arrival_date`, `planned_departure_date`) VALUES
(1, 'admin', 'Gates', 'Bill', 42, '', '-', '', 'admin@example.com', 1, '', 'XL', '$6$rounds=5000$hjXbIhoRTH3vKiRa$Wl2P2iI5T9iRR.HHu/YFHswBW0WVn0yxCfCiX0Keco9OdIoDK6bIAADswP6KvMCJSwTGdV8PgA8g8Xfw5l8BD1', NULL, 1, 1, 0, 1, 0, 'de_DE.UTF-8', 'L', 1474990948, '0001-01-01 00:00:00', '', '', '', '038850abdd1feb264406be3ffa746235', 0, 1439490478, 1436964455, 1440161255);
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `UserAngelTypes`
--
DROP TABLE IF EXISTS `UserAngelTypes`;
CREATE TABLE `UserAngelTypes` (
`id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`angeltype_id` int(11) NOT NULL,
`confirm_user_id` int(11) DEFAULT NULL,
`coordinator` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `UserDriverLicenses`
--
DROP TABLE IF EXISTS `UserDriverLicenses`;
CREATE TABLE `UserDriverLicenses` (
`user_id` int(11) NOT NULL,
`has_car` tinyint(1) NOT NULL,
`has_license_car` tinyint(1) NOT NULL,
`has_license_3_5t_transporter` tinyint(1) NOT NULL,
`has_license_7_5t_truck` tinyint(1) NOT NULL,
`has_license_12_5t_truck` tinyint(1) NOT NULL,
`has_license_forklift` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Daten für Tabelle `UserDriverLicenses`
--
INSERT INTO `UserDriverLicenses` (`user_id`, `has_car`, `has_license_car`, `has_license_3_5t_transporter`, `has_license_7_5t_truck`, `has_license_12_5t_truck`, `has_license_forklift`) VALUES
(1, 1, 1, 1, 1, 1, 1);
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `UserGroups`
--
DROP TABLE IF EXISTS `UserGroups`;
CREATE TABLE `UserGroups` (
`id` int(11) NOT NULL,
`uid` int(11) NOT NULL,
`group_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Daten für Tabelle `UserGroups`
--
INSERT INTO `UserGroups` (`id`, `uid`, `group_id`) VALUES
(3, 1, -7),
(4, 1, -6),
(12, 1, -5),
(2, 1, -4),
(1, 1, -2);
--
-- Indizes der exportierten Tabellen
--
--
-- Indizes für die Tabelle `AngelTypes`
--
ALTER TABLE `AngelTypes`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `Name` (`name`);
--
-- Indizes für die Tabelle `GroupPrivileges`
--
ALTER TABLE `GroupPrivileges`
ADD PRIMARY KEY (`id`),
ADD KEY `group_id` (`group_id`,`privilege_id`),
ADD KEY `privilege_id` (`privilege_id`);
--
-- Indizes für die Tabelle `Groups`
--
ALTER TABLE `Groups`
ADD PRIMARY KEY (`UID`);
--
-- Indizes für die Tabelle `LogEntries`
--
ALTER TABLE `LogEntries`
ADD PRIMARY KEY (`id`),
ADD KEY `timestamp` (`timestamp`);
--
-- Indizes für die Tabelle `Messages`
--
ALTER TABLE `Messages`
ADD PRIMARY KEY (`id`),
ADD KEY `Datum` (`Datum`),
ADD KEY `SUID` (`SUID`),
ADD KEY `RUID` (`RUID`);
--
-- Indizes für die Tabelle `NeededAngelTypes`
--
ALTER TABLE `NeededAngelTypes`
ADD PRIMARY KEY (`id`),
ADD KEY `room_id` (`room_id`,`angel_type_id`),
ADD KEY `shift_id` (`shift_id`),
ADD KEY `angel_type_id` (`angel_type_id`);
--
-- Indizes für die Tabelle `News`
--
ALTER TABLE `News`
ADD PRIMARY KEY (`ID`),
ADD KEY `UID` (`UID`);
--
-- Indizes für die Tabelle `NewsComments`
--
ALTER TABLE `NewsComments`
ADD PRIMARY KEY (`ID`),
ADD KEY `Refid` (`Refid`),
ADD KEY `UID` (`UID`);
--
-- Indizes für die Tabelle `Privileges`
--
ALTER TABLE `Privileges`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `name` (`name`);
--
-- Indizes für die Tabelle `Questions`
--
ALTER TABLE `Questions`
ADD PRIMARY KEY (`QID`),
ADD KEY `UID` (`UID`),
ADD KEY `AID` (`AID`);
--
-- Indizes für die Tabelle `Room`
--
ALTER TABLE `Room`
ADD PRIMARY KEY (`RID`),
ADD UNIQUE KEY `Name` (`Name`);
--
-- Indizes für die Tabelle `ShiftEntry`
--
ALTER TABLE `ShiftEntry`
ADD PRIMARY KEY (`id`),
ADD KEY `TID` (`TID`),
ADD KEY `UID` (`UID`),
ADD KEY `SID` (`SID`,`TID`),
ADD KEY `freeloaded` (`freeloaded`);
--
-- Indizes für die Tabelle `Shifts`
--
ALTER TABLE `Shifts`
ADD PRIMARY KEY (`SID`),
ADD UNIQUE KEY `PSID` (`PSID`),
ADD KEY `RID` (`RID`),
ADD KEY `shifttype_id` (`shifttype_id`),
ADD KEY `created_by_user_id` (`created_by_user_id`),
ADD KEY `edited_by_user_id` (`edited_by_user_id`);
--
-- Indizes für die Tabelle `ShiftTypes`
--
ALTER TABLE `ShiftTypes`
ADD PRIMARY KEY (`id`),
ADD KEY `angeltype_id` (`angeltype_id`);
--
-- Indizes für die Tabelle `User`
--
ALTER TABLE `User`
ADD PRIMARY KEY (`UID`),
ADD UNIQUE KEY `Nick` (`Nick`),
ADD KEY `api_key` (`api_key`),
ADD KEY `password_recovery_token` (`password_recovery_token`),
ADD KEY `force_active` (`force_active`),
ADD KEY `arrival_date` (`arrival_date`,`planned_arrival_date`),
ADD KEY `planned_departure_date` (`planned_departure_date`);
--
-- Indizes für die Tabelle `UserAngelTypes`
--
ALTER TABLE `UserAngelTypes`
ADD PRIMARY KEY (`id`),
ADD KEY `user_id` (`user_id`,`angeltype_id`,`confirm_user_id`),
ADD KEY `angeltype_id` (`angeltype_id`),
ADD KEY `confirm_user_id` (`confirm_user_id`),
ADD KEY `coordinator` (`coordinator`);
--
-- Indizes für die Tabelle `UserDriverLicenses`
--
ALTER TABLE `UserDriverLicenses`
ADD PRIMARY KEY (`user_id`);
--
-- Indizes für die Tabelle `UserGroups`
--
ALTER TABLE `UserGroups`
ADD PRIMARY KEY (`id`),
ADD KEY `uid` (`uid`,`group_id`),
ADD KEY `group_id` (`group_id`);
--
-- AUTO_INCREMENT für exportierte Tabellen
--
--
-- AUTO_INCREMENT für Tabelle `AngelTypes`
--
ALTER TABLE `AngelTypes`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
--
-- AUTO_INCREMENT für Tabelle `GroupPrivileges`
--
ALTER TABLE `GroupPrivileges`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=259;
--
-- AUTO_INCREMENT für Tabelle `LogEntries`
--
ALTER TABLE `LogEntries`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT für Tabelle `Messages`
--
ALTER TABLE `Messages`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT für Tabelle `NeededAngelTypes`
--
ALTER TABLE `NeededAngelTypes`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT für Tabelle `News`
--
ALTER TABLE `News`
MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT für Tabelle `NewsComments`
--
ALTER TABLE `NewsComments`
MODIFY `ID` bigint(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT für Tabelle `Privileges`
--
ALTER TABLE `Privileges`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=40;
--
-- AUTO_INCREMENT für Tabelle `Questions`
--
ALTER TABLE `Questions`
MODIFY `QID` bigint(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT für Tabelle `Room`
--
ALTER TABLE `Room`
MODIFY `RID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT für Tabelle `ShiftEntry`
--
ALTER TABLE `ShiftEntry`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT für Tabelle `Shifts`
--
ALTER TABLE `Shifts`
MODIFY `SID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;
--
-- AUTO_INCREMENT für Tabelle `ShiftTypes`
--
ALTER TABLE `ShiftTypes`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
--
-- AUTO_INCREMENT für Tabelle `User`
--
ALTER TABLE `User`
MODIFY `UID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT für Tabelle `UserAngelTypes`
--
ALTER TABLE `UserAngelTypes`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT für Tabelle `UserGroups`
--
ALTER TABLE `UserGroups`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;
--
-- Constraints der exportierten Tabellen
--
--
-- Constraints der Tabelle `GroupPrivileges`
--
ALTER TABLE `GroupPrivileges`
ADD CONSTRAINT `groupprivileges_ibfk_1` FOREIGN KEY (`group_id`) REFERENCES `Groups` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `groupprivileges_ibfk_2` FOREIGN KEY (`privilege_id`) REFERENCES `Privileges` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints der Tabelle `Messages`
--
ALTER TABLE `Messages`
ADD CONSTRAINT `messages_ibfk_1` FOREIGN KEY (`SUID`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `messages_ibfk_2` FOREIGN KEY (`RUID`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints der Tabelle `NeededAngelTypes`
--
ALTER TABLE `NeededAngelTypes`
ADD CONSTRAINT `neededangeltypes_ibfk_1` FOREIGN KEY (`room_id`) REFERENCES `Room` (`RID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `neededangeltypes_ibfk_2` FOREIGN KEY (`shift_id`) REFERENCES `Shifts` (`SID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `neededangeltypes_ibfk_3` FOREIGN KEY (`angel_type_id`) REFERENCES `AngelTypes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints der Tabelle `News`
--
ALTER TABLE `News`
ADD CONSTRAINT `news_ibfk_1` FOREIGN KEY (`UID`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints der Tabelle `NewsComments`
--
ALTER TABLE `NewsComments`
ADD CONSTRAINT `newscomments_ibfk_1` FOREIGN KEY (`Refid`) REFERENCES `News` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `newscomments_ibfk_2` FOREIGN KEY (`UID`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints der Tabelle `Questions`
--
ALTER TABLE `Questions`
ADD CONSTRAINT `questions_ibfk_1` FOREIGN KEY (`UID`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `questions_ibfk_2` FOREIGN KEY (`AID`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints der Tabelle `ShiftEntry`
--
ALTER TABLE `ShiftEntry`
ADD CONSTRAINT `shiftentry_ibfk_1` FOREIGN KEY (`SID`) REFERENCES `Shifts` (`SID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `shiftentry_ibfk_2` FOREIGN KEY (`UID`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `shiftentry_ibfk_3` FOREIGN KEY (`TID`) REFERENCES `AngelTypes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints der Tabelle `Shifts`
--
ALTER TABLE `Shifts`
ADD CONSTRAINT `shifts_ibfk_1` FOREIGN KEY (`RID`) REFERENCES `Room` (`RID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `shifts_ibfk_2` FOREIGN KEY (`shifttype_id`) REFERENCES `ShiftTypes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `shifts_ibfk_3` FOREIGN KEY (`created_by_user_id`) REFERENCES `User` (`UID`) ON DELETE SET NULL ON UPDATE CASCADE,
ADD CONSTRAINT `shifts_ibfk_4` FOREIGN KEY (`edited_by_user_id`) REFERENCES `User` (`UID`) ON DELETE SET NULL ON UPDATE CASCADE;
--
-- Constraints der Tabelle `ShiftTypes`
--
ALTER TABLE `ShiftTypes`
ADD CONSTRAINT `shifttypes_ibfk_1` FOREIGN KEY (`angeltype_id`) REFERENCES `AngelTypes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints der Tabelle `UserAngelTypes`
--
ALTER TABLE `UserAngelTypes`
ADD CONSTRAINT `userangeltypes_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `userangeltypes_ibfk_2` FOREIGN KEY (`angeltype_id`) REFERENCES `AngelTypes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `userangeltypes_ibfk_3` FOREIGN KEY (`confirm_user_id`) REFERENCES `User` (`UID`) ON DELETE SET NULL ON UPDATE CASCADE;
--
-- Constraints der Tabelle `UserDriverLicenses`
--
ALTER TABLE `UserDriverLicenses`
ADD CONSTRAINT `userdriverlicenses_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints der Tabelle `UserGroups`
--
ALTER TABLE `UserGroups`
ADD CONSTRAINT `usergroups_ibfk_1` FOREIGN KEY (`group_id`) REFERENCES `Groups` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `usergroups_ibfk_2` FOREIGN KEY (`uid`) REFERENCES `User` (`UID`) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -29,9 +29,24 @@ class ImportInstallSql extends Migration
'UserAngelTypes',
'UserDriverLicenses',
'UserGroups',
'UserWorkLog',
];
/**
* Run the migration
*/
public function up(): void
{
foreach ($this->oldTables as $table) {
if ($this->schema->hasTable($table)) {
return;
}
}
$sql = file_get_contents(__DIR__ . '/../install.sql');
$this->schema->getConnection()->unprepared($sql);
}
/**
* Reverse the migration
*/
@ -39,7 +54,6 @@ class ImportInstallSql extends Migration
{
$this->schema->getConnection()->statement('SET FOREIGN_KEY_CHECKS=0;');
// Delete all remaining tables
foreach ($this->oldTables as $table) {
if ($this->schema->hasTable($table)) {
$this->schema->dropIfExists($table);

View File

@ -8,5 +8,24 @@ use Engelsystem\Database\Migration\Migration;
class ImportUpdateSql extends Migration
{
// Do nothing as the tables will be created by later migrations and deleted by ImportInstall
/**
* Run the migration
*/
public function up(): void
{
if ($this->schema->hasTable('UserWorkLog')) {
return;
}
$sql = file_get_contents(__DIR__ . '/../update.sql');
$this->schema->getConnection()->unprepared($sql);
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->dropIfExists('UserWorkLog');
}
}

View File

@ -9,6 +9,7 @@ use Illuminate\Database\Schema\Blueprint;
class ChangeUsersContactDectFieldSize extends Migration
{
/** @var array */
protected array $tables = [
'AngelTypes' => 'contact_dect',
'users_contact' => 'dect',

View File

@ -11,6 +11,7 @@ use stdClass;
class CreateRoomsTable extends Migration
{
use ChangesReferences;
use Reference;
/**
* Run the migration

View File

@ -37,7 +37,6 @@ class CreateWorklogsTable extends Migration
->get();
foreach ($previousRecords as $previousRecord) {
$worked_at = Carbon::createFromTimestamp($previousRecord->work_timestamp);
$created_at = Carbon::createFromTimestamp($previousRecord->created_timestamp);
$this->schema->getConnection()
->table('worklogs')
@ -45,7 +44,7 @@ class CreateWorklogsTable extends Migration
'id' => $previousRecord->id,
'user_id' => $previousRecord->user_id,
'creator_id' => $previousRecord->created_user_id,
'worked_at' => $worked_at,
'worked_at' => $previousRecord->work_timestamp,
'hours' => $previousRecord->work_hours,
'comment' => $previousRecord->comment,
'created_at' => $created_at,
@ -88,11 +87,11 @@ class CreateWorklogsTable extends Migration
->insert([
'id' => $record->id,
'user_id' => $record->user_id,
'work_timestamp' => Carbon::createFromFormat('Y-m-d', $record->worked_at)->timestamp,
'work_timestamp' => $record->worked_at->timestamp,
'work_hours' => $record->hours,
'comment' => $record->comment,
'created_user_id' => $record->creator_id,
'created_timestamp' => Carbon::createFromFormat('Y-m-d H:i:s', $record->created_at)->timestamp,
'created_timestamp' => $record->created_at->timestamp,
]);
}

View File

@ -10,6 +10,8 @@ use Illuminate\Database\Schema\Blueprint;
class AddTimestampsToQuestions extends Migration
{
use ChangesReferences;
/**
* Run the migration
*/

View File

@ -21,7 +21,7 @@ class AddNameMinutesAndTimestampsToSchedules extends Migration
$this->schema->table('schedules', function (Blueprint $table): void {
$table->string('name')->default('')->after('id');
$table->unsignedInteger('shift_type')->default(0)->after('name');
$table->integer('shift_type')->default(0)->after('name');
$table->integer('minutes_before')->default(0)->after('shift_type');
$table->integer('minutes_after')->default(0)->after('minutes_before');
$table->timestamps();
@ -36,7 +36,7 @@ class AddNameMinutesAndTimestampsToSchedules extends Migration
$this->schema->table('schedules', function (Blueprint $table): void {
$table->string('name')->default(null)->change();
$table->unsignedInteger('shift_type')->default(null)->change();
$table->integer('shift_type')->default(null)->change();
$table->integer('minutes_before')->default(null)->change();
$table->integer('minutes_after')->default(null)->change();
});

View File

@ -9,6 +9,8 @@ use Illuminate\Database\Schema\Blueprint;
class AddEmailNewsToUsersSettings extends Migration
{
use Reference;
/**
* Run the migration
*/

View File

@ -9,6 +9,8 @@ use Illuminate\Database\Schema\Blueprint;
class OauthAddTokens extends Migration
{
use Reference;
/**
* Run the migration
*/

View File

@ -9,6 +9,8 @@ use Illuminate\Database\Schema\Blueprint;
class NewsAddIsPinned extends Migration
{
use Reference;
/**
* Run the migration
*/

View File

@ -9,6 +9,8 @@ use Illuminate\Database\Schema\Blueprint;
class OauthChangeTokensToText extends Migration
{
use Reference;
/**
* Run the migration
*/

View File

@ -1,45 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Config\Config;
use Engelsystem\Database\Migration\Migration;
use Engelsystem\Helpers\Carbon;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
use stdClass;
class CreateFirstUser extends Migration
{
public function __construct(SchemaBuilder $schemaBuilder, protected Config $config)
{
parent::__construct($schemaBuilder);
}
/**
* Run the migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
if ($db->table('users')->count() > 0) {
return;
}
$db->table('users')->insert([
'name' => 'admin',
'email' => 'admin@localhost',
'password' => password_hash('asdfasdf', PASSWORD_DEFAULT),
'api_key' => bin2hex(random_bytes(16)),
'created_at' => Carbon::now(),
]);
/** @var stdClass $admin */
$admin = $db->table('users')->where('name', 'admin')->first();
foreach (['users_contact', 'users_personal_data', 'users_state'] as $table) {
$db->table($table)->insert(['user_id' => $admin->id]);
}
$db->table('users_settings')->insert(['user_id' => $admin->id, 'language' => 'en_US', 'theme' => 0]);
}
}

View File

@ -6,12 +6,14 @@ namespace Engelsystem\Migrations;
use Engelsystem\Config\Config;
use Engelsystem\Database\Migration\Migration;
use Engelsystem\Helpers\Authenticator;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
use stdClass;
class SetAdminPassword extends Migration
{
public function __construct(SchemaBuilder $schemaBuilder, protected Config $config)
use Reference;
public function __construct(SchemaBuilder $schemaBuilder, protected Authenticator $auth, protected Config $config)
{
parent::__construct($schemaBuilder);
}
@ -21,21 +23,12 @@ class SetAdminPassword extends Migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
/** @var stdClass $admin */
$admin = $db->table('users')->where('name', 'admin')->first();
$admin = $this->auth->authenticate('admin', 'asdfasdf');
$setupPassword = $this->config->get('setup_admin_password');
if (
!$admin
|| !password_verify('asdfasdf', $admin->password)
|| !$setupPassword
) {
if (!$admin || !$setupPassword) {
return;
}
$db->table('users')
->where('id', $admin->id)
->update(['password' => password_hash($setupPassword, PASSWORD_DEFAULT)]);
$this->auth->setPassword($admin, $setupPassword);
}
}

View File

@ -9,6 +9,8 @@ use Illuminate\Database\Schema\Blueprint;
class AddShiftsDescription extends Migration
{
use Reference;
/**
* Run the migration
*/

View File

@ -9,6 +9,8 @@ use Illuminate\Database\Schema\Blueprint;
class UsersSettingsAddEmailGoody extends Migration
{
use Reference;
/**
* Run the migration
*/

View File

@ -1,158 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use stdClass;
class FillPrivilegesAndGroupsRelatedTables extends Migration
{
/**
* Inserts missing data into permissions & groups related tables
*/
public function up(): void
{
$db = $this->schema->getConnection();
if ($db->table('privileges')->count() > 0) {
return;
}
$db->table('groups')
->insert([
['id' => 10, 'name' => 'Guest'],
['id' => 20, 'name' => 'Angel'],
['id' => 30, 'name' => 'Welcome Angel'],
['id' => 35, 'name' => 'Voucher Angel'],
['id' => 50, 'name' => 'Shirt Manager'],
['id' => 60, 'name' => 'Shift Coordinator'],
['id' => 65, 'name' => 'Team Coordinator'],
['id' => 80, 'name' => 'Bureaucrat'],
['id' => 85, 'name' => 'News Admin'],
['id' => 90, 'name' => 'Developer'],
]);
$db->table('privileges')
->insert([
['id' => 1, 'name' => 'start', 'description' => 'Startseite für Gäste/Nicht eingeloggte User'],
['id' => 2, 'name' => 'login', 'description' => 'Logindialog'],
['id' => 3, 'name' => 'news', 'description' => 'Anzeigen der News-Seite'],
['id' => 4, 'name' => 'logout', 'description' => 'User darf sich ausloggen'],
['id' => 5, 'name' => 'register', 'description' => 'Einen neuen Engel registerieren'],
['id' => 6, 'name' => 'admin_rooms', 'description' => 'Räume administrieren'],
['id' => 7, 'name' => 'admin_angel_types', 'description' => 'Engel Typen administrieren'],
['id' => 8, 'name' => 'user_settings', 'description' => 'User profile settings'],
['id' => 9, 'name' => 'user_messages',
'description' => 'Writing and reading messages from user to user'],
['id' => 10, 'name' => 'admin_groups', 'description' => 'Manage usergroups and their rights'],
['id' => 14, 'name' => 'admin_news', 'description' => 'Administrate the news section'],
['id' => 15, 'name' => 'news_comments', 'description' => 'User can comment news'],
['id' => 16, 'name' => 'admin_user', 'description' => 'Administrate the angels'],
['id' => 17, 'name' => 'user_meetings', 'description' => 'Lists meetings (news)'],
['id' => 18, 'name' => 'admin_language', 'description' => 'Translate the system'],
['id' => 19, 'name' => 'admin_log', 'description' => 'Display recent changes'],
['id' => 21, 'name' => 'schedule.import', 'description' => 'Import rooms and shifts from schedule.xml'],
['id' => 24, 'name' => 'user_shifts', 'description' => 'Signup for shifts'],
['id' => 25, 'name' => 'user_shifts_admin', 'description' => 'Signup other angels for shifts.'],
['id' => 26, 'name' => 'user_myshifts',
'description' => 'Allow angels to view their own shifts and cancel them.'],
['id' => 27, 'name' => 'admin_arrive', 'description' => 'Mark angels when they arrive.'],
['id' => 28, 'name' => 'admin_shifts', 'description' => 'Create shifts'],
['id' => 30, 'name' => 'ical', 'description' => 'iCal shift export'],
['id' => 31, 'name' => 'admin_active',
'description' => 'Mark angels as active and if they got a t-shirt.'],
['id' => 32, 'name' => 'admin_free', 'description' => 'Show a list of free/unemployed angels.'],
['id' => 33, 'name' => 'admin_user_angeltypes', 'description' => 'Confirm restricted angel types'],
['id' => 34, 'name' => 'atom', 'description' => ' Atom news export'],
['id' => 35, 'name' => 'shifts_json_export', 'description' => 'Export shifts in JSON format'],
['id' => 36, 'name' => 'angeltypes', 'description' => 'View angeltypes'],
['id' => 37, 'name' => 'user_angeltypes', 'description' => 'Join angeltypes.'],
['id' => 38, 'name' => 'shifttypes', 'description' => 'Administrate shift types'],
['id' => 39, 'name' => 'admin_event_config', 'description' => 'Allow editing event config'],
['id' => 40, 'name' => 'view_rooms', 'description' => 'User can view rooms'],
['id' => 41, 'name' => 'shiftentry_edit_angeltype_supporter',
'description' => 'If user with this privilege is angeltype supporter, '
. 'he can put users in shifts for their angeltype'],
['id' => 43, 'name' => 'admin_user_worklog', 'description' => 'Manage user work log entries.'],
['id' => 44, 'name' => 'faq.view', 'description' => 'View FAQ entries'],
['id' => 45, 'name' => 'faq.edit', 'description' => 'Edit FAQ entries'],
['id' => 46, 'name' => 'question.add', 'description' => 'Ask questions'],
['id' => 47, 'name' => 'question.edit', 'description' => 'Answer questions'],
['id' => 48, 'name' => 'user.edit.shirt', 'description' => 'Edit user shirts'],
['id' => 49, 'name' => 'voucher.edit', 'description' => 'Edit vouchers'],
]);
$db->table('group_privileges')->insert([
['id' => 23, 'group_id' => 10, 'privilege_id' => 2],
['id' => 24, 'group_id' => 10, 'privilege_id' => 5],
['id' => 85, 'group_id' => 90, 'privilege_id' => 10],
['id' => 86, 'group_id' => 90, 'privilege_id' => 21],
['id' => 87, 'group_id' => 90, 'privilege_id' => 18],
['id' => 88, 'group_id' => 10, 'privilege_id' => 1],
['id' => 206, 'group_id' => 80, 'privilege_id' => 31],
['id' => 207, 'group_id' => 80, 'privilege_id' => 7],
['id' => 209, 'group_id' => 80, 'privilege_id' => 21],
['id' => 210, 'group_id' => 80, 'privilege_id' => 14],
['id' => 212, 'group_id' => 80, 'privilege_id' => 6],
['id' => 213, 'group_id' => 80, 'privilege_id' => 28],
['id' => 214, 'group_id' => 80, 'privilege_id' => 16],
['id' => 215, 'group_id' => 80, 'privilege_id' => 33],
['id' => 216, 'group_id' => 80, 'privilege_id' => 5],
['id' => 218, 'group_id' => 60, 'privilege_id' => 39],
['id' => 219, 'group_id' => 65, 'privilege_id' => 14],
['id' => 220, 'group_id' => 65, 'privilege_id' => 33],
['id' => 221, 'group_id' => 65, 'privilege_id' => 25],
['id' => 235, 'group_id' => 60, 'privilege_id' => 27],
['id' => 236, 'group_id' => 60, 'privilege_id' => 32],
['id' => 237, 'group_id' => 60, 'privilege_id' => 19],
['id' => 238, 'group_id' => 60, 'privilege_id' => 14],
['id' => 239, 'group_id' => 60, 'privilege_id' => 28],
['id' => 240, 'group_id' => 60, 'privilege_id' => 16],
['id' => 241, 'group_id' => 60, 'privilege_id' => 5],
['id' => 242, 'group_id' => 60, 'privilege_id' => 25],
['id' => 243, 'group_id' => 20, 'privilege_id' => 36],
['id' => 244, 'group_id' => 20, 'privilege_id' => 34],
['id' => 245, 'group_id' => 20, 'privilege_id' => 30],
['id' => 246, 'group_id' => 20, 'privilege_id' => 4],
['id' => 247, 'group_id' => 20, 'privilege_id' => 3],
['id' => 248, 'group_id' => 20, 'privilege_id' => 15],
['id' => 249, 'group_id' => 20, 'privilege_id' => 35],
['id' => 250, 'group_id' => 20, 'privilege_id' => 37],
['id' => 251, 'group_id' => 20, 'privilege_id' => 17],
['id' => 252, 'group_id' => 20, 'privilege_id' => 9],
['id' => 253, 'group_id' => 20, 'privilege_id' => 26],
['id' => 255, 'group_id' => 20, 'privilege_id' => 8],
['id' => 256, 'group_id' => 20, 'privilege_id' => 24],
['id' => 257, 'group_id' => 80, 'privilege_id' => 38],
['id' => 258, 'group_id' => 50, 'privilege_id' => 31],
['id' => 259, 'group_id' => 20, 'privilege_id' => 40],
['id' => 260, 'group_id' => 85, 'privilege_id' => 14],
['id' => 262, 'group_id' => 60, 'privilege_id' => 43],
['id' => 263, 'group_id' => 20, 'privilege_id' => 41],
['id' => 264, 'group_id' => 30, 'privilege_id' => 27],
['id' => 265, 'group_id' => 10, 'privilege_id' => 44],
['id' => 266, 'group_id' => 20, 'privilege_id' => 44],
['id' => 267, 'group_id' => 60, 'privilege_id' => 45],
['id' => 268, 'group_id' => 20, 'privilege_id' => 46],
['id' => 269, 'group_id' => 60, 'privilege_id' => 47],
['id' => 270, 'group_id' => 60, 'privilege_id' => 48],
['id' => 271, 'group_id' => 50, 'privilege_id' => 48],
['id' => 272, 'group_id' => 50, 'privilege_id' => 27],
['id' => 273, 'group_id' => 60, 'privilege_id' => 49],
['id' => 274, 'group_id' => 35, 'privilege_id' => 49],
['id' => 275, 'group_id' => 35, 'privilege_id' => 27],
]);
/** @var stdClass $admin */
$admin = $db->table('users')->where('name', 'admin')->first();
if (!$admin) {
return;
}
// Angel, ShiCo, Team coordinator, Bureaucrat, Dev
foreach ([20, 60, 65, 80, 90] as $group) {
$db->table('users_groups')->insert(['user_id' => $admin->id, 'group_id' => $group]);
}
}
}

View File

@ -6,7 +6,6 @@ namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Str;
class ChangeApiKeyLength extends Migration
{
@ -25,19 +24,6 @@ class ChangeApiKeyLength extends Migration
*/
public function down(): void
{
$connection = $this->schema->getConnection();
$data = $connection->table('users')->get(['id', 'api_key']);
foreach ($data as $user) {
if (Str::length($user->api_key) <= 32) {
continue;
}
$key = Str::substr($user->api_key, 0, 32);
$connection->table('users')
->where('id', $user->id)
->update(['api_key' => $key]);
}
$this->schema->table('users', function (Blueprint $table): void {
$table->string('api_key', 32)->change();
});

View File

@ -9,6 +9,8 @@ use Illuminate\Database\Schema\Blueprint;
class AddEmailMessagesToUsersSettings extends Migration
{
use Reference;
/**
* Run the migration
*/

View File

@ -1,45 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
class CreateApiPermissions extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')->insert([
['name' => 'api', 'description' => 'Use the API'],
]);
$db->table('groups')->insert([
['id' => 40, 'name' => 'API'],
]);
$bureaucratGroup = 80;
$apiId = $db->table('privileges')->where('name', 'api')->first()->id;
$db->table('group_privileges')->insert([
['group_id' => $bureaucratGroup, 'privilege_id' => $apiId],
['group_id' => 40, 'privilege_id' => $apiId],
]);
}
/**
* Reverse the migration
*/
public function down(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->where('name', 'api')
->delete();
$db->table('groups')
->where('id', 40)
->delete();
}
}

View File

@ -1,28 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Support\Str;
class CleanupShortApiKeys extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
foreach ($db->table('users')->get() as $user) {
if (Str::length($user->api_key) > 42) {
continue;
}
$db->table('users')
->where('id', $user->id)
->update(['api_key' => bin2hex(random_bytes(32))]);
}
}
}

View File

@ -1,33 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddIfsgCerificatesToUsersLicenses extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('users_licenses', function (Blueprint $table): void {
$table->boolean('ifsg_certificate_light')->default(false)->after('drive_12t');
$table->boolean('ifsg_certificate')->default(false)->after('ifsg_certificate_light');
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('users_licenses', function (Blueprint $table): void {
$table->dropColumn('ifsg_certificate_light');
$table->dropColumn('ifsg_certificate');
});
}
}

View File

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddRequiresIfsgCerificateToAngeltypes extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('angel_types', function (Blueprint $table): void {
$table->boolean('requires_ifsg_certificate')->default(false)->after('requires_driver_license');
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('angel_types', function (Blueprint $table): void {
$table->dropColumn('requires_ifsg_certificate');
});
}
}

View File

@ -1,39 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AngeltypesRenameNoSelfSignupToShiftSelfSignup extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('angel_types', function (Blueprint $table): void {
$table->renameColumn('no_self_signup', 'shift_self_signup')->default(true);
$connection = $this->schema->getConnection();
$connection->table('angel_types')
->update(['no_self_signup' => $connection->raw('NOT no_self_signup'),
]);
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('angel_types', function (Blueprint $table): void {
$table->renameColumn('shift_self_signup', 'no_self_signup');
$connection = $this->schema->getConnection();
$connection->table('angel_types')
->update(['shift_self_signup' => $connection->raw('NOT shift_self_signup'),
]);
});
}
}

View File

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddHideOnShiftViewToAngeltypes extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('angel_types', function (Blueprint $table): void {
$table->boolean('hide_on_shift_view')->default(false)->after('hide_register');
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('angel_types', function (Blueprint $table): void {
$table->dropColumn('hide_on_shift_view');
});
}
}

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddUserToSessionsTable extends Migration
{
use Reference;
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('sessions', function (Blueprint $table): void {
$this->referencesUser($table)->nullable()->index()->after('payload');
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('sessions', function (Blueprint $table): void {
$table->dropForeign('sessions_user_id_foreign');
$table->dropColumn('user_id');
});
}
}

View File

@ -1,41 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class NewsRenameImportantToHighlight extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('news', function (Blueprint $table): void {
$table->renameColumn('is_important', 'is_highlighted');
});
$this->schema->getConnection()
->table('privileges')
->where('name', 'news.important')
->update(['name' => 'news.highlight', 'description' => 'Highlight News']);
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('news', function (Blueprint $table): void {
$table->renameColumn('is_highlighted', 'is_important');
});
$this->schema->getConnection()
->table('privileges')
->where('name', 'news.highlight')
->update(['name' => 'news.important', 'description' => 'Make News Important']);
}
}

View File

@ -1,69 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class RenameRoomsToLocations extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->schema->rename('rooms', 'locations');
$this->schema->table('shifts', function (Blueprint $table): void {
$table->renameColumn('room_id', 'location_id');
});
$this->schema->table('needed_angel_types', function (Blueprint $table): void {
$table->renameColumn('room_id', 'location_id');
});
$db = $this->schema->getConnection();
$db->table('privileges')->where('name', 'admin_rooms')->update([
'name' => 'admin_locations',
'description' => 'Manage locations',
]);
$db->table('privileges')->where('name', 'view_rooms')->update([
'name' => 'view_locations',
'description' => 'User can view locations',
]);
$db->table('privileges')->where('name', 'schedule.import')->update([
'description' => 'Import locations and shifts from schedule.xml',
]);
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->rename('locations', 'rooms');
$this->schema->table('shifts', function (Blueprint $table): void {
$table->renameColumn('location_id', 'room_id');
});
$this->schema->table('needed_angel_types', function (Blueprint $table): void {
$table->renameColumn('location_id', 'room_id');
});
$db = $this->schema->getConnection();
$db->table('privileges')->where('name', 'admin_locations')->update([
'name' => 'admin_rooms',
'description' => 'Räume administrieren',
]);
$db->table('privileges')->where('name', 'view_locations')->update([
'name' => 'view_rooms',
'description' => 'User can view rooms',
]);
$db->table('privileges')->where('name', 'schedule.import')->update([
'description' => 'Import rooms and shifts from schedule.xml',
]);
}
}

View File

@ -1,39 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddMissingScheduleForeignKeys extends Migration
{
use Reference;
/**
* Run the migration
*/
public function up(): void
{
$schemaManager = $this->schema->getConnection()->getDoctrineSchemaManager();
$hasShiftTypeReference = $schemaManager->introspectTable('schedules')
->hasIndex('schedules_shift_type_foreign');
if (!$hasShiftTypeReference) {
$this->schema->table('schedules', function (Blueprint $table): void {
$table->unsignedInteger('shift_type')->change();
$this->addReference($table, 'shift_type', 'shift_types');
});
}
$hasShiftIdReference = $schemaManager->introspectTable('schedule_shift')
->hasIndex('schedule_shift_schedule_id_foreign');
if (!$hasShiftIdReference) {
$this->schema->table('schedule_shift', function (Blueprint $table): void {
$table->unsignedInteger('shift_id')->change();
$this->addReference($table, 'shift_id', 'shifts');
});
}
}
}

View File

@ -1,50 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
class DegenderShirtSizes extends Migration
{
/** @var string[] */
protected array $sizes = [
'S-G' => 'S-F',
'M-G' => 'M-F',
'L-G' => 'L-F',
'XL-G' => 'XL-F',
];
/**
* Run the migration
*/
public function up(): void
{
$this->migrate($this->sizes);
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->migrate(array_flip($this->sizes));
}
/**
* @param string[] $sizes
*/
private function migrate(array $sizes): void
{
$connection = $this->schema->getConnection();
foreach ($sizes as $from => $to) {
$connection
->table('users_personal_data')
->where('shirt_size', $from)
->update([
'shirt_size' => $to,
]);
}
}
}

View File

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddUserInfoToUsersState extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('users_state', function (Blueprint $table): void {
$table->string('user_info')->nullable()->default(null)->after('arrival_date');
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('users_state', function (Blueprint $table): void {
$table->dropColumn('user_info');
});
}
}

View File

@ -1,52 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
class AddUserInfoPermissions extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->insert([
['name' => 'user.info.show', 'description' => 'Show User Info'],
['name' => 'user.info.edit', 'description' => 'Edit User Info'],
]);
$showUserInfo = $db->table('privileges')
->where('name', 'user.info.show')
->get(['id'])
->first();
$editUserInfo = $db->table('privileges')
->where('name', 'user.info.edit')
->get(['id'])
->first();
$buerocrat = 80;
$shico = 60;
$db->table('group_privileges')
->insertOrIgnore([
['group_id' => $buerocrat, 'privilege_id' => $editUserInfo->id],
['group_id' => $shico, 'privilege_id' => $showUserInfo->id],
]);
}
/**
* Reverse the migration
*/
public function down(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->whereIn('name', ['user.info.edit', 'user.info.show'])
->delete();
}
}

View File

@ -1,38 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddUserIdToLogEntries extends Migration
{
use Reference;
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('log_entries', function (Blueprint $table): void {
$table->unsignedInteger('user_id')->after('id')->nullable()->default(null);
$table->foreign('user_id')
->references('id')->on('users')
->onUpdate('cascade')
->nullOnDelete();
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('log_entries', function (Blueprint $table): void {
$table->dropForeign('log_entries_user_id_foreign');
$table->dropColumn('user_id');
});
}
}

View File

@ -1,57 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
class ChangeEditShirtRequireBureaucrat extends Migration
{
protected int $bureaucrat = 80;
protected int $shiCo = 60;
protected int $editShirt;
protected Connection $db;
public function __construct(SchemaBuilder $schema)
{
parent::__construct($schema);
$this->db = $this->schema->getConnection();
$this->editShirt = $this->db->table('privileges')
->where('name', 'user.edit.shirt')
->get(['id'])
->first()->id;
}
/**
* Run the migration
*/
public function up(): void
{
$this->movePermission($this->editShirt, $this->shiCo, $this->bureaucrat);
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->movePermission($this->editShirt, $this->bureaucrat, $this->shiCo);
}
protected function movePermission(int $privilege, int $oldGroup, int $newGroup): void
{
$this->db->table('group_privileges')
->insertOrIgnore(['group_id' => $newGroup, 'privilege_id' => $privilege]);
$this->db->table('group_privileges')
->where(['group_id' => $oldGroup, 'privilege_id' => $privilege])
->delete();
}
}

View File

@ -1,44 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
class AddLogsAllPermission extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->insert([
['name' => 'logs.all', 'description' => 'View all logs'],
]);
$logsAll = $db->table('privileges')
->where('name', 'logs.all')
->get(['id'])
->first();
$bureaucrat = 80;
$db->table('group_privileges')
->insertOrIgnore([
['group_id' => $bureaucrat, 'privilege_id' => $logsAll->id],
]);
}
/**
* Reverse the migration
*/
public function down(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->where('name', 'logs.all')
->delete();
}
}

View File

@ -1,40 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class ScheduleShiftTypeNeededAngelTypes extends Migration
{
use Reference;
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('schedules', function (Blueprint $table): void {
$table->boolean('needed_from_shift_type')->after('shift_type')->default(false);
});
$this->schema->table('needed_angel_types', function (Blueprint $table): void {
$this->references($table, 'shift_types')->after('shift_id')->nullable();
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('schedules', function (Blueprint $table): void {
$table->dropColumn('needed_from_shift_type');
});
$this->schema->table('needed_angel_types', function (Blueprint $table): void {
$table->dropForeign('needed_angel_types_shift_type_id_foreign');
$table->dropColumn('shift_type_id');
});
}
}

View File

@ -1,44 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
class AddUserEditPermission extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->insert([
'name' => 'user.edit', 'description' => 'Edit user',
]);
$editUser = $db->table('privileges')
->where('name', 'user.edit')
->get(['id'])
->first();
$buerocrat = 80;
$db->table('group_privileges')
->insertOrIgnore([
'group_id' => $buerocrat, 'privilege_id' => $editUser->id,
]);
}
/**
* Reverse the migration
*/
public function down(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->where('name', 'user.edit')
->delete();
}
}

View File

@ -1,52 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateScheduleLocationsTable extends Migration
{
use ChangesReferences;
use Reference;
/**
* Creates the new table
*/
public function up(): void
{
$connection = $this->schema->getConnection();
$this->schema->create('schedule_locations', function (Blueprint $table): void {
$table->increments('id');
$this->references($table, 'schedules');
$this->references($table, 'locations');
$table->index(['schedule_id', 'location_id']);
});
$scheduleLocations = $connection
->table('schedule_shift')
->select(['schedules.id AS schedule_id', 'locations.id AS location_id'])
->leftJoin('schedules', 'schedules.id', 'schedule_shift.schedule_id')
->leftJoin('shifts', 'shifts.id', 'schedule_shift.shift_id')
->leftJoin('locations', 'locations.id', 'shifts.location_id')
->groupBy(['schedules.id', 'locations.id'])
->get();
foreach ($scheduleLocations as $scheduleLocation) {
$connection->table('schedule_locations')
->insert((array) $scheduleLocation);
}
}
/**
* Drops the table
*/
public function down(): void
{
$this->schema->drop('schedule_locations');
}
}

View File

@ -1,77 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
class AddShifttypesEditPermissionAndShifttypesRequiresShico extends Migration
{
protected int $bureaucrat = 80;
protected int $shiCo = 60;
protected int $shifttypes;
protected Connection $db;
public function __construct(SchemaBuilder $schema)
{
parent::__construct($schema);
$this->db = $this->schema->getConnection();
$this->shifttypes = $this->db->table('privileges')
->where('name', 'shifttypes')
->get(['id'])
->first()->id;
}
/**
* Run the migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->insert([
'name' => 'shifttypes.edit', 'description' => 'Edit shift types',
]);
$editShifttypes = $db->table('privileges')
->where('name', 'shifttypes.edit')
->get(['id'])
->first();
$this->movePermission($this->shifttypes, $this->bureaucrat, $this->shiCo);
$db->table('group_privileges')
->insertOrIgnore([
'group_id' => $this->bureaucrat, 'privilege_id' => $editShifttypes->id,
]);
}
/**
* Reverse the migration
*/
public function down(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->where('name', 'shifttypes.edit')
->delete();
$this->movePermission($this->shifttypes, $this->shiCo, $this->bureaucrat);
}
protected function movePermission(int $privilege, int $oldGroup, int $newGroup): void
{
$this->db->table('group_privileges')
->insertOrIgnore(['group_id' => $newGroup, 'privilege_id' => $privilege]);
$this->db->table('group_privileges')
->where(['group_id' => $oldGroup, 'privilege_id' => $privilege])
->delete();
}
}

View File

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddIfsgConfirmedToUsersLicenses extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('users_licenses', function (Blueprint $table): void {
$table->boolean('ifsg_confirmed')->default(false)->after('ifsg_certificate');
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('users_licenses', function (Blueprint $table): void {
$table->dropColumn('ifsg_confirmed');
});
}
}

View File

@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
class AddUserIfsgEditPermission extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->insert([
'name' => 'user.ifsg.edit', 'description' => 'Edit IfSG Certificate',
]);
$editIfsg = $db->table('privileges')
->where('name', 'user.ifsg.edit')
->get(['id'])
->first();
$shico = 60;
$team_coordinator = 65;
$db->table('group_privileges')
->insertOrIgnore([
['group_id' => $shico, 'privilege_id' => $editIfsg->id],
['group_id' => $team_coordinator, 'privilege_id' => $editIfsg->id],
]);
}
/**
* Reverse the migration
*/
public function down(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->where('name', 'user.ifsg.edit')
->delete();
}
}

View File

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddDriveConfirmedToUsersLicenses extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('users_licenses', function (Blueprint $table): void {
$table->boolean('drive_confirmed')->default(false)->after('drive_12t');
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('users_licenses', function (Blueprint $table): void {
$table->dropColumn('drive_confirmed');
});
}
}

View File

@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
class AddUserDriveEditPermission extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->insert([
'name' => 'user.drive.edit', 'description' => 'Edit Driving License',
]);
$editDrive = $db->table('privileges')
->where('name', 'user.drive.edit')
->get(['id'])
->first();
$shico = 60;
$team_coordinator = 65;
$db->table('group_privileges')
->insertOrIgnore([
['group_id' => $shico, 'privilege_id' => $editDrive->id],
['group_id' => $team_coordinator, 'privilege_id' => $editDrive->id],
]);
}
/**
* Reverse the migration
*/
public function down(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->where('name', 'user.drive.edit')
->delete();
}
}

View File

@ -1,44 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
class AddUserFaEditPermission extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->insert([
'name' => 'user.fa.edit', 'description' => 'Edit User Force Active State',
]);
$editFa = $db->table('privileges')
->where('name', 'user.fa.edit')
->get(['id'])
->first();
$bureaucrat = 80;
$db->table('group_privileges')
->insertOrIgnore([
['group_id' => $bureaucrat, 'privilege_id' => $editFa->id],
]);
}
/**
* Reverse the migration
*/
public function down(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->where('name', 'user.fa.edit')
->delete();
}
}

View File

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class RenameGoodyToGoodie extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('users_settings', function (Blueprint $table): void {
$table->renameColumn('email_goody', 'email_goodie');
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('users_settings', function (Blueprint $table): void {
$table->renameColumn('email_goodie', 'email_goody');
});
}
}

View File

@ -1,49 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class RenameShirtToGoodie extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('users_state', function (Blueprint $table): void {
$table->renameColumn('got_shirt', 'got_goodie');
});
$db = $this->schema->getConnection();
$db->table('privileges')->where('name', 'admin_active')->update([
'description' => 'Mark angels as active and if they got a goodie.',
]);
$db->table('privileges')->where('name', 'user.edit.shirt')->update([
'name' => 'user.goodie.edit',
'description' => 'Edit user goodies',
]);
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('users_state', function (Blueprint $table): void {
$table->renameColumn('got_goodie', 'got_shirt');
});
$db = $this->schema->getConnection();
$db->table('privileges')->where('name', 'admin_active')->update([
'description' => 'Mark angels as active and if they got a t-shirt.',
]);
$db->table('privileges')->where('name', 'user.goodie.edit')->update([
'name' => 'user.edit.shirt',
'description' => 'Edit user shirts',
]);
}
}

View File

@ -1,205 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
class RefactorPermissionsAndGroups extends Migration
{
protected int $developer = 90;
protected int $bureaucrat = 80;
protected int $shiCo = 60;
protected int $newsAdmin = 85;
protected int $teamCoordinator = 65;
protected int $angel = 20;
protected int $active;
protected int $driveEdit;
protected int $eventConfig;
protected int $goodieEdit;
protected int $ifsgEdit;
protected int $log;
protected int $news;
protected int $register;
protected int $scheduleImport;
protected int $shifts;
protected int $user;
protected int $userAngeltypes;
protected int $userShifts;
protected string $shiftentry = 'shiftentry_edit_angeltype_supporter';
protected string $language = 'admin_language';
protected string $userEdit = 'user.edit';
protected string $userNickEdit = 'user.nick.edit';
protected string $shifttypes = 'shifttypes';
protected string $shifttypesView = 'shifttypes.view';
protected Connection $db;
public function __construct(SchemaBuilder $schema)
{
parent::__construct($schema);
$this->db = $this->schema->getConnection();
$this->active = $this->getPrivilegeId('admin_active');
$this->driveEdit = $this->getPrivilegeId('user.drive.edit');
$this->eventConfig = $this->getPrivilegeId('admin_event_config');
$this->goodieEdit = $this->getPrivilegeId('user.goodie.edit');
$this->ifsgEdit = $this->getPrivilegeId('user.ifsg.edit');
$this->log = $this->getPrivilegeId('admin_log');
$this->news = $this->getPrivilegeId('admin_news');
$this->register = $this->getPrivilegeId('register');
$this->scheduleImport = $this->getPrivilegeId('schedule.import');
$this->shifts = $this->getPrivilegeId('admin_shifts');
$this->user = $this->getPrivilegeId('admin_user');
$this->userAngeltypes = $this->getPrivilegeId('admin_user_angeltypes');
$this->userShifts = $this->getPrivilegeId('user_shifts_admin');
}
/**
* Run the migration
*/
public function up(): void
{
$this->deletePermission($this->shiftentry);
$this->deletePermission($this->language);
$this->movePermission($this->active, $this->bureaucrat, $this->shiCo);
$this->movePermission($this->userAngeltypes, $this->bureaucrat, $this->shiCo);
$this->movePermission($this->eventConfig, $this->shiCo, $this->developer);
$this->movePermission($this->goodieEdit, $this->bureaucrat, $this->shiCo);
$this->insertGroupPermission($this->log, $this->bureaucrat);
$this->deleteGroupPermission($this->news, $this->bureaucrat);
$this->deleteGroupPermission($this->shifts, $this->bureaucrat);
$this->deleteGroupPermission($this->user, $this->bureaucrat);
$this->deleteGroupPermission($this->register, $this->bureaucrat);
$this->deleteGroupPermission($this->scheduleImport, $this->developer);
$this->updatePermission($this->shifttypes, $this->shifttypesView, 'View shift types');
$this->updatePermission($this->userEdit, $this->userNickEdit, 'Edit user nick');
$this->deleteGroup($this->newsAdmin);
$this->deleteGroup($this->teamCoordinator);
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->insertPermission(
$this->shiftentry,
'If user with this privilege is angeltype supporter, he can put users in shifts for their angeltype',
$this->angel
);
$this->insertPermission(
$this->language,
'Translate the system',
$this->developer
);
$this->movePermission($this->active, $this->shiCo, $this->bureaucrat);
$this->movePermission($this->userAngeltypes, $this->shiCo, $this->bureaucrat);
$this->movePermission($this->eventConfig, $this->developer, $this->shiCo);
$this->movePermission($this->goodieEdit, $this->shiCo, $this->bureaucrat);
$this->deleteGroupPermission($this->log, $this->bureaucrat);
$this->insertGroupPermission($this->news, $this->bureaucrat);
$this->insertGroupPermission($this->shifts, $this->bureaucrat);
$this->insertGroupPermission($this->user, $this->bureaucrat);
$this->insertGroupPermission($this->register, $this->bureaucrat);
$this->insertGroupPermission($this->scheduleImport, $this->developer);
$this->updatePermission($this->shifttypesView, $this->shifttypes, 'Administrate shift types');
$this->updatePermission($this->userNickEdit, $this->userEdit, 'Edit user');
$this->insertGroup($this->newsAdmin, 'News Admin', [$this->news]);
$this->insertGroup($this->teamCoordinator, 'Team Coordinator', [
$this->news,
$this->userAngeltypes,
$this->driveEdit,
$this->ifsgEdit,
$this->userShifts,
]);
}
protected function getPrivilegeId(string $privilege): int
{
return $this->db->table('privileges')
->where('name', $privilege)
->get(['id'])
->first()->id;
}
protected function deleteGroup(int $group): void
{
$this->db->table('groups')
->where(['id' => $group])
->delete();
}
protected function insertGroup(int $id, string $name, array $privileges): void
{
$this->db->table('groups')
->insertOrIgnore([
'name' => $name,
'id' => $id,
]);
foreach ($privileges as $privilege) {
$this->insertGroupPermission($privilege, $id);
}
}
protected function deleteGroupPermission(int $privilege, int $group): void
{
$this->db->table('group_privileges')
->where(['group_id' => $group, 'privilege_id' => $privilege])
->delete();
}
protected function insertGroupPermission(int $privilege, int $group): void
{
$this->db->table('group_privileges')
->insertOrIgnore([
['group_id' => $group, 'privilege_id' => $privilege],
]);
}
protected function movePermission(int $privilege, int $oldGroup, int $newGroup): void
{
$this->insertGroupPermission($privilege, $newGroup);
$this->deleteGroupPermission($privilege, $oldGroup);
}
protected function insertPermission(string $name, string $description, int $group): void
{
$this->db->table('privileges')
->insertOrIgnore([
'name' => $name, 'description' => $description,
]);
$permission = $this->getPrivilegeId($name);
$this->insertGroupPermission($permission, $group);
}
protected function deletePermission(string $privilege): void
{
$this->db->table('privileges')
->where(['name' => $privilege])
->delete();
}
protected function updatePermission(string $oldName, string $newName, string $description): void
{
$this->db->table('privileges')->where('name', $oldName)->update([
'name' => $newName,
'description' => $description,
]);
}
}

View File

@ -1,73 +0,0 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
class AddUsersArriveListPermission extends Migration
{
protected int $voucher = 35;
protected int $arrive;
protected Connection $db;
public function __construct(SchemaBuilder $schema)
{
parent::__construct($schema);
$this->db = $this->schema->getConnection();
$this->arrive = $this->db->table('privileges')
->where('name', 'admin_arrive')
->get(['id'])
->first()->id;
}
/**
* Run the migration
*/
public function up(): void
{
$this->db->table('privileges')
->insert([
'name' => 'users.arrive.list', 'description' => 'View arrive angels list',
]);
$arriveList = $this->db->table('privileges')
->where('name', 'users.arrive.list')
->get(['id'])
->first()->id;
// Goodie Manager, Shift Coordinator, Voucher Angel, Welcome Angel
$groups = [50, 60, 35, 30];
foreach ($groups as $group) {
$this->db->table('group_privileges')
->insertOrIgnore([
['group_id' => $group, 'privilege_id' => $arriveList],
]);
}
$this->db->table('group_privileges')
->where(['group_id' => $this->voucher, 'privilege_id' => $this->arrive])
->delete();
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->db->table('privileges')
->where('name', 'users.arrive.list')
->delete();
$this->db->table('group_privileges')
->insertOrIgnore([
['group_id' => $this->voucher, 'privilege_id' => $this->arrive],
]);
}
}

View File

@ -30,7 +30,7 @@ trait Reference
$table->primary($fromColumn);
}
$this->addReference($table, $fromColumn, $targetTable, $targetColumn);
$this->addReference($table, $fromColumn, $targetTable, $targetColumn ?: 'id');
return $col;
}

59
db/update.sql Normal file
View File

@ -0,0 +1,59 @@
INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES (40, 'view_rooms', 'User can view rooms');
INSERT INTO `GroupPrivileges` (`id`, `group_id`, `privilege_id`) VALUES (NULL, '-2', '40');
ALTER TABLE `UserAngelTypes` CHANGE `coordinator` `supporter` BOOLEAN;
ALTER TABLE `User` ADD COLUMN `email_by_human_allowed` BOOLEAN NOT NULL;
-- No Self Sign Up for some Angel Types
ALTER TABLE AngelTypes ADD no_self_signup TINYINT(1) NOT NULL;
ALTER TABLE `AngelTypes`
ADD `contact_user_id` INT NULL,
ADD `contact_name` VARCHAR(250) NULL,
ADD `contact_dect` VARCHAR(5) NULL,
ADD `contact_email` VARCHAR(250) NULL,
ADD INDEX (`contact_user_id`);
ALTER TABLE `AngelTypes`
ADD FOREIGN KEY (`contact_user_id`) REFERENCES `User`(`UID`) ON DELETE SET NULL ON UPDATE CASCADE;
INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES (NULL, 'shiftentry_edit_angeltype_supporter', 'If user with this privilege is angeltype supporter, he can put users in shifts for their angeltype');
-- DB Performance
ALTER TABLE `Shifts` ADD INDEX(`start`);
ALTER TABLE `NeededAngelTypes` ADD INDEX(`count`);
-- Security
UPDATE `Groups` SET UID = UID * 10;
INSERT INTO `Groups` (Name, UID) VALUES ('News Admin', -65);
INSERT INTO `Privileges` (id, name, `desc`) VALUES (42, 'admin_news_html', 'Use HTML in news');
INSERT INTO `GroupPrivileges` (group_id, privilege_id) VALUES (-65, 14), (-65, 42);
-- Add log level to LogEntries
ALTER TABLE `LogEntries` CHANGE COLUMN `nick` `level` VARCHAR(20) NOT NULL;
-- Angeltype contact update
ALTER TABLE `AngelTypes` DROP FOREIGN KEY angeltypes_ibfk_1;
ALTER TABLE `AngelTypes` DROP `contact_user_id`;
-- Room update
ALTER TABLE `Room` DROP `Number`;
ALTER TABLE `Room` DROP `show`;
ALTER TABLE `Room` DROP `Man`;
ALTER TABLE `Room` ADD `from_frab` BOOLEAN NOT NULL AFTER `FromPentabarf`;
UPDATE Room SET `from_frab` = (`FromPentabarf` = 'Y');
ALTER TABLE `Room` DROP `FromPentabarf`;
ALTER TABLE `Room` ADD `map_url` VARCHAR(300) NULL AFTER `from_frab`;
ALTER TABLE `Room` ADD `description` TEXT NULL AFTER `map_url`;
-- Dashboard
ALTER TABLE `AngelTypes` ADD `show_on_dashboard` BOOLEAN NOT NULL AFTER `contact_email`;
UPDATE `AngelTypes` SET `show_on_dashboard` = TRUE;
-- Work Log
CREATE TABLE `UserWorkLog` ( `id` INT NOT NULL AUTO_INCREMENT , `user_id` INT NOT NULL , `work_hours` DECIMAL NOT NULL , `comment` VARCHAR(200) NOT NULL , `created_user_id` INT NOT NULL , `created_timestamp` INT NOT NULL , PRIMARY KEY (`id`), INDEX (`user_id`), INDEX (`created_user_id`)) ENGINE = InnoDB;
ALTER TABLE `UserWorkLog` ADD FOREIGN KEY (`created_user_id`) REFERENCES `User`(`UID`) ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE `UserWorkLog` ADD FOREIGN KEY (`user_id`) REFERENCES `User`(`UID`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `UserWorkLog` ADD INDEX(`created_timestamp`);
INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES (NULL, 'admin_user_worklog', 'Manage user work log entries.');
ALTER TABLE `UserWorkLog` CHANGE `work_hours` `work_hours` DECIMAL(10,2) NOT NULL;
ALTER TABLE `UserWorkLog` ADD `work_timestamp` INT NOT NULL AFTER `user_id`;

View File

@ -8,7 +8,7 @@ RUN composer --no-ansi dump-autoload --optimize
FROM alpine AS translation
RUN apk add gettext
COPY resources/lang/ /data
RUN find /data -type f -name '*.po' -exec sh -c 'msgfmt "${1%.*}.po" -o"${1%.*}.mo"' shell {} \;
RUN find /data -type f -name '*.po' -exec sh -c 'file="{}"; msgfmt "${file%.*}.po" -o "${file%.*}.mo"' \;
# Build the themes
FROM node:20-alpine AS themes
@ -26,7 +26,6 @@ COPY config/ /app/config
COPY db/ /app/db
COPY includes/ /app/includes
COPY public/ /app/public
COPY resources/api /app/resources/api
COPY resources/views /app/resources/views
COPY src/ /app/src
COPY storage/ /app/storage

View File

@ -24,7 +24,7 @@ ENV TRUSTED_PROXIES 10.0.0.0/8,::ffff:10.0.0.0/8,\
# Engelsystem development workspace
# Contains all tools required to build / manage the system
FROM es_base AS es_workspace
RUN echo 'memory_limit = 1024M' > /usr/local/etc/php/conf.d/docker-php.ini
RUN echo 'memory_limit = 512M' > /usr/local/etc/php/conf.d/docker-php.ini
RUN apk add --no-cache gettext git nodejs npm yarn
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
ENTRYPOINT php -r 'sleep(PHP_INT_MAX);'

View File

@ -20,7 +20,10 @@ services:
APP_NAME: Engelsystem DEV
env_file: deployment.env
ports:
- "127.0.0.1:5080:80"
- "5080:80"
networks:
- database
- internet
depends_on:
- es_database
es_workspace:
@ -41,17 +44,11 @@ services:
ENVIRONMENT: development
MAIL_DRIVER: log
APP_NAME: Engelsystem DEV
networks:
- database
- internet
depends_on:
- es_database
es_phpmyadmin:
image: phpmyadmin
environment:
PMA_HOST: es_database
ports:
- "127.0.0.1:8888:80"
depends_on:
- es_database
profiles: [ dev ]
es_database:
image: mariadb:10.2
environment:
@ -62,5 +59,12 @@ services:
MYSQL_INITDB_SKIP_TZINFO: "yes"
volumes:
- db:/var/lib/mysql
networks:
- database
volumes:
db: {}
networks:
database:
internal: true
internet:

View File

@ -2,7 +2,7 @@
use Engelsystem\Helpers\Carbon;
use Engelsystem\Models\AngelType;
use Engelsystem\Models\Location;
use Engelsystem\Models\Room;
use Engelsystem\Models\UserAngelType;
use Engelsystem\ShiftsFilter;
use Engelsystem\ShiftsFilterRenderer;
@ -17,7 +17,7 @@ use Illuminate\Support\Collection;
*/
function angeltypes_title()
{
return __('angeltypes.angeltypes');
return __('Angeltypes');
}
/**
@ -48,7 +48,7 @@ function angeltypes_controller()
function angeltype_link($angeltype_id, $params = [])
{
$params = array_merge(['action' => 'view', 'angeltype_id' => $angeltype_id], $params);
return url('/angeltypes', $params);
return page_link_to('angeltypes', $params);
}
/**
@ -59,7 +59,7 @@ function angeltype_link($angeltype_id, $params = [])
function angeltype_delete_controller()
{
if (!auth()->can('admin_angel_types')) {
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
$angeltype = AngelType::findOrFail(request()->input('angeltype_id'));
@ -68,11 +68,11 @@ function angeltype_delete_controller()
$angeltype->delete();
engelsystem_log('Deleted angeltype: ' . AngelType_name_render($angeltype, true));
success(sprintf(__('Angeltype %s deleted.'), $angeltype->name));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
return [
sprintf(__('Delete angeltype %s'), htmlspecialchars($angeltype->name)),
sprintf(__('Delete angeltype %s'), $angeltype->name),
AngelType_delete_view($angeltype),
];
}
@ -92,14 +92,14 @@ function angeltype_edit_controller()
// Edit existing angeltype
$angeltype = AngelType::findOrFail($request->input('angeltype_id'));
if (!auth()->user()?->isAngelTypeSupporter($angeltype) && !auth()->can('admin_user_angeltypes')) {
throw_redirect(url('/angeltypes'));
if (!auth()->user()->isAngelTypeSupporter($angeltype) && !auth()->can('admin_user_angeltypes')) {
throw_redirect(page_link_to('angeltypes'));
}
} else {
// New angeltype
if ($supporter_mode) {
// Supporters aren't allowed to create new angeltypes.
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
$angeltype = new AngelType();
}
@ -118,13 +118,11 @@ function angeltype_edit_controller()
}
$angeltype->restricted = $request->has('restricted');
$angeltype->shift_self_signup = $request->has('shift_self_signup');
$angeltype->no_self_signup = $request->has('no_self_signup');
$angeltype->show_on_dashboard = $request->has('show_on_dashboard');
$angeltype->hide_register = $request->has('hide_register');
$angeltype->hide_on_shift_view = $request->has('hide_on_shift_view');
$angeltype->requires_driver_license = $request->has('requires_driver_license');
$angeltype->requires_ifsg_certificate = $request->has('requires_ifsg_certificate');
}
$angeltype->description = strip_request_item_nl('description', $angeltype->description);
@ -136,29 +134,23 @@ function angeltype_edit_controller()
if ($valid) {
$angeltype->save();
success(__('Angel type saved.'));
success('Angel type saved.');
engelsystem_log(
'Saved angeltype: ' . $angeltype->name . ($angeltype->restricted ? ', restricted' : '')
. ($angeltype->shift_self_signup ? ', shift_self_signup' : '')
. (config('driving_license_enabled')
? (($angeltype->requires_driver_license ? ', requires driver license' : '') . ', ')
: '')
. (config('ifsg_enabled')
? (($angeltype->requires_ifsg_certificate ? ', requires ifsg certificate' : '') . ', ')
: '')
. ($angeltype->no_self_signup ? ', no_self_signup' : '')
. ($angeltype->requires_driver_license ? ', requires driver license' : '') . ', '
. $angeltype->contact_name . ', '
. $angeltype->contact_dect . ', '
. $angeltype->contact_email . ', '
. $angeltype->show_on_dashboard . ', '
. $angeltype->hide_register . ', '
. $angeltype->hide_on_shift_view
. $angeltype->hide_register
);
throw_redirect(angeltype_link($angeltype->id));
}
}
return [
sprintf(__('Edit %s'), htmlspecialchars((string) $angeltype->name)),
sprintf(__('Edit %s'), $angeltype->name),
AngelType_edit_view($angeltype, $supporter_mode),
];
}
@ -173,15 +165,13 @@ function angeltype_controller()
$user = auth()->user();
if (!auth()->can('angeltypes')) {
throw_redirect(url('/'));
throw_redirect(page_link_to('/'));
}
$angeltype = AngelType::findOrFail(request()->input('angeltype_id'));
/** @var UserAngelType $user_angeltype */
$user_angeltype = UserAngelType::whereUserId($user->id)->where('angel_type_id', $angeltype->id)->first();
$members = $angeltype->userAngelTypes
->sortBy('name', SORT_NATURAL | SORT_FLAG_CASE)
->load(['state', 'personalData', 'contact']);
$members = $angeltype->userAngelTypes->sortBy('name', SORT_NATURAL | SORT_FLAG_CASE);
$days = angeltype_controller_shiftsFilterDays($angeltype);
$shiftsFilter = angeltype_controller_shiftsFilter($angeltype, $days);
if (request()->input('showFilledShifts')) {
@ -201,7 +191,7 @@ function angeltype_controller()
$isSupporter = !is_null($user_angeltype) && $user_angeltype->supporter;
return [
sprintf(__('Team %s'), htmlspecialchars($angeltype->name)),
sprintf(__('Team %s'), $angeltype->name),
AngelType_view(
$angeltype,
$members,
@ -230,8 +220,9 @@ function angeltype_controller_shiftsFilterDays(AngelType $angeltype)
$days = [];
foreach ($all_shifts as $shift) {
$day = Carbon::make($shift['start'])->format('Y-m-d');
$dayFormatted = Carbon::make($shift['start'])->format(__('Y-m-d'));
if (!isset($days[$day])) {
$days[$day] = dateWithEventDay($day);
$days[$day] = $dayFormatted;
}
}
ksort($days);
@ -248,13 +239,13 @@ function angeltype_controller_shiftsFilterDays(AngelType $angeltype)
function angeltype_controller_shiftsFilter(AngelType $angeltype, $days)
{
$request = request();
$locationIds = Location::query()
$roomIds = Room::query()
->select('id')
->pluck('id')
->toArray();
$shiftsFilter = new ShiftsFilter(
auth()->can('user_shifts_admin'),
$locationIds,
$roomIds,
[$angeltype->id]
);
$selected_day = date('Y-m-d');
@ -278,70 +269,59 @@ function angeltype_controller_shiftsFilter(AngelType $angeltype, $days)
function angeltypes_list_controller()
{
$user = auth()->user();
$admin_angeltypes = auth()->can('admin_angel_types');
if (!auth()->can('angeltypes')) {
throw_redirect(url('/'));
throw_redirect(page_link_to('/'));
}
$angeltypes = AngelTypes_with_user($user->id);
foreach ($angeltypes as $angeltype) {
$actions = [
button(
url('/angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]),
icon('eye') . ($admin_angeltypes ? '' : __('View')),
'btn-sm btn-info',
'',
($admin_angeltypes ? __('View') : '')
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]),
icon('eye') . __('view'),
'btn-sm'
),
];
if ($admin_angeltypes) {
if (auth()->can('admin_angel_types')) {
$actions[] = button(
url('/angeltypes', ['action' => 'edit', 'angeltype_id' => $angeltype->id]),
icon('pencil'),
'btn-sm',
'',
__('form.edit')
page_link_to('angeltypes', ['action' => 'edit', 'angeltype_id' => $angeltype->id]),
icon('pencil') . __('edit'),
'btn-sm'
);
$actions[] = button(
url('/angeltypes', ['action' => 'delete', 'angeltype_id' => $angeltype->id]),
icon('trash'),
'btn-sm btn-danger',
'',
__('form.delete')
page_link_to('angeltypes', ['action' => 'delete', 'angeltype_id' => $angeltype->id]),
icon('trash') . __('delete'),
'btn-sm'
);
}
$angeltype->membership = AngelType_render_membership($angeltype);
if (!empty($angeltype->user_angel_type_id)) {
$actions[] = button(
url(
'/user-angeltypes',
page_link_to(
'user_angeltypes',
['action' => 'delete', 'user_angeltype_id' => $angeltype->user_angel_type_id]
),
icon('box-arrow-right') . ($admin_angeltypes ? '' : __('Leave')),
'btn-sm',
'',
($admin_angeltypes ? __('Leave') : '')
icon('box-arrow-right') . __('leave'),
'btn-sm'
);
} else {
$actions[] = button(
url('/user_angeltypes', ['action' => 'add', 'angeltype_id' => $angeltype->id]),
icon('box-arrow-in-right') . ($admin_angeltypes ? '' : __('Join')),
'btn-sm' . ($admin_angeltypes ? ' btn-success' : ''),
'',
($admin_angeltypes ? __('Join') : '')
page_link_to('user_angeltypes', ['action' => 'add', 'angeltype_id' => $angeltype->id]),
icon('box-arrow-in-right') . __('join'),
'btn-sm'
);
}
$angeltype->is_restricted = $angeltype->restricted ? icon('mortarboard-fill') : '';
$angeltype->shift_self_signup_allowed = $angeltype->shift_self_signup ? icon('pencil-square') : '';
$angeltype->no_self_signup_allowed = $angeltype->no_self_signup ? '' : icon('pencil-square');
$angeltype->name = '<a href="'
. url('/angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id])
. page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id])
. '">'
. htmlspecialchars($angeltype->name)
. $angeltype->name
. '</a>';
$angeltype->actions = table_buttons($actions);

View File

@ -17,7 +17,7 @@ function event_config_title()
function event_config_edit_controller()
{
if (!auth()->can('admin_event_config')) {
throw_redirect(url('/'));
throw_redirect(page_link_to('/'));
}
$request = request();
@ -117,8 +117,8 @@ function event_config_edit_controller()
$teardown_end_date ? $teardown_end_date->format('Y-m-d H:i') : ''
)
);
success(__('settings.success'));
throw_redirect(url('/admin_event_config'));
success(__('Settings saved.'));
throw_redirect(page_link_to('admin_event_config'));
}
}

View File

@ -1,8 +1,8 @@
<?php
use Engelsystem\Models\AngelType;
use Engelsystem\Models\Location;
use Engelsystem\Models\News;
use Engelsystem\Models\Room;
use Engelsystem\Models\Shifts\Shift;
use Engelsystem\ShiftsFilter;
@ -15,22 +15,22 @@ function public_dashboard_controller()
{
$filter = null;
if (request()->get('filtered')) {
$requestLocations = check_request_int_array('locations');
$requestRooms = check_request_int_array('rooms');
$requestAngelTypes = check_request_int_array('types');
if (!$requestLocations && !$requestAngelTypes) {
if (!$requestRooms && !$requestAngelTypes) {
$sessionFilter = collect(session()->get('shifts-filter', []));
$requestLocations = $sessionFilter->get('locations', []);
$requestRooms = $sessionFilter->get('rooms', []);
$requestAngelTypes = $sessionFilter->get('types', []);
}
$angelTypes = collect(unrestricted_angeltypes());
$locations = $requestLocations ?: Location::orderBy('name')->get()->pluck('id')->toArray();
$rooms = $requestRooms ?: Room::orderBy('name')->get()->pluck('id')->toArray();
$angelTypes = $requestAngelTypes ?: $angelTypes->pluck('id')->toArray();
$filterValues = [
'userShiftsAdmin' => false,
'filled' => [],
'locations' => $locations,
'rooms' => $rooms,
'types' => $angelTypes,
'startTime' => null,
'endTime' => null,
@ -57,14 +57,14 @@ function public_dashboard_controller()
}
}
$highlighted_news = News::whereIsHighlighted(true)
$important_news = News::whereIsImportant(true)
->orderBy('updated_at')
->limit(1)
->get();
return [
__('Public Dashboard'),
public_dashboard_view($stats, $free_shifts, $highlighted_news),
public_dashboard_view($stats, $free_shifts, $important_news),
];
}
@ -87,7 +87,7 @@ function public_dashboard_controller_free_shift(Shift $shift, ShiftsFilter $filt
'duration' => round(($shift->end->timestamp - $shift->start->timestamp) / 3600),
'shifttype_name' => $shift->shiftType->name,
'title' => $shift->title,
'location_name' => $shift->location->name,
'room_name' => $shift->room->name,
'needed_angels' => public_dashboard_needed_angels($shift->neededAngels, $filter),
];
@ -136,5 +136,5 @@ function public_dashboard_needed_angels($needed_angels, ShiftsFilter $filter = n
*/
function public_dashboard_link(array $parameters = []): string
{
return url('/public-dashboard', $parameters);
return page_link_to('public-dashboard', $parameters);
}

View File

@ -1,40 +1,40 @@
<?php
use Engelsystem\Models\AngelType;
use Engelsystem\Models\Location;
use Engelsystem\Models\Room;
use Engelsystem\ShiftsFilter;
use Engelsystem\ShiftsFilterRenderer;
/**
* Location controllers for managing everything location related.
* Room controllers for managing everything room related.
*/
/**
* View a location with its shifts.
* View a room with its shifts.
*
* @return array
*/
function location_controller(): array
function room_controller(): array
{
if (!auth()->can('view_locations')) {
throw_redirect(url('/'));
if (!auth()->can('view_rooms')) {
throw_redirect(page_link_to());
}
$request = request();
$location = load_location();
$room = load_room();
$all_shifts = $location->shifts->sortBy('start');
$all_shifts = $room->shifts->sortBy('start');
$days = [];
foreach ($all_shifts as $shift) {
$day = $shift->start->format('Y-m-d');
if (!isset($days[$day])) {
$days[$day] = dateWithEventDay($day);
$days[$day] = $shift->start->format(__('Y-m-d'));
}
}
$shiftsFilter = new ShiftsFilter(
true,
[$location->id],
[$room->id],
AngelType::query()->get('id')->pluck('id')->toArray()
);
$selected_day = date('Y-m-d');
@ -53,17 +53,17 @@ function location_controller(): array
$shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
return [
htmlspecialchars($location->name),
location_view($location, $shiftsFilterRenderer, $shiftCalendarRenderer),
$room->name,
Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer),
];
}
/**
* Dispatch different location actions.
* Dispatch different room actions.
*
* @return array
*/
function locations_controller(): array
function rooms_controller(): array
{
$request = request();
$action = $request->input('action');
@ -72,36 +72,36 @@ function locations_controller(): array
}
return match ($action) {
'view' => location_controller(),
'list' => throw_redirect(url('/admin/locations')),
default => throw_redirect(url('/admin/locations')),
'view' => room_controller(),
'list' => throw_redirect(page_link_to('admin/rooms')),
default => throw_redirect(page_link_to('admin/rooms')),
};
}
/**
* @param Location $location
* @param Room $room
* @return string
*/
function location_link(Location $location)
function room_link(Room $room)
{
return url('/locations', ['action' => 'view', 'location_id' => $location->id]);
return page_link_to('rooms', ['action' => 'view', 'room_id' => $room->id]);
}
/**
* Loads location by request param location_id
* Loads room by request param room_id
*
* @return Location
* @return Room
*/
function load_location()
function load_room()
{
if (!test_request_int('location_id')) {
throw_redirect(url('/'));
if (!test_request_int('room_id')) {
throw_redirect(page_link_to());
}
$location = Location::find(request()->input('location_id'));
if (!$location) {
throw_redirect(url('/'));
$room = Room::find(request()->input('room_id'));
if (!$room) {
throw_redirect(page_link_to());
}
return $location;
return $room;
}

View File

@ -18,7 +18,7 @@ function shift_entries_controller(): array
{
$user = auth()->user();
if (!$user) {
throw_redirect(url('/login'));
throw_redirect(page_link_to('login'));
}
$action = strip_request_item('action');
@ -44,7 +44,7 @@ function shift_entry_create_controller(): array
$request = request();
if ($user->isFreeloader()) {
throw_redirect(url('/user_myshifts'));
throw_redirect(page_link_to('user_myshifts'));
}
$shift = Shift($request->input('shift_id'));
@ -113,21 +113,17 @@ function shift_entry_create_controller_admin(Shift $shift, ?AngelType $angeltype
}
/** @var User[]|Collection $users */
$users = User::with('userAngelTypes')->orderBy('name')->get();
$users = User::query()->orderBy('name')->get();
$users_select = [];
foreach ($users as $user) {
$name = $user->displayName;
if ($user->userAngelTypes->where('id', $angeltype->id)->isEmpty()) {
$name = __('%s (not "%s")', [$name, $angeltype->name]);
}
$users_select[$user->id] = $name;
$users_select[$user->id] = $user->displayName;
}
$angeltypes_select = $angeltypes->pluck('name', 'id')->toArray();
$location = $shift->location;
$room = $shift->room;
return [
ShiftEntry_create_title(),
ShiftEntry_create_view_admin($shift, $location, $angeltype, $angeltypes_select, $signup_user, $users_select),
ShiftEntry_create_view_admin($shift, $room, $angeltype, $angeltypes_select, $signup_user, $users_select),
];
}
@ -171,10 +167,10 @@ function shift_entry_create_controller_supporter(Shift $shift, AngelType $angelt
$users_select[$u->id] = $u->displayName;
}
$location = $shift->location;
$room = $shift->room;
return [
ShiftEntry_create_title(),
ShiftEntry_create_view_supporter($shift, $location, $angeltype, $signup_user, $users_select),
ShiftEntry_create_view_supporter($shift, $room, $angeltype, $signup_user, $users_select),
];
}
@ -210,7 +206,7 @@ function shift_entry_create_controller_user(Shift $shift, AngelType $angeltype):
$request = request();
$signup_user = auth()->user();
$needed_angeltype = (new AngelType())->forceFill(NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) ?: []);
$needed_angeltype = (new AngelType())->forceFill(NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype));
$shift_entries = $shift->shiftEntries()
->where('angel_type_id', $angeltype->id)
->get();
@ -254,10 +250,10 @@ function shift_entry_create_controller_user(Shift $shift, AngelType $angeltype):
throw_redirect(shift_link($shift));
}
$location = $shift->location;
$room = $shift->room;
return [
ShiftEntry_create_title(),
ShiftEntry_create_view_user($shift, $location, $angeltype, $comment),
ShiftEntry_create_view_user($shift, $room, $angeltype, $comment),
];
}
@ -276,7 +272,7 @@ function shift_entry_create_link(Shift $shift, AngelType $angeltype, $params = [
'shift_id' => $shift->id,
'angeltype_id' => $angeltype->id,
], $params);
return url('/shift-entries', $params);
return page_link_to('shift_entries', $params);
}
/**
@ -292,7 +288,7 @@ function shift_entry_create_link_admin(Shift $shift, $params = [])
'action' => 'create',
'shift_id' => $shift->id,
], $params);
return url('/shift-entries', $params);
return page_link_to('shift_entries', $params);
}
/**
@ -305,10 +301,11 @@ function shift_entry_load()
$request = request();
if (!$request->has('shift_entry_id') || !test_request_int('shift_entry_id')) {
throw_redirect(url('/user-shifts'));
throw_redirect(page_link_to('user_shifts'));
}
$shiftEntry = ShiftEntry::findOrFail($request->input('shift_entry_id'));
return ShiftEntry::findOrFail($request->input('shift_entry_id'));
return $shiftEntry;
}
/**
@ -365,5 +362,5 @@ function shift_entry_delete_link($shiftEntry, $params = [])
'action' => 'delete',
'shift_entry_id' => $shiftEntry['shift_entry_id'] ?? $shiftEntry['id'],
], $params);
return url('/shift-entries', $params);
return page_link_to('shift_entries', $params);
}

View File

@ -1,17 +1,13 @@
<?php
use Engelsystem\Http\Exceptions\HttpForbidden;
use Engelsystem\Http\Exceptions\HttpNotFound;
use Engelsystem\Http\Redirector;
use Engelsystem\Models\AngelType;
use Engelsystem\Models\Location;
use Engelsystem\Models\Shifts\NeededAngelType;
use Engelsystem\Models\Room;
use Engelsystem\Models\Shifts\ScheduleShift;
use Engelsystem\Models\Shifts\Shift;
use Engelsystem\Models\Shifts\ShiftType;
use Engelsystem\Models\Shifts\ShiftSignupStatus;
use Engelsystem\ShiftSignupState;
use Illuminate\Support\Str;
/**
* @param array|Shift $shift
@ -24,7 +20,16 @@ function shift_link($shift)
$parameters['shift_id'] = $shift['shift_id'] ?? $shift['id'];
}
return url('/shifts', $parameters);
return page_link_to('shifts', $parameters);
}
/**
* @param Shift $shift
* @return string
*/
function shift_delete_link(Shift $shift)
{
return page_link_to('user_shifts', ['delete_shift' => $shift->id]);
}
/**
@ -33,7 +38,7 @@ function shift_link($shift)
*/
function shift_edit_link(Shift $shift)
{
return url('/user-shifts', ['edit_shift' => $shift->id]);
return page_link_to('user_shifts', ['edit_shift' => $shift->id]);
}
/**
@ -47,11 +52,11 @@ function shift_edit_controller()
$request = request();
if (!auth()->can('admin_shifts')) {
throw_redirect(url('/user-shifts'));
throw_redirect(page_link_to('user_shifts'));
}
if (!$request->has('edit_shift') || !test_request_int('edit_shift')) {
throw_redirect(url('/user-shifts'));
throw_redirect(page_link_to('user_shifts'));
}
$shift_id = $request->input('edit_shift');
@ -62,14 +67,14 @@ function shift_edit_controller()
));
}
$locations = [];
foreach (Location::orderBy('name')->get() as $location) {
$locations[$location->id] = $location->name;
$rooms = [];
foreach (Room::orderBy('name')->get() as $room) {
$rooms[$room->id] = $room->name;
}
$angeltypes = AngelType::all()->pluck('name', 'id')->toArray();
$shifttypes = ShiftType::all()->pluck('name', 'id')->toArray();
$needed_angel_types = collect(NeededAngelTypes_by_shift($shift))->pluck('count', 'angel_type_id')->toArray();
$needed_angel_types = collect(NeededAngelTypes_by_shift($shift_id))->pluck('count', 'angel_type_id')->toArray();
foreach (array_keys($angeltypes) as $angeltype_id) {
if (!isset($needed_angel_types[$angeltype_id])) {
$needed_angel_types[$angeltype_id] = 0;
@ -79,7 +84,7 @@ function shift_edit_controller()
$shifttype_id = $shift->shift_type_id;
$title = $shift->title;
$description = $shift->description;
$rid = $shift->location_id;
$rid = $shift->room_id;
$start = $shift->start;
$end = $shift->end;
@ -92,12 +97,12 @@ function shift_edit_controller()
if (
$request->has('rid')
&& preg_match('/^\d+$/', $request->input('rid'))
&& isset($locations[$request->input('rid')])
&& isset($rooms[$request->input('rid')])
) {
$rid = $request->input('rid');
} else {
$valid = false;
error(__('Please select a location.'));
error(__('Please select a room.'));
}
if ($request->has('shifttype_id') && isset($shifttypes[$request->input('shifttype_id')])) {
@ -149,16 +154,13 @@ function shift_edit_controller()
$shift->shift_type_id = $shifttype_id;
$shift->title = $title;
$shift->description = $description;
$shift->location_id = $rid;
$shift->room_id = $rid;
$shift->start = $start;
$shift->end = $end;
$shift->updatedBy()->associate(auth()->user());
$shift->save();
event('shift.updating', [
'shift' => $shift,
'oldShift' => $oldShift,
]);
mail_shift_change($oldShift, $shift);
NeededAngelType::whereShiftId($shift_id)->delete();
$needed_angel_types_info = [];
@ -192,16 +194,13 @@ function shift_edit_controller()
foreach ($angeltypes as $angeltype_id => $angeltype_name) {
$angel_types_spinner .= form_spinner(
'angeltype_count_' . $angeltype_id,
htmlspecialchars($angeltype_name),
$needed_angel_types[$angeltype_id],
[],
(bool) ScheduleShift::whereShiftId($shift->id)->first(),
$angeltype_name,
$needed_angel_types[$angeltype_id]
);
}
$link = button(url('/shifts', ['action' => 'view', 'shift_id' => $shift_id]), icon('chevron-left'), 'btn-sm', '', __('general.back'));
return page_with_title(
$link . ' ' . shifts_title(),
shifts_title(),
[
msg(),
'<noscript>'
@ -209,59 +208,80 @@ function shift_edit_controller()
. '</noscript>',
form([
form_select('shifttype_id', __('Shifttype'), $shifttypes, $shifttype_id),
form_text('title', __('title.title'), $title),
form_select('rid', __('Location:'), $locations, $rid),
form_text('title', __('Title'), $title),
form_select('rid', __('Room:'), $rooms, $rid),
form_text('start', __('Start:'), $start->format('Y-m-d H:i')),
form_text('end', __('End:'), $end->format('Y-m-d H:i')),
form_textarea('description', __('Additional description'), $description),
form_info(
'',
__('This description is for single shifts, otherwise please use the description in shift type.')
),
form_info('', __('This description is for single shifts, otherwise please use the description in shift type.')),
'<h2>' . __('Needed angels') . '</h2>',
$angel_types_spinner,
form_submit('submit', icon('save') . __('form.save')),
form_submit('submit', __('Save')),
]),
]
);
}
function shift_delete_controller(): void
/**
* @return string
*/
function shift_delete_controller()
{
$request = request();
// Only accessible for admins / ShiCos with user_shifts_admin privileg
if (!auth()->can('user_shifts_admin')) {
throw new HttpForbidden();
throw_redirect(page_link_to('user_shifts'));
}
// Must contain shift id and confirmation
if (!$request->has('delete_shift') || !$request->hasPostData('delete')) {
throw new HttpNotFound();
// Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg)
if (!$request->has('delete_shift') || !preg_match('/^\d+$/', $request->input('delete_shift'))) {
throw_redirect(page_link_to('user_shifts'));
}
$shift_id = $request->input('delete_shift');
$shift = Shift::findOrFail($shift_id);
event('shift.deleting', ['shift' => $shift]);
$shift->delete();
engelsystem_log(
'Deleted shift ' . $shift->title . ': ' . $shift->shiftType->name
. ' from ' . $shift->start->format('Y-m-d H:i')
. ' to ' . $shift->end->format('Y-m-d H:i')
);
success(__('Shift deleted.'));
/** @var Redirector $redirect */
$redirect = app('redirect');
$old = $redirect->back()->getHeaderLine('location');
if (Str::contains($old, '/shifts') && Str::contains($old, 'action=view')) {
throw_redirect(url('/user-shifts'));
$shift = Shift($shift_id);
if (empty($shift)) {
throw_redirect(page_link_to('user_shifts'));
}
throw_redirect($old);
// Schicht löschen bestätigt
if ($request->hasPostData('delete')) {
foreach ($shift->shiftEntries as $entry) {
event('shift.entry.deleting', [
'user' => $entry->user,
'start' => $shift->start,
'end' => $shift->end,
'name' => $shift->shiftType->name,
'title' => $shift->title,
'type' => $entry->angelType->name,
'room' => $shift->room,
'freeloaded' => $entry->freeloaded,
]);
}
$shift->delete();
engelsystem_log(
'Deleted shift ' . $shift->title . ': ' . $shift->shiftType->name
. ' from ' . $shift->start->format('Y-m-d H:i')
. ' to ' . $shift->end->format('Y-m-d H:i')
);
success(__('Shift deleted.'));
throw_redirect(page_link_to('user_shifts'));
}
return page_with_title(shifts_title(), [
error(sprintf(
__('Do you want to delete the shift %s from %s to %s?'),
$shift->shiftType->name,
$shift->start->format(__('Y-m-d H:i')),
$shift->end->format(__('H:i'))
), true),
form([
form_hidden('delete_shift', $shift->id),
form_submit('delete', __('delete')),
]),
]);
}
/**
@ -273,21 +293,21 @@ function shift_controller()
$request = request();
if (!auth()->can('user_shifts')) {
throw_redirect(url('/'));
throw_redirect(page_link_to('/'));
}
if (!$request->has('shift_id')) {
throw_redirect(url('/user-shifts'));
throw_redirect(page_link_to('user_shifts'));
}
$shift = Shift($request->input('shift_id'));
if (empty($shift)) {
error(__('Shift could not be found.'));
throw_redirect(url('/user-shifts'));
throw_redirect(page_link_to('user_shifts'));
}
$shifttype = $shift->shiftType;
$location = $shift->location;
$room = $shift->room;
/** @var AngelType[] $angeltypes */
$angeltypes = AngelType::all();
$user_shifts = Shifts_by_user($user->id);
@ -318,8 +338,8 @@ function shift_controller()
}
return [
htmlspecialchars($shift->shiftType->name),
Shift_view($shift, $shifttype, $location, $angeltypes, $shift_signup_state),
$shift->shiftType->name,
Shift_view($shift, $shifttype, $room, $angeltypes, $shift_signup_state),
];
}
@ -330,13 +350,13 @@ function shifts_controller()
{
$request = request();
if (!$request->has('action')) {
throw_redirect(url('/user-shifts'));
throw_redirect(page_link_to('user_shifts'));
}
return match ($request->input('action')) {
'view' => shift_controller(),
'next' => shift_next_controller(), // throws redirect
default => throw_redirect(url('/')),
default => throw_redirect(page_link_to('/')),
};
}
@ -346,7 +366,7 @@ function shifts_controller()
function shift_next_controller()
{
if (!auth()->can('user_shifts')) {
throw_redirect(url('/'));
throw_redirect(page_link_to('/'));
}
$upcoming_shifts = ShiftEntries_upcoming_for_user(auth()->user());
@ -355,5 +375,5 @@ function shift_next_controller()
throw_redirect(shift_link($upcoming_shifts[0]->shift));
}
throw_redirect(url('/user-shifts'));
throw_redirect(page_link_to('user_shifts'));
}

View File

@ -0,0 +1,163 @@
<?php
use Engelsystem\Models\Shifts\ShiftType;
/**
* @param ShiftType $shifttype
* @return string
*/
function shifttype_link(ShiftType $shifttype)
{
return page_link_to('shifttypes', ['action' => 'view', 'shifttype_id' => $shifttype->id]);
}
/**
* Delete a shifttype.
*
* @return array
*/
function shifttype_delete_controller()
{
$request = request();
if (!$request->has('shifttype_id')) {
throw_redirect(page_link_to('shifttypes'));
}
$shifttype = ShiftType::findOrFail($request->input('shifttype_id'));
if ($request->hasPostData('delete')) {
engelsystem_log('Deleted shifttype ' . $shifttype->name);
success(sprintf(__('Shifttype %s deleted.'), $shifttype->name));
$shifttype->delete();
throw_redirect(page_link_to('shifttypes'));
}
return [
sprintf(__('Delete shifttype %s'), $shifttype->name),
ShiftType_delete_view($shifttype),
];
}
/**
* Edit or create shift type.
*
* @return array
*/
function shifttype_edit_controller()
{
$shifttype_id = null;
$name = '';
$description = '';
$request = request();
if ($request->has('shifttype_id')) {
$shifttype = ShiftType::findOrFail($request->input('shifttype_id'));
$shifttype_id = $shifttype->id;
$name = $shifttype->name;
$description = $shifttype->description;
}
if ($request->hasPostData('submit')) {
$valid = true;
if ($request->has('name') && $request->input('name') != '') {
$name = strip_request_item('name');
} else {
$valid = false;
error(__('Please enter a name.'));
}
if ($request->has('description')) {
$description = strip_request_item_nl('description');
}
if ($valid) {
$shiftType = ShiftType::findOrNew($shifttype_id);
$shiftType->name = $name;
$shiftType->description = $description;
$shiftType->save();
if ($shifttype_id) {
engelsystem_log('Updated shifttype ' . $name);
success(__('Updated shifttype.'));
} else {
$shifttype_id = $shiftType->id;
engelsystem_log('Created shifttype ' . $name);
success(__('Created shifttype.'));
}
throw_redirect(page_link_to('shifttypes', ['action' => 'view', 'shifttype_id' => $shifttype_id]));
}
}
return [
shifttypes_title(),
ShiftType_edit_view($name, $description, $shifttype_id),
];
}
/**
* @return array
*/
function shifttype_controller()
{
$request = request();
if (!$request->has('shifttype_id')) {
throw_redirect(page_link_to('shifttypes'));
}
$shifttype = ShiftType::findOrFail($request->input('shifttype_id'));
return [
$shifttype->name,
ShiftType_view($shifttype),
];
}
/**
* List all shift types.
*
* @return array
*/
function shifttypes_list_controller()
{
$shifttypes = ShiftType::all();
return [
shifttypes_title(),
ShiftTypes_list_view($shifttypes),
];
}
/**
* Text for shift type related links.
*
* @return string
*/
function shifttypes_title()
{
return __('Shifttypes');
}
/**
* Route shift type actions
*
* @return array
*/
function shifttypes_controller()
{
$request = request();
$action = 'list';
if ($request->has('action')) {
$action = $request->input('action');
}
return match ($action) {
'view' => shifttype_controller(),
'edit' => shifttype_edit_controller(),
'delete' => shifttype_delete_controller(),
'list' => shifttypes_list_controller(),
default => shifttypes_list_controller(),
};
}

View File

@ -5,6 +5,8 @@ use Engelsystem\Models\AngelType;
use Engelsystem\Models\User\User;
use Engelsystem\Models\UserAngelType;
use Illuminate\Database\Eloquent\Collection;
use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\Exception\TransportException;
/**
* Display a hint for team/angeltype supporters if there are unconfirmed users for his angeltype.
@ -35,9 +37,9 @@ function user_angeltypes_unconfirmed_hint()
$unconfirmed_links = [];
foreach ($unconfirmed_user_angeltypes as $user_angeltype) {
$unconfirmed_links[] = '<a href="'
. url('/angeltypes', ['action' => 'view', 'angeltype_id' => $user_angeltype->angel_type_id])
. '">' . htmlspecialchars($user_angeltype->angelType->name)
$unconfirmed_links[] = '<a class="text-info" href="'
. page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $user_angeltype->angel_type_id])
. '">' . $user_angeltype->angelType->name
. ' (+' . $user_angeltype->count . ')'
. '</a>';
}
@ -65,13 +67,13 @@ function user_angeltypes_delete_all_controller(): array
if (!$request->has('angeltype_id')) {
error(__('Angeltype doesn\'t exist.'));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
$angeltype = AngelType::findOrFail($request->input('angeltype_id'));
if (!auth()->user()->isAngelTypeSupporter($angeltype) && !auth()->can('admin_user_angeltypes')) {
error(__('You are not allowed to delete all users for this angeltype.'));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
if ($request->hasPostData('deny_all')) {
@ -81,7 +83,7 @@ function user_angeltypes_delete_all_controller(): array
engelsystem_log(sprintf('Denied all users for angeltype %s', AngelType_name_render($angeltype, true)));
success(sprintf(__('Denied all users for angeltype %s.'), $angeltype->name));
throw_redirect(url('/angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
}
return [
@ -102,13 +104,13 @@ function user_angeltypes_confirm_all_controller(): array
if (!$request->has('angeltype_id')) {
error(__('Angeltype doesn\'t exist.'));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
$angeltype = AngelType::findOrFail($request->input('angeltype_id'));
if (!auth()->can('admin_user_angeltypes') && !$user->isAngelTypeSupporter($angeltype)) {
error(__('You are not allowed to confirm all users for this angeltype.'));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
if ($request->hasPostData('confirm_all')) {
@ -125,7 +127,7 @@ function user_angeltypes_confirm_all_controller(): array
user_angeltype_confirm_email($user, $angeltype);
}
throw_redirect(url('/angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
}
return [
@ -146,7 +148,7 @@ function user_angeltype_confirm_controller(): array
if (!$request->has('user_angeltype_id')) {
error(__('User angeltype doesn\'t exist.'));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
/** @var UserAngelType $user_angeltype */
@ -154,7 +156,7 @@ function user_angeltype_confirm_controller(): array
$angeltype = $user_angeltype->angelType;
if (!$user->isAngelTypeSupporter($angeltype) && !auth()->can('admin_user_angeltypes')) {
error(__('You are not allowed to confirm this users angeltype.'));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
$user_source = $user_angeltype->user;
@ -171,7 +173,7 @@ function user_angeltype_confirm_controller(): array
user_angeltype_confirm_email($user_source, $angeltype);
throw_redirect(url('/angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
}
return [
@ -186,14 +188,23 @@ function user_angeltype_confirm_email(User $user, AngelType $angeltype): void
return;
}
/** @var EngelsystemMailer $mailer */
$mailer = app(EngelsystemMailer::class);
$mailer->sendViewTranslated(
$user,
'notification.angeltype.confirmed',
'emails/angeltype-confirmed',
['name' => $angeltype->name, 'angeltype' => $angeltype, 'username' => $user->displayName]
);
try {
/** @var EngelsystemMailer $mailer */
$mailer = app(EngelsystemMailer::class);
$mailer->sendViewTranslated(
$user,
'notification.angeltype.confirmed',
'emails/angeltype-confirmed',
['name' => $angeltype->name, 'angeltype' => $angeltype, 'username' => $user->displayName]
);
} catch (TransportException $e) {
/** @var LoggerInterface $logger */
$logger = app('logger');
$logger->error(
'Unable to send email "{title}" to user {user} with {exception}',
['title' => __('notification.angeltype.confirmed'), 'user' => $user->name, 'exception' => $e]
);
}
}
function user_angeltype_add_email(User $user, AngelType $angeltype): void
@ -202,14 +213,23 @@ function user_angeltype_add_email(User $user, AngelType $angeltype): void
return;
}
/** @var EngelsystemMailer $mailer */
$mailer = app(EngelsystemMailer::class);
$mailer->sendViewTranslated(
$user,
'notification.angeltype.added',
'emails/angeltype-added',
['name' => $angeltype->name, 'angeltype' => $angeltype, 'username' => $user->displayName]
);
try {
/** @var EngelsystemMailer $mailer */
$mailer = app(EngelsystemMailer::class);
$mailer->sendViewTranslated(
$user,
'notification.angeltype.added',
'emails/angeltype-added',
['name' => $angeltype->name, 'angeltype' => $angeltype, 'username' => $user->displayName]
);
} catch (TransportException $e) {
/** @var LoggerInterface $logger */
$logger = app('logger');
$logger->error(
'Unable to send email "{title}" to user {user} with {exception}',
['title' => __('notification.angeltype.added'), 'user' => $user->name, 'exception' => $e]
);
}
}
/**
@ -224,35 +244,34 @@ function user_angeltype_delete_controller(): array
if (!$request->has('user_angeltype_id')) {
error(__('User angeltype doesn\'t exist.'));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
/** @var UserAngelType $user_angeltype */
$user_angeltype = UserAngelType::findOrFail($request->input('user_angeltype_id'));
$angeltype = $user_angeltype->angelType;
$user_source = $user_angeltype->user;
$isOwnAngelType = $user->id == $user_source->id;
if (
!$isOwnAngelType
$user->id != $user_angeltype->user_id
&& !$user->isAngelTypeSupporter($angeltype)
&& !auth()->can('admin_user_angeltypes')
) {
error(__('You are not allowed to delete this users angeltype.'));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
if ($request->hasPostData('delete')) {
$user_angeltype->delete();
engelsystem_log(sprintf('User "%s" removed from "%s".', User_Nick_render($user_source, true), $angeltype->name));
success(sprintf($isOwnAngelType ? __('You successfully left "%2$s".') : __('User "%s" removed from "%s".'), $user_source->displayName, $angeltype->name));
engelsystem_log(sprintf('User %s removed from %s.', User_Nick_render($user_source, true), $angeltype->name));
success(sprintf(__('User %s removed from %s.'), $user_source->displayName, $angeltype->name));
throw_redirect(url('/angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
}
return [
__('Leave angeltype'),
UserAngelType_delete_view($user_angeltype, $user_source, $angeltype, $isOwnAngelType),
__('Remove angeltype'),
UserAngelType_delete_view($user_angeltype, $user_source, $angeltype),
];
}
@ -266,21 +285,21 @@ function user_angeltype_update_controller(): array
$supporter = false;
$request = request();
if (!auth()->can('admin_angel_types') && !config('supporters_can_promote')) {
if (!auth()->can('admin_angel_types')) {
error(__('You are not allowed to set supporter rights.'));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
if (!$request->has('user_angeltype_id')) {
error(__('User angeltype doesn\'t exist.'));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
if ($request->has('supporter') && preg_match('/^[01]$/', $request->input('supporter'))) {
$supporter = $request->input('supporter') == '1';
} else {
error(__('No supporter update given.'));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
/** @var UserAngelType $user_angeltype */
@ -302,7 +321,7 @@ function user_angeltype_update_controller(): array
));
success(sprintf($msg, $angeltype->name, $user_source->displayName));
throw_redirect(url('/angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
}
return [
@ -363,7 +382,7 @@ function user_angeltype_add_controller(): array
user_angeltype_add_email($user_source, $angeltype);
throw_redirect(url('/angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
}
}
@ -387,7 +406,7 @@ function user_angeltype_join_controller(AngelType $angeltype)
$user_angeltype = UserAngelType::whereUserId($user->id)->where('angel_type_id', $angeltype->id)->first();
if (!empty($user_angeltype)) {
error(sprintf(__('You are already a %s.'), $angeltype->name));
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
$request = request();
@ -415,11 +434,11 @@ function user_angeltype_join_controller(AngelType $angeltype)
));
}
throw_redirect(url('/angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
throw_redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]));
}
return [
sprintf(__('Become a %s'), htmlspecialchars($angeltype->name)),
sprintf(__('Become a %s'), $angeltype->name),
UserAngelType_join_view($user, $angeltype),
];
}
@ -433,7 +452,7 @@ function user_angeltypes_controller(): array
{
$request = request();
if (!$request->has('action')) {
throw_redirect(url('/angeltypes'));
throw_redirect(page_link_to('angeltypes'));
}
return match ($request->input('action')) {
@ -443,6 +462,6 @@ function user_angeltypes_controller(): array
'delete' => user_angeltype_delete_controller(),
'update' => user_angeltype_update_controller(),
'add' => user_angeltype_add_controller(),
default => throw_redirect(url('/angeltyps')),
default => throw_redirect(page_link_to('angeltyps')),
};
}

View File

@ -0,0 +1,143 @@
<?php
use Engelsystem\Models\User\User;
/**
* Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license
* information provided.
*
* @return string|null
*/
function user_driver_license_required_hint()
{
$user = auth()->user();
// User has already entered data, no hint needed.
if ($user->license->wantsToDrive()) {
return null;
}
$angeltypes = $user->userAngelTypes;
foreach ($angeltypes as $angeltype) {
if ($angeltype->requires_driver_license) {
return sprintf(
__('You joined an angeltype which requires a driving license. Please edit your driving license information here: %s.'),
'<a href="' . user_driver_license_edit_link() . '" class="text-info">' . __('driving license information') . '</a>'
);
}
}
return null;
}
/**
* Route user driver licenses actions.
*
* @return array
*/
function user_driver_licenses_controller()
{
$user = auth()->user();
if (!$user) {
throw_redirect(page_link_to());
}
$action = strip_request_item('action', 'edit');
return match ($action) {
'edit' => user_driver_license_edit_controller(),
default => user_driver_license_edit_controller(),
};
}
/**
* Link to user driver license edit page for given user.
*
* @param User $user
* @return string
*/
function user_driver_license_edit_link($user = null)
{
if (!$user) {
return page_link_to('user_driver_licenses');
}
return page_link_to('user_driver_licenses', ['user_id' => $user->id]);
}
/**
* Loads the user for the driver license.
*
* @return User
*/
function user_driver_license_load_user()
{
$request = request();
$user_source = auth()->user();
if ($request->has('user_id')) {
$user_source = User::find($request->input('user_id'));
if (empty($user_source)) {
throw_redirect(user_driver_license_edit_link());
}
}
return $user_source;
}
/**
* Edit a users driver license information.
*
* @return array
*/
function user_driver_license_edit_controller()
{
$user = auth()->user();
$request = request();
$user_source = user_driver_license_load_user();
// only privilege admin_user can edit other users driver license information
if ($user->id != $user_source->id && !auth()->can('admin_user')) {
throw_redirect(user_driver_license_edit_link());
}
$driverLicense = $user_source->license;
if ($request->hasPostData('submit')) {
if ($request->has('wants_to_drive')) {
$driverLicense->has_car = $request->has('has_car');
$driverLicense->drive_car = $request->has('has_license_car');
$driverLicense->drive_3_5t = $request->has('has_license_3_5t_transporter');
$driverLicense->drive_7_5t = $request->has('has_license_7_5t_truck');
$driverLicense->drive_12t = $request->has('has_license_12t_truck');
$driverLicense->drive_forklift = $request->has('has_license_forklift');
if ($driverLicense->wantsToDrive()) {
$driverLicense->save();
engelsystem_log('Driver license information updated.');
success(__('Your driver license information has been saved.'));
throw_redirect(user_link($user_source->id));
} else {
error(__('Please select at least one driving license.'));
}
} else {
$driverLicense->has_car = false;
$driverLicense->drive_car = false;
$driverLicense->drive_3_5t = false;
$driverLicense->drive_7_5t = false;
$driverLicense->drive_12t = false;
$driverLicense->drive_forklift = false;
$driverLicense->save();
engelsystem_log('Driver license information removed.');
success(__('Your driver license information has been removed.'));
throw_redirect(user_link($user_source->id));
}
}
return [
sprintf(__('Edit %s driving license information'), $user_source->displayName),
UserDriverLicense_edit_view($user_source, $driverLicense),
];
}

View File

@ -1,14 +1,12 @@
<?php
use Engelsystem\Database\Db;
use Engelsystem\Models\AngelType;
use Engelsystem\Models\Shifts\ShiftEntry;
use Engelsystem\Models\User\State;
use Engelsystem\Models\User\User;
use Engelsystem\ShiftCalendarRenderer;
use Engelsystem\ShiftsFilter;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;
/**
@ -22,7 +20,7 @@ function users_controller()
$request = request();
if (!$user) {
throw_redirect(url('/'));
throw_redirect(page_link_to());
}
$action = 'list';
@ -57,7 +55,7 @@ function user_delete_controller()
}
if (!auth()->can('admin_user')) {
throw_redirect(url('/'));
throw_redirect(page_link_to());
}
// You cannot delete yourself
@ -93,7 +91,7 @@ function user_delete_controller()
}
return [
sprintf(__('Delete %s'), htmlspecialchars($user_source->displayName)),
sprintf(__('Delete %s'), $user_source->displayName),
User_delete_view($user_source),
];
}
@ -103,7 +101,7 @@ function user_delete_controller()
*/
function users_link()
{
return url('/users');
return page_link_to('users');
}
/**
@ -112,7 +110,7 @@ function users_link()
*/
function user_edit_link($userId)
{
return url('/admin-user', ['user_id' => $userId]);
return page_link_to('admin_user', ['user_id' => $userId]);
}
/**
@ -121,7 +119,7 @@ function user_edit_link($userId)
*/
function user_delete_link($userId)
{
return url('/users', ['action' => 'delete', 'user_id' => $userId]);
return page_link_to('users', ['action' => 'delete', 'user_id' => $userId]);
}
/**
@ -130,7 +128,7 @@ function user_delete_link($userId)
*/
function user_link($userId)
{
return url('/users', ['action' => 'view', 'user_id' => $userId]);
return page_link_to('users', ['action' => 'view', 'user_id' => $userId]);
}
/**
@ -151,7 +149,7 @@ function user_edit_vouchers_controller()
(!auth()->can('admin_user') && !auth()->can('voucher.edit'))
|| !config('enable_voucher')
) {
throw_redirect(url('/'));
throw_redirect(page_link_to());
}
if ($request->hasPostData('submit')) {
@ -184,7 +182,7 @@ function user_edit_vouchers_controller()
}
return [
sprintf(__('%s\'s vouchers'), htmlspecialchars($user_source->displayName)),
sprintf(__('%s\'s vouchers'), $user_source->displayName),
User_edit_vouchers_view($user_source),
];
}
@ -202,11 +200,11 @@ function user_controller()
$user_source = User::find($request->input('user_id'));
if (!$user_source) {
error(__('User not found.'));
throw_redirect(url('/'));
throw_redirect(page_link_to('/'));
}
}
$shifts = Shifts_by_user($user_source->id, true);
$shifts = Shifts_by_user($user_source->id, auth()->can('user_shifts_admin'));
foreach ($shifts as $shift) {
// TODO: Move queries to model
$shift->needed_angeltypes = Db::select(
@ -236,32 +234,17 @@ function user_controller()
}
if (empty($user_source->api_key)) {
auth()->resetApiKey($user_source);
User_reset_api_key($user_source, false);
}
$goodie_score = sprintf('%.2f', User_goodie_score($user_source->id)) . '&nbsp;h';
if ($user_source->state->force_active && config('enable_force_active')) {
$goodie_score = '<span title="' . $goodie_score . '">' . __('Enough') . '</span>';
if ($user_source->state->force_active) {
$tshirt_score = __('Enough');
} else {
$tshirt_score = sprintf('%.2f', User_tshirt_score($user_source->id)) . '&nbsp;h';
}
$worklogs = $user_source->worklogs()
->with(['user', 'creator'])
->get();
$is_ifsg_supporter = (bool) AngelType::whereRequiresIfsgCertificate(true)
->leftJoin('user_angel_type', 'user_angel_type.angel_type_id', 'angel_types.id')
->where('user_angel_type.user_id', $user->id)
->where('user_angel_type.supporter', true)
->count();
$is_drive_supporter = (bool) AngelType::whereRequiresDriverLicense(true)
->leftJoin('user_angel_type', 'user_angel_type.angel_type_id', 'angel_types.id')
->where('user_angel_type.user_id', $user->id)
->where('user_angel_type.supporter', true)
->count();
return [
htmlspecialchars($user_source->displayName),
$user_source->displayName,
User_view(
$user_source,
auth()->can('admin_user'),
@ -270,14 +253,10 @@ function user_controller()
$user_source->groups,
$shifts,
$user->id == $user_source->id,
$goodie_score,
auth()->can('user.goodie.edit'),
$tshirt_score,
auth()->can('admin_active'),
auth()->can('admin_user_worklog'),
$worklogs,
auth()->can('user.ifsg.edit')
|| $is_ifsg_supporter
|| auth()->can('user.drive.edit')
|| $is_drive_supporter,
UserWorkLogsForUser($user_source->id)
),
];
}
@ -292,7 +271,7 @@ function users_list_controller()
$request = request();
if (!auth()->can('admin_user')) {
throw_redirect(url('/'));
throw_redirect(page_link_to());
}
$order_by = 'name';
@ -307,7 +286,7 @@ function users_list_controller()
'freeloads',
'active',
'force_active',
'got_goodie',
'got_shirt',
'shirt_size',
'planned_arrival_date',
'planned_departure_date',
@ -318,15 +297,13 @@ function users_list_controller()
}
/** @var User[]|Collection $users */
$users = User::with(['contact', 'personalData', 'state', 'shiftEntries' => function (HasMany $query) {
$query->where('freeloaded', true);
}])
$users = User::with(['contact', 'personalData', 'state'])
->orderBy('name')
->get();
foreach ($users as $user) {
$user->setAttribute(
'freeloads',
$user->shiftEntries
$user->shiftEntries()
->where('freeloaded', true)
->count()
);
@ -351,7 +328,7 @@ function users_list_controller()
State::whereActive(true)->count(),
State::whereForceActive(true)->count(),
ShiftEntry::whereFreeloaded(true)->count(),
State::whereGotGoodie(true)->count(),
State::whereGotShirt(true)->count(),
State::query()->sum('got_voucher')
),
];
@ -366,13 +343,13 @@ function load_user()
{
$request = request();
if (!$request->has('user_id')) {
throw_redirect(url('/'));
throw_redirect(page_link_to());
}
$user = User::find($request->input('user_id'));
if (!$user) {
error(__('User doesn\'t exist.'));
throw_redirect(url('/'));
throw_redirect(page_link_to());
}
return $user;
@ -460,57 +437,3 @@ function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter)
return new ShiftCalendarRenderer($filtered_shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
}
/**
* Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license
* information provided.
*
* @return string|null
*/
function user_driver_license_required_hint()
{
$user = auth()->user();
// User has already entered data, no hint needed.
if (!config('driving_license_enabled') || $user->license->wantsToDrive()) {
return null;
}
$angeltypes = $user->userAngelTypes;
foreach ($angeltypes as $angeltype) {
if ($angeltype->requires_driver_license) {
return sprintf(
__('angeltype.driving_license.required.info.here'),
'<a href="' . url('/settings/certificates') . '">' . __('driving_license.info') . '</a>'
);
}
}
return null;
}
function user_ifsg_certificate_required_hint()
{
$user = auth()->user();
// User has already entered data, no hint needed.
if (!config('ifsg_enabled') || $user->license->ifsg_light || $user->license->ifsg) {
return null;
}
$angeltypes = $user->userAngelTypes;
foreach ($angeltypes as $angeltype) {
if (
$angeltype->requires_ifsg_certificate && !(
$user->license->ifsg_certificate || $user->license->ifsg_certificate_light
)
) {
return sprintf(
__('angeltype.ifsg.required.info.here'),
'<a href="' . url('/settings/certificates') . '">' . __('ifsg.info') . '</a>'
);
}
}
return null;
}

View File

@ -4,7 +4,6 @@
* Bootstrap application
*/
use Engelsystem\Application;
use Engelsystem\Http\UrlGeneratorInterface;
require __DIR__ . '/application.php';
@ -19,12 +18,12 @@ require __DIR__ . '/includes.php';
/**
* Check for maintenance
*/
/** @var Application $app */
/** @var \Engelsystem\Application $app */
if ($app->get('config')->get('maintenance')) {
http_response_code(503);
$url = $app->get(UrlGeneratorInterface::class);
$maintenance = file_get_contents(__DIR__ . '/../resources/views/layouts/maintenance.html');
$maintenance = str_replace('%APP_NAME%', htmlspecialchars($app->get('config')->get('app_name')), $maintenance);
$maintenance = str_replace('%APP_NAME%', $app->get('config')->get('app_name'), $maintenance);
$maintenance = str_replace('%ASSETS_PATH%', $url->to(''), $maintenance);
echo $maintenance;
die();

View File

@ -1,7 +1,9 @@
<?php
use Engelsystem\Helpers\Translation\Translator;
use Engelsystem\Mail\EngelsystemMailer;
use Engelsystem\Models\User\User;
use Psr\Log\LogLevel;
/**
* @param User $recipientUser
@ -16,18 +18,38 @@ function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe
return true;
}
/** @var EngelsystemMailer $mailer */
$mailer = app('mailer');
$status = $mailer->sendViewTranslated(
$recipientUser,
$title,
'emails/mail',
['username' => $recipientUser->displayName, 'message' => $message]
);
/** @var Translator $translator */
$translator = app()->get('translator');
$locale = $translator->getLocale();
$status = true;
try {
/** @var EngelsystemMailer $mailer */
$mailer = app('mailer');
$translator->setLocale($recipientUser->settings->language);
$mailer->sendView(
$recipientUser->contact->email ?: $recipientUser->email,
$title,
'emails/mail',
['username' => $recipientUser->displayName, 'message' => $message]
);
} catch (Exception $e) {
$status = false;
engelsystem_log(sprintf(
'An exception occurred while sending a mail to %s in %s:%u: %s',
$recipientUser->name,
$e->getFile(),
$e->getLine(),
$e->getMessage()
), LogLevel::CRITICAL);
}
$translator->setLocale($locale);
if (!$status) {
error(sprintf(__('User %s could not be notified by e-mail due to an error.'), $recipientUser->displayName));
engelsystem_log(sprintf('User %s could not be notified by e-mail due to an error.', $recipientUser->name));
error(sprintf(__('User %s could not be notified by email due to an error.'), $recipientUser->displayName));
engelsystem_log(sprintf('User %s could not be notified by email due to an error.', $recipientUser->name));
}
return $status;

View File

@ -3,8 +3,6 @@
declare(strict_types=1);
use Engelsystem\Renderer\Twig\Extensions\Globals;
use Engelsystem\Helpers\Carbon;
use Engelsystem\Helpers\DayOfEvent;
function theme_id(): int
{
@ -14,6 +12,9 @@ function theme_id(): int
return $globals['themeId'];
}
/**
* @return array
*/
function theme(): array
{
$theme_id = theme_id();
@ -24,16 +25,3 @@ function theme_type(): string
{
return theme()['type'];
}
function dateWithEventDay(string $day): string
{
$date = Carbon::createFromFormat('Y-m-d', $day);
$dayOfEvent = DayOfEvent::get($date);
$dateFormatted = $date->format(__('general.date'));
if (!config('enable_show_day_of_event') || is_null($dayOfEvent)) {
return $dateFormatted;
}
return $dateFormatted . ' (' . $dayOfEvent . ')';
}

View File

@ -17,12 +17,11 @@ function msg()
*
* @param string $msg
* @param bool $immediately
* @param bool $immediatelyRaw
* @return string
*/
function info($msg, $immediately = false, $immediatelyRaw = false)
function info($msg, $immediately = false)
{
return alert(NotificationType::INFORMATION, $msg, $immediately, $immediatelyRaw);
return alert(NotificationType::INFORMATION, $msg, $immediately);
}
/**
@ -30,12 +29,11 @@ function info($msg, $immediately = false, $immediatelyRaw = false)
*
* @param string $msg
* @param bool $immediately
* @param bool $immediatelyRaw
* @return string
*/
function warning($msg, $immediately = false, $immediatelyRaw = false)
function warning($msg, $immediately = false)
{
return alert(NotificationType::WARNING, $msg, $immediately, $immediatelyRaw);
return alert(NotificationType::WARNING, $msg, $immediately);
}
/**
@ -43,12 +41,11 @@ function warning($msg, $immediately = false, $immediatelyRaw = false)
*
* @param string $msg
* @param bool $immediately
* @param bool $immediatelyRaw
* @return string
*/
function error($msg, $immediately = false, $immediatelyRaw = false)
function error($msg, $immediately = false)
{
return alert(NotificationType::ERROR, $msg, $immediately, $immediatelyRaw);
return alert(NotificationType::ERROR, $msg, $immediately);
}
/**
@ -56,27 +53,24 @@ function error($msg, $immediately = false, $immediatelyRaw = false)
*
* @param string $msg
* @param bool $immediately
* @param bool $immediatelyRaw
* @return string
*/
function success($msg, $immediately = false, $immediatelyRaw = false)
function success($msg, $immediately = false)
{
return alert(NotificationType::MESSAGE, $msg, $immediately, $immediatelyRaw);
return alert(NotificationType::MESSAGE, $msg, $immediately);
}
/**
* Renders an alert message with the given alert-* class or sets it in session
*
* @see \Engelsystem\Controllers\HasUserNotifications
*
* @param NotificationType $type
* @param string $msg
* @param bool $immediately
* @param bool $immediatelyRaw
* @return string
*
* @see \Engelsystem\Controllers\HasUserNotifications
*
*/
function alert(NotificationType $type, $msg, $immediately = false, $immediatelyRaw = false)
function alert(NotificationType $type, $msg, $immediately = false)
{
if (empty($msg)) {
return '';
@ -93,7 +87,6 @@ function alert(NotificationType $type, $msg, $immediately = false, $immediatelyR
['danger', 'warning', 'info', 'success'],
$type->value
);
$msg = $immediatelyRaw ? $msg : htmlspecialchars($msg);
return '<div class="alert alert-' . $type . '" role="alert">' . $msg . '</div>';
}

View File

@ -0,0 +1,97 @@
<?php
namespace Engelsystem\Events\Listener;
use Carbon\Carbon;
use Engelsystem\Helpers\Shifts;
use Engelsystem\Mail\EngelsystemMailer;
use Engelsystem\Models\Room;
use Engelsystem\Models\User\User;
use Engelsystem\Models\Worklog;
use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\Exception\TransportException;
class Shift
{
public function __construct(
protected LoggerInterface $log,
protected EngelsystemMailer $mailer
) {
}
public function deletedEntryCreateWorklog(
User $user,
Carbon $start,
Carbon $end,
string $name,
string $title,
string $type,
Room $room,
bool $freeloaded
): void {
if ($freeloaded || $start > Carbon::now()) {
return;
}
$workLog = new Worklog();
$workLog->user()->associate($user);
$workLog->creator()->associate(auth()->user());
$workLog->worked_at = $start->copy()->startOfDay();
$workLog->hours =
(($end->timestamp - $start->timestamp) / 60 / 60)
* Shifts::getNightShiftMultiplier($start, $end);
$workLog->comment = sprintf(
__('%s (%s as %s) in %s, %s - %s'),
$name,
$title,
$type,
$room->name,
$start->format(__('Y-m-d H:i')),
$end->format(__('Y-m-d H:i'))
);
$workLog->save();
$this->log->info(
'Created worklog entry from shift for {user} ({uid}): {worklog})',
['user' => $workLog->user->name, 'uid' => $workLog->user->id, 'worklog' => $workLog->comment]
);
}
public function deletedEntrySendEmail(
User $user,
Carbon $start,
Carbon $end,
string $name,
string $title,
string $type,
Room $room,
bool $freeloaded
): void {
if (!$user->settings->email_shiftinfo) {
return;
}
$subject = 'notification.shift.deleted';
try {
$this->mailer->sendViewTranslated(
$user,
$subject,
'emails/worklog-from-shift',
[
'name' => $name,
'title' => $title,
'start' => $start,
'end' => $end,
'room' => $room,
'freeloaded' => $freeloaded,
'username' => $user->displayName,
]
);
} catch (TransportException $e) {
$this->log->error(
'Unable to send email "{title}" to user {user} with {exception}',
['title' => $subject, 'user' => $user->name, 'exception' => $e]
);
}
}
}

View File

@ -18,34 +18,40 @@ $includeFiles = [
__DIR__ . '/../includes/model/ShiftSignupState.php',
__DIR__ . '/../includes/model/Stats.php',
__DIR__ . '/../includes/model/User_model.php',
__DIR__ . '/../includes/model/UserWorkLog_model.php',
__DIR__ . '/../includes/model/ValidationResult.php',
__DIR__ . '/../includes/view/AngelTypes_view.php',
__DIR__ . '/../includes/view/EventConfig_view.php',
__DIR__ . '/../includes/view/PublicDashboard_view.php',
__DIR__ . '/../includes/view/Locations_view.php',
__DIR__ . '/../includes/view/Rooms_view.php',
__DIR__ . '/../includes/view/ShiftCalendarLane.php',
__DIR__ . '/../includes/view/ShiftCalendarRenderer.php',
__DIR__ . '/../includes/view/ShiftCalendarShiftRenderer.php',
__DIR__ . '/../includes/view/ShiftsFilterRenderer.php',
__DIR__ . '/../includes/view/Shifts_view.php',
__DIR__ . '/../includes/view/ShiftEntry_view.php',
__DIR__ . '/../includes/view/ShiftTypes_view.php',
__DIR__ . '/../includes/view/UserAngelTypes_view.php',
__DIR__ . '/../includes/view/UserDriverLicenses_view.php',
__DIR__ . '/../includes/view/UserHintsRenderer.php',
__DIR__ . '/../includes/view/User_view.php',
__DIR__ . '/../includes/controller/angeltypes_controller.php',
__DIR__ . '/../includes/controller/event_config_controller.php',
__DIR__ . '/../includes/controller/public_dashboard_controller.php',
__DIR__ . '/../includes/controller/locations_controller.php',
__DIR__ . '/../includes/controller/rooms_controller.php',
__DIR__ . '/../includes/controller/shift_entries_controller.php',
__DIR__ . '/../includes/controller/shifts_controller.php',
__DIR__ . '/../includes/controller/shifttypes_controller.php',
__DIR__ . '/../includes/controller/users_controller.php',
__DIR__ . '/../includes/controller/user_angeltypes_controller.php',
__DIR__ . '/../includes/controller/user_driver_licenses_controller.php',
__DIR__ . '/../includes/helper/legacy_helper.php',
__DIR__ . '/../includes/helper/message_helper.php',
__DIR__ . '/../includes/helper/email_helper.php',
__DIR__ . '/../includes/helper/shift_helper.php',
__DIR__ . '/../includes/mailer/shifts_mailer.php',
__DIR__ . '/../includes/mailer/users_mailer.php',
@ -56,8 +62,11 @@ $includeFiles = [
__DIR__ . '/../includes/pages/admin_groups.php',
__DIR__ . '/../includes/pages/admin_shifts.php',
__DIR__ . '/../includes/pages/admin_user.php',
__DIR__ . '/../includes/pages/guest_login.php',
__DIR__ . '/../includes/pages/user_myshifts.php',
__DIR__ . '/../includes/pages/user_shifts.php',
__DIR__ . '/../includes/pages/schedule/ImportSchedule.php',
];
foreach ($includeFiles as $file) {

View File

@ -1,7 +1,87 @@
<?php
use Engelsystem\Models\Shifts\Shift;
use Engelsystem\Models\Shifts\ShiftEntry;
use Engelsystem\Models\User\User;
use Illuminate\Database\Eloquent\Collection;
function mail_shift_change(Shift $old_shift, Shift $new_shift)
{
/** @var ShiftEntry[]|Collection $shiftEntries */
$shiftEntries = $old_shift->shiftEntries()
->with(['user', 'user.settings'])
->get();
$old_room = $old_shift->room;
$new_room = $new_shift->room;
$noticeable_changes = false;
$message = __('A Shift you are registered on has changed:');
$message .= "\n";
if ($old_shift->shift_type_id != $new_shift->shift_type_id) {
$message .= sprintf(
__('* Shift type changed from %s to %s'),
$old_shift->shiftType->name,
$new_shift->shiftType->name
) . "\n";
$noticeable_changes = true;
}
if ($old_shift->title != $new_shift->title) {
$message .= sprintf(__('* Shift title changed from %s to %s'), $old_shift->title, $new_shift->title) . "\n";
$noticeable_changes = true;
}
if ($old_shift->start->timestamp != $new_shift->start->timestamp) {
$message .= sprintf(
__('* Shift Start changed from %s to %s'),
$old_shift->start->format(__('Y-m-d H:i')),
$new_shift->start->format(__('Y-m-d H:i'))
) . "\n";
$noticeable_changes = true;
}
if ($old_shift->end->timestamp != $new_shift->end->timestamp) {
$message .= sprintf(
__('* Shift End changed from %s to %s'),
$old_shift->end->format(__('Y-m-d H:i')),
$new_shift->end->format(__('Y-m-d H:i'))
) . "\n";
$noticeable_changes = true;
}
if ($old_shift->room_id != $new_shift->room_id) {
$message .= sprintf(__('* Shift Location changed from %s to %s'), $old_room->name, $new_room->name) . "\n";
$noticeable_changes = true;
}
if (!$noticeable_changes) {
// There are no changes worth sending an E-Mail
return;
}
$message .= "\n";
$message .= __('The updated Shift:') . "\n";
$message .= $new_shift->shiftType->name . "\n";
$message .= $new_shift->title . "\n";
$message .= $new_shift->start->format(__('Y-m-d H:i')) . ' - ' . $new_shift->end->format(__('H:i')) . "\n";
$message .= $new_room->name . "\n\n";
$message .= url('/shifts', ['action' => 'view', 'shift_id' => $new_shift->id]) . "\n";
foreach ($shiftEntries as $shiftEntry) {
$user = $shiftEntry->user;
if ($user->settings->email_shiftinfo) {
engelsystem_email_to_user(
$user,
__('Your Shift has changed'),
$message,
true
);
}
}
}
function mail_shift_assign(User $user, Shift $shift)
{
@ -9,11 +89,13 @@ function mail_shift_assign(User $user, Shift $shift)
return;
}
$room = $shift->room;
$message = __('You have been assigned to a Shift:') . "\n";
$message .= $shift->shiftType->name . "\n";
$message .= $shift->title . "\n";
$message .= $shift->start->format(__('general.datetime')) . ' - ' . $shift->end->format(__('H:i')) . "\n";
$message .= $shift->location->name . "\n\n";
$message .= $shift->start->format(__('Y-m-d H:i')) . ' - ' . $shift->end->format(__('H:i')) . "\n";
$message .= $room->name . "\n\n";
$message .= url('/shifts', ['action' => 'view', 'shift_id' => $shift->id]) . "\n";
engelsystem_email_to_user($user, __('Assigned to Shift'), $message, true);
@ -25,11 +107,13 @@ function mail_shift_removed(User $user, Shift $shift)
return;
}
$room = $shift->room;
$message = __('You have been removed from a Shift:') . "\n";
$message .= $shift->shiftType->name . "\n";
$message .= $shift->title . "\n";
$message .= $shift->start->format(__('general.datetime')) . ' - ' . $shift->end->format(__('H:i')) . "\n";
$message .= $shift->location->name . "\n";
$message .= $shift->start->format(__('Y-m-d H:i')) . ' - ' . $shift->end->format(__('H:i')) . "\n";
$message .= $room->name . "\n";
engelsystem_email_to_user($user, __('Removed from Shift'), $message, true);
}

View File

@ -10,7 +10,7 @@ function mail_user_delete($user)
{
return engelsystem_email_to_user(
$user,
__('Your account has been deleted.'),
__('Your account has been deleted'),
__(
'Your %s account has been deleted. If you have any questions regarding your account deletion, please contact heaven.',
[config('app_name')]

View File

@ -1,70 +1,47 @@
<?php
use Engelsystem\Database\Db;
use Engelsystem\Models\Shifts\Shift;
use Engelsystem\Models\Shifts\ShiftEntry;
use Illuminate\Database\Eloquent\Collection;
/**
* Returns all needed angeltypes and already taken needs.
*
* @param Shift $shift
* @param int $shiftId id of shift
* @return array
*/
function NeededAngelTypes_by_shift($shift)
function NeededAngelTypes_by_shift($shiftId)
{
$needed_angeltypes_source = [];
// Select from shift
if (!$shift->schedule) {
$needed_angeltypes_source = Db::select(
'
$needed_angeltypes_source = Db::select(
'
SELECT
`needed_angel_types`.*,
`angel_types`.`id`,
`angel_types`.`name`,
`angel_types`.`restricted`,
`angel_types`.`shift_self_signup`
`angel_types`.`no_self_signup`
FROM `needed_angel_types`
JOIN `angel_types` ON `angel_types`.`id` = `needed_angel_types`.`angel_type_id`
WHERE `needed_angel_types`.`shift_id` = ?
ORDER BY `location_id` DESC
',
[$shift->id]
);
}
WHERE `shift_id` = ?
ORDER BY `room_id` DESC',
[$shiftId]
);
// Get needed by shift type
if ($shift->schedule && $shift->schedule->needed_from_shift_type) {
// Use settings from room
if (count($needed_angeltypes_source) == 0) {
$needed_angeltypes_source = Db::select('
SELECT
`needed_angel_types`.*,
`angel_types`.`name`,
`angel_types`.`restricted`,
`angel_types`.`shift_self_signup`
SELECT `needed_angel_types`.*, `angel_types`.`name`, `angel_types`.`restricted`
FROM `needed_angel_types`
JOIN `angel_types` ON `angel_types`.`id` = `needed_angel_types`.`angel_type_id`
WHERE `needed_angel_types`.`shift_type_id` = ?
ORDER BY `location_id` DESC
', [$shift->shift_type_id]);
}
// Load from room
if ($shift->schedule && !$shift->schedule->needed_from_shift_type) {
$needed_angeltypes_source = Db::select('
SELECT
`needed_angel_types`.*,
`angel_types`.`name`,
`angel_types`.`restricted`,
`angel_types`.`shift_self_signup`
FROM `needed_angel_types`
JOIN `angel_types` ON `angel_types`.`id` = `needed_angel_types`.`angel_type_id`
WHERE `needed_angel_types`.`location_id` = ?
ORDER BY `location_id` DESC
', [$shift->location_id]);
JOIN `shifts` ON `shifts`.`room_id` = `needed_angel_types`.`room_id`
WHERE `shifts`.`id` = ?
ORDER BY `room_id` DESC
', [$shiftId]);
}
/** @var ShiftEntry[]|Collection $shift_entries */
$shift_entries = ShiftEntry::with('user', 'angelType')
->where('shift_id', $shift->id)
->where('shift_id', $shiftId)
->get();
$needed_angeltypes = [];
foreach ($needed_angeltypes_source as $angeltype) {

View File

@ -15,7 +15,7 @@ function ShiftEntry_onCreate(ShiftEntry $shiftEntry): void
'User ' . User_Nick_render($shiftEntry->user, true)
. ' signed up for shift ' . $shiftEntry->shift->title
. ' (' . $shift->shiftType->name . ')'
. ' at ' . $shift->location->name
. ' at ' . $shift->room->name
. ' from ' . $shift->start->format('Y-m-d H:i')
. ' to ' . $shift->end->format('Y-m-d H:i')
. ' as ' . $shiftEntry->angelType->name
@ -33,14 +33,14 @@ function ShiftEntry_onDelete(ShiftEntry $shiftEntry)
$signout_user = $shiftEntry->user;
$shift = Shift($shiftEntry->shift);
$shifttype = $shift->shiftType;
$location = $shift->location;
$room = $shift->room;
$angeltype = $shiftEntry->angelType;
engelsystem_log(
'Shift signout: ' . User_Nick_render($signout_user, true)
. ' from shift ' . $shift->title
. ' (' . $shifttype->name . ')'
. ' at ' . $location->name
. ' at ' . $room->name
. ' from ' . $shift->start->format('Y-m-d H:i')
. ' to ' . $shift->end->format('Y-m-d H:i')
. ' as ' . $angeltype->name

Some files were not shown because too many files have changed in this diff Show More