Skip to content

Commit

Permalink
Merge pull request #31 from mum-project/next
Browse files Browse the repository at this point in the history
Upgrade Laravel base, remove unused features
  • Loading branch information
martbock authored Jan 28, 2021
2 parents 9ec2898 + 9b52efc commit 1d315fd
Show file tree
Hide file tree
Showing 169 changed files with 16,463 additions and 14,315 deletions.
21 changes: 0 additions & 21 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,11 @@ MAIL_PASSWORD=
# MAILBOXES_HOMEDIR=/srv/mail/mailboxes/%d/%n
# MAILBOXES_MAILDIR=maildir:/srv/mail/mailboxes/%d/%n:LAYOUT=fs

# SYSTEM_HEALTH_CHECK_SERVICES=false
# SYSTEM_HEALTH_CHECK_FREQUENCY=5min
# SYSTEM_HEALTH_MAX_ENTRIES_INCIDENT_HISTORY=100

# SIZE_MEASUREMENTS_DELETE_OLD=true
# SIZE_MEASUREMENTS_DELETE_AFTER_MONTHS=12
# SIZE_MEASUREMENTS_DELETE_AFTER_WEEKS=0
# SIZE_MEASUREMENTS_DELETE_AFTER_DAYS=0

# ENABLE_INTEGRATIONS=false
# INTEGRATIONS_ENABLE_SHELL_COMMANDS=false
# INTEGRATIONS_ENABLE_WEB_HOOKS=false
# INTEGRATIONS_SHELL_COMMANDS_FAILED_RETRY_DELAY=60
# INTEGRATIONS_SHELL_COMMANDS_ALLOW_PARAMETERS=false
# INTEGRATIONS_WEB_HOOKS_FAILED_RETRY_DELAY=60
# INTEGRATIONS_SHELL_COMMAND_01=
# INTEGRATIONS_SHELL_COMMAND_02=
# INTEGRATIONS_SHELL_COMMAND_03=
# INTEGRATIONS_SHELL_COMMAND_04=
# INTEGRATIONS_SHELL_COMMAND_05=
# INTEGRATIONS_SHELL_COMMAND_06=
# INTEGRATIONS_SHELL_COMMAND_07=
# INTEGRATIONS_SHELL_COMMAND_08=
# INTEGRATIONS_SHELL_COMMAND_09=
# INTEGRATIONS_SHELL_COMMAND_10=

# SHOW_EMAIL_SETTINGS=true

SMTP_HOSTNAME=smtp.example.com
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ yarn-error.log
.DS_Store
/coverage_report
.php_cs.cache
/build/
/build/
.phpunit.result.cache
14 changes: 11 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ os:
language: php

php:
- 7.2
- 7.3
- 8.0

before_script:
- cp .env.travis .env
- composer self-update
- composer install --prefer-source --no-interaction --dev
- php artisan key:generate
- php artisan migrate
- npm install
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
Expand All @@ -26,10 +26,18 @@ before_install:

script:
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- npm run production

after_script:
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi

services:
- mysql

jobs:
include:
- language: node_js
node_js: 14
before_script:
- npm install
script:
- npm run production
83 changes: 29 additions & 54 deletions app/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

namespace App;

