Skip to content

Commit

Permalink
Merge pull request #390 from ZsgsDesign/dev
Browse files Browse the repository at this point in the history
release: 0.4.0 Piranha
  • Loading branch information
ZsgsDesign authored Apr 30, 2020
2 parents b831b63 + 45e47a5 commit 96f1328
Show file tree
Hide file tree
Showing 166 changed files with 8,292 additions and 3,302 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ GOOGLE_ANALYTICS=""
GITHUB_KEY=
GITHUB_SECRET=
GITHUB_CALLBACK_URL=

MOSS_USERID=
185 changes: 185 additions & 0 deletions app/Admin/Controllers/AbuseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<?php

namespace App\Admin\Controllers;

use App\User;
use App\Models\Eloquent\Abuse;
use App\Models\Eloquent\Group;
use App\Models\Eloquent\GroupBanned;
use App\Models\Eloquent\UserBanned;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class AbuseController extends AdminController
{
use HasResourceActions;

/**
* Title for current resource.
*
* @var string
*/
protected $title = 'Abuses';

/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
$grid = new Grid(new Abuse);

$grid->column('id', __('Id'));
$grid->column('title', __('Title'));
$grid->column('cause', __('Cause'))->display(function() {
return Abuse::$cause[$this->cause];
});
$grid->column('supplement', __('Supplement'));
$grid->column('link', __('Link'));
$grid->column('audit', __('Status'))->using(['0' => 'Pending', '1' => 'Passed']);
$grid->column('user', __('Submitter'))->display(function() {
return "#{$this->user_id} {$this->user->name}";
});
$grid->column('created_at', __('Created at'));
$grid->column('updated_at', __('Updated at'));
return $grid;
}

/**
* Make a show builder.
*
* @param mixed $id
* @return Show
*/
protected function detail($id)
{
$show = new Show(Abuse::findOrFail($id));

$show->field('id', __('Id'));
$show->field('title', __('Title'));
$show->field('cause', __('Cause'));
$show->field('supplement', __('Supplement'));
$show->field('link', __('Link'));
$show->field('audit', __('Audit'));
$show->field('user_id', __('User id'));
$show->field('created_at', __('Created at'));
$show->field('updated_at', __('Updated at'));
$show->field('deleted_at', __('Deleted at'));

return $show;
}

/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
$form = new Form(new Abuse);

$form->text('title', __('Title'));
$form->number('cause', __('Cause'));
$form->textarea('supplement', __('Supplement'));
$form->textarea('link', __('Link'));
$form->switch('audit', __('Audit'));
$form->number('user_id', __('User id'));

$form->ignore(['created_at']);

$form->saving(function (Form $form) {
$abuse = $form->model();
//get gategory and subject id
$regex = '/^([A-Za-z]+) #(\d+)/';
$matches = [];
preg_match($regex,$abuse->title,$matches);
$category = array_search(strtolower($matches[1]),Abuse::$supportCategory);
$subject_id = (int)$matches[2];
switch($abuse->category) {
case 0:
$gid = $subject_id;
$group = Group::find($gid);
if(empty($group)) {
return ;
}
if($form->audit) {
$ban_time = request()->created_at;
sendMessage([
'sender' => 1,
'receiver' => $abuse->user_id,
'title' => "Your abuse report about group {$group->name} was passed",
'content' => "Hi, Dear **{$abuse->user->name}**,\n\nWe have checked your Abuse report about group **[{$group->name}]({$group->link})**.\n\n We think you're right.\n\n So as the consequence leading to a temporary/permanent sanction against the group.\n\n Thank you for your contribution to our community environment.\n\n Sincerely, NOJ"
]);
sendMessage([
'sender' => 1,
'receiver' => $group->leader->id,
'title' => "Your group {$group->name} has been banned.",
'content' => "Hi, Dear **{$group->leader->name}**,\n\n For the following reasons: \n\n {$abuse->supplement}\n\n your group **[{$group->name}]({$group->link})** is currently banned and will continue until {$ban_time}.\n\n Before this, only you can enter the group. \n\n Please rectify before this, or you may be subjected to more serious treatment.\n\n Thank you for your contribution to our community environment.\n\n Sincerely, NOJ"
]);
$abuse->delete();
GroupBanned::create([
'abuse_id' => $abuse->id,
'group_id' => $group->gid,
'reason' => $abuse->supplement,
'removed_at' => $ban_time
]);
return ;
}else{
sendMessage([
'sender' => 1,
'receiver' => $abuse->user_id,
'title' => "Your abuse report about group {$group->name} was rejected",
'content' => "Hi, Dear **{$abuse->user->name}**,\n\n We have checked your Abuse report about group **[{$group->name}]({$group->link})**.\n\n However, we regret to say that the information you submitted is not sufficient for us to take action.\n\n Of course, we will continue to follow up the investigation.\n\n Thank you for your contribution to our community environment.\n\n Sincerely, NOJ"
]);
$abuse->delete();
return ;
}
return;
case 1:
$ban_time = request()->created_at;
UserBanned::create([
'abuse_id' => $abuse->id,
'user_id' => $subject_id,
'reason' => $abuse->supplement,
'removed_at' => $ban_time
]);
$abuse->delete();
return;
default:
return;
}


});

