forked from anonaddy/anonaddy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Will
committed
Jun 2, 2020
1 parent
a1b7b78
commit 0fcf355
Showing
28 changed files
with
2,689 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Resources\RuleResource; | ||
use Illuminate\Http\Request; | ||
|
||
class ActiveRuleController extends Controller | ||
{ | ||
public function store(Request $request) | ||
{ | ||
$rule = user()->rules()->findOrFail($request->id); | ||
|
||
$rule->activate(); | ||
|
||
return new RuleResource($rule); | ||
} | ||
|
||
public function destroy($id) | ||
{ | ||
$rule = user()->rules()->findOrFail($id); | ||
|
||
$rule->deactivate(); | ||
|
||
return response('', 204); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\StoreReorderRuleRequest; | ||
use App\Rule; | ||
|
||
class ReorderRuleController extends Controller | ||
{ | ||
public function store(StoreReorderRuleRequest $request) | ||
{ | ||
collect($request->ids)->each(function ($id, $key) { | ||
$rule = Rule::findOrFail($id); | ||
|
||
$rule->update([ | ||
'order' => $key | ||
]); | ||
}); | ||
|
||
return response('', 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\StoreRuleRequest; | ||
use App\Http\Resources\RuleResource; | ||
|
||
class RuleController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
return RuleResource::collection(user()->rules()->orderBy('order')->get()); | ||
} | ||
|
||
public function show($id) | ||
{ | ||
$rule = user()->rules()->findOrFail($id); | ||
|
||
return new RuleResource($rule); | ||
} | ||
|
||
public function store(StoreRuleRequest $request) | ||
{ | ||
$rule = user()->rules()->create([ | ||
'name' => $request->name, | ||
'conditions' => $request->conditions, | ||
'actions' => $request->actions, | ||
'operator' => $request->operator | ||
]); | ||
|
||
return new RuleResource($rule->refresh()); | ||
} | ||
|
||
public function update(StoreRuleRequest $request, $id) | ||
{ | ||
$rule = user()->rules()->findOrFail($id); | ||
|
||
$rule->update([ | ||
'name' => $request->name, | ||
'conditions' => $request->conditions, | ||
'actions' => $request->actions, | ||
'operator' => $request->operator | ||
]); | ||
|
||
return new RuleResource($rule->refresh()); | ||
} | ||
|
||
public function destroy($id) | ||
{ | ||
$rule = user()->rules()->findOrFail($id); | ||
|
||
$rule->delete(); | ||
|
||
return response('', 204); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
class ShowRuleController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
return view('rules.index', [ | ||
'rules' => user()->rules()->orderBy('order')->get() | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use App\Rules\ValidRuleId; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class StoreReorderRuleRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'ids' => [ | ||
'required', | ||
'array', | ||
new ValidRuleId | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rule; | ||
|
||
class StoreRuleRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'name' => [ | ||
'required', | ||
'string', | ||
'max:50' | ||
], | ||
'conditions' => [ | ||
'required', | ||
'array', | ||
'max:5' | ||
], | ||
'conditions.*.type' => [ | ||
'required', | ||
Rule::in([ | ||
'subject', | ||
'sender', | ||
'alias' | ||
]) | ||
], | ||
'conditions.*.match' => [ | ||
'sometimes', | ||
'required', | ||
Rule::in([ | ||
'is exactly', | ||
'is not', | ||
'contains', | ||
'does not contain', | ||
'starts with', | ||
'does not start with', | ||
'ends with', | ||
'does not end with' | ||
]) | ||
], | ||
'conditions.*.values' => [ | ||
'required', | ||
'array', | ||
'min:1', | ||
'max:10' | ||
], | ||
'conditions.*.values.*' => [ | ||
'distinct', | ||
], | ||
'actions' => [ | ||
'required', | ||
'array', | ||
'max:5' | ||
], | ||
'actions.*.type' => [ | ||
'required', | ||
Rule::in([ | ||
'subject', | ||
'displayFrom', | ||
'encryption', | ||
'banner', | ||
'block', | ||
'webhook' | ||
]), | ||
], | ||
'actions.*.value' => [ | ||
'required', | ||
'max:50' | ||
], | ||
'operator' => [ | ||
'required', | ||
'in:AND,OR' | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class RuleResource extends JsonResource | ||
{ | ||
public function toArray($request) | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'user_id' => $this->user_id, | ||
'name' => $this->name, | ||
'order' => $this->order, | ||
'conditions' => $this->conditions, | ||
'actions' => $this->actions, | ||
'operator' => $this->operator, | ||
'active' => $this->active, | ||
'created_at' => $this->created_at->toDateTimeString(), | ||
'updated_at' => $this->updated_at->toDateTimeString(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.