use App\Interfaces\Integratable;
use App\Scopes\ExcludeAutoDeactivatedAliasesScope;
use App\Traits\QueryFilterTrait;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class Alias extends Model implements Integratable
class Alias extends Model
{
use QueryFilterTrait;
use HasFactory, QueryFilterTrait;

/**
* The attributes that aren't mass assignable.
Expand Down Expand Up @@ -42,9 +45,9 @@ protected static function boot()
/**
* Gets the domain that this alias belongs to.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
* @return BelongsTo
*/
public function domain()
public function domain(): BelongsTo
{
return $this->belongsTo(Domain::class);
}
Expand All @@ -53,9 +56,9 @@ public function domain()
* Gets all mailboxes that have permission to send emails with this alias as the sender address (MAIL FROM).
* This collection does NOT include mailboxes that match one of the destination addresses of the alias.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
* @return BelongsToMany
*/
public function senderMailboxes()
public function senderMailboxes(): BelongsToMany
{
return $this->belongsToMany(Mailbox::class, 'alias_senders');
}
Expand All @@ -69,19 +72,19 @@ public function senderMailboxes()
* you have to insert values into the table manually.
* It is NOT possible to use the Eloquent relationship save() method.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
* @return BelongsToMany
*/
public function recipientMailboxes()
public function recipientMailboxes(): BelongsToMany
{
return $this->belongsToMany(Mailbox::class, 'alias_recipients');
}

/**
* Gets all entries of alias recipients, whether they are local mailboxes or external addresses.
*
* @return \Illuminate\Support\Collection
* @return Collection
*/
public function recipients()
public function recipients(): Collection
{
return DB::table('alias_recipients')
->where('alias_id', '=', $this->id)
Expand All @@ -91,9 +94,9 @@ public function recipients()
/**
* Gets all external alias recipient addresses.
*
* @return \Illuminate\Support\Collection
* @return Collection
*/
public function externalRecipients()
public function externalRecipients(): Collection
{
return DB::table('alias_recipients')
->where('alias_id', '=', $this->id)
Expand All @@ -105,9 +108,9 @@ public function externalRecipients()
* Gets a collection of external recipients that is
* compatible with the Javascript frontend code.
*
* @return \Illuminate\Support\Collection
* @return Collection
*/
public function getExternalRecipientResource()
public function getExternalRecipientResource(): Collection
{
return $this->externalRecipients()
->map(function ($externalRecipient) {
Expand All @@ -121,9 +124,9 @@ public function getExternalRecipientResource()
/**
* Gets all recipient addresses (as a string) INCLUDING external ones.
*
* @return mixed
* @return Collection
*/
public function recipientAddresses()
public function recipientAddresses(): Collection
{
return DB::table('alias_recipients')
->where('alias_id', $this->id)
Expand All @@ -135,7 +138,7 @@ public function recipientAddresses()
*
* @return string
*/
public function address()
public function address(): string
{
return $this->local_part . '@' . $this->domain->domain;
}
Expand All @@ -146,7 +149,7 @@ public function address()
* @param Mailbox $mailbox
* @return bool
*/
public function addRecipientMailbox(Mailbox $mailbox)
public function addRecipientMailbox(Mailbox $mailbox): bool
{
return DB::table('alias_recipients')
->insert([
Expand All @@ -162,7 +165,7 @@ public function addRecipientMailbox(Mailbox $mailbox)
* @param Mailbox $mailbox
* @return bool
*/
public function removeRecipientMailbox(Mailbox $mailbox)
public function removeRecipientMailbox(Mailbox $mailbox): bool
{
return DB::table('alias_recipients')
->where([
Expand All @@ -186,7 +189,7 @@ public function removeRecipientMailbox(Mailbox $mailbox)
* @param string $address
* @return bool
*/
public function addExternalRecipient(string $address)
public function addExternalRecipient(string $address): bool
{
return DB::table('alias_recipients')
->insert([
Expand All @@ -201,7 +204,7 @@ public function addExternalRecipient(string $address)
* @param string $address
* @return bool
*/
public function removeExternalRecipient(string $address)
public function removeExternalRecipient(string $address): bool
{
return DB::table('alias_recipients')
->whereNull('mailbox_id')
Expand All @@ -225,7 +228,7 @@ public function removeExternalRecipient(string $address)
*
* @return bool
*/
public function removeAllExternalRecipients()
public function removeAllExternalRecipients(): bool
{
return DB::table('alias_recipients')
->whereNull('mailbox_id')
Expand All @@ -244,7 +247,7 @@ public function removeAllExternalRecipients()
*
* @return int
*/
public function removeAllRecipientMailboxes()
public function removeAllRecipientMailboxes(): int
{
return DB::table('alias_recipients')
->whereNotNull('mailbox_id')
Expand All @@ -258,43 +261,15 @@ public function removeAllRecipientMailboxes()
->delete();
}

/**
* Gets all available placeholders for integrations.
* Example: ['placeholder' => $model->value]
*
* @return array
*/
public function getIntegratablePlaceholders()
{
return [
'id' => $this->id,
'local_part' => $this->local_part,
'address' => $this->address(),
'description' => $this->description,
'domain' => $this->domain->domain,
'active' => $this->active
];
}

/**
* Gets the class name of the integratable.
*
* @return string
*/
public function getIntegratableClassName()
{
return static::class;
}

/**
* Scope a query to only include aliases that the authenticated
* mailbox user is authorized to view.
*
* @param Builder $query
* @param Builder $query
* @param Mailbox|null $mailbox
* @return Builder
*/
public function scopeWhereAuthorized(Builder $query, Mailbox $mailbox = null)
public function scopeWhereAuthorized(Builder $query, Mailbox $mailbox = null): Builder
{
if (isUserSuperAdmin()) {
return $query;
Expand Down
Loading

0 comments on commit 1d315fd

Please sign in to comment.