return $form;
}

public function edit($id, Content $content)
{
return $content
->header('Check Abuses')
->description('Refer to abuse reports submitted by users')
->body($this->check_form()->edit($id));
}

protected function check_form()
{
$form = new Form(new Abuse);
$form->display('id',__('Abuse id'));
$form->display('title', __('Title'));
$form->display('cause', __('Cause'));
$form->display('supplement', __('Supplement'));
$form->display('link', __('Group Link'));
$form->display('user_id', __('Submitter'));
$form->radio('audit','result')->options(['0' => 'Reject', '1'=> 'Pass']);
$form->datetime('created_at','ban until');

return $form;
}
}
2 changes: 1 addition & 1 deletion app/Admin/Controllers/ContestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected function grid()
});
$grid->registration_due("Registration Due");
$grid->filter(function(Grid\Filter $filter) {
$filter->match('gid');
$filter->equal('gid');
$filter->like('name');
});
return $grid;
Expand Down
4 changes: 2 additions & 2 deletions app/Admin/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public static function general()

$status = [
['name' => 'NOJ Version', 'value' => version()],
['name' => 'Lastest Version', 'value' => is_null($version)?'Failed to fetch latest version':$version["name"]],
['name' => 'Lastest Version', 'value' => is_null($version)?'Failed to fetch latest version':$version["name"]],
['name' => 'Problems', 'value' => \App\Models\Eloquent\ProblemModel::count()],
['name' => 'Solutions', 'value' => \App\Models\Eloquent\ProblemSolutionModel::count()],
['name' => 'Submissions', 'value' => \App\Models\Eloquent\SubmissionModel::count()],
['name' => 'Contests', 'value' => \App\Models\Eloquent\ContestModel::count()],
['name' => 'Users', 'value' => \App\Models\Eloquent\UserModel::count()],
['name' => 'Groups', 'value' => \App\Models\Eloquent\GroupModel::count()],
['name' => 'Groups', 'value' => \App\Models\Eloquent\Group::count()],
];

return view('admin::dashboard.general', [
Expand Down
9 changes: 4 additions & 5 deletions app/Admin/Controllers/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace App\Admin\Controllers;

use App\Models\GroupModel;
use App\Models\Eloquent\GroupModel as EloquentGroupModel;
use App\Models\Eloquent\Group;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
Expand Down Expand Up @@ -80,7 +79,7 @@ public function create(Content $content)
*/
protected function grid()
{
$grid=new Grid(new EloquentGroupModel);
$grid=new Grid(new Group);
$grid->column('gid', "ID")->sortable();
$grid->column("gcode", "Group Code");
$grid->img("Focus Image")->display(function($url) {
Expand Down Expand Up @@ -111,7 +110,7 @@ protected function grid()
*/
protected function detail($id)
{
$show=new Show(EloquentGroupModel::findOrFail($id));
$show=new Show(Group::findOrFail($id));
return $show;
}

Expand All @@ -122,7 +121,7 @@ protected function detail($id)
*/
protected function form()
{
$form=new Form(new EloquentGroupModel);
$form=new Form(new Group);
$form->model()->makeVisible('password');
$form->tab('Basic', function(Form $form) {
$form->display('gid');
Expand Down
Loading

0 comments on commit 96f1328

Please sign in to comment.