update phân quyền chi tiết

This commit is contained in:
2020-11-02 14:35:22 +07:00
parent c4bb81e55c
commit e4a665dd2e
29 changed files with 1188 additions and 343 deletions

View File

@@ -55,6 +55,12 @@ class AreaController extends Controller {
public function actionCreate() {
$model = new Area();
Yii::$app->response->format = "json";
if (!Yii::$app->user->can(Yii::$app->controller->id . "Create"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$check = Area::findOne(['code' => $data['Code']]);
@@ -81,6 +87,12 @@ class AreaController extends Controller {
public function actionUpdate($id) {
$model = $this->findModel($id);
Yii::$app->response->format = "json";
if (!Yii::$app->user->can(Yii::$app->controller->id . "Update"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$check = Area::findOne(['code' => $data['Code']]);
@@ -112,6 +124,12 @@ class AreaController extends Controller {
}
public function actionDelete() {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Delete"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$lists = Yii::$app->request->post("lists");
foreach ($lists as $key => $value) {
@@ -129,6 +147,9 @@ class AreaController extends Controller {
}
public function actionExport() {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Export"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$objPHPExcel = new \PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$toExcelFile[] = ["Mã khu vực", "Tên khu vực", "khu vực cha", "Chú thích"];

View File

@@ -40,8 +40,10 @@ class AssignController extends Controller {
}
public function actionIndex() {
$this->view->title = 'Cấp quyền truy cập';
if (!Yii::$app->user->can("scheduleAssign"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$this->view->title = 'Cấp quyền truy cập';
return $this->render('index', [
"company" => Department::findOne(1),
"scheduleArray" => Schedule::scheduleArray(),

View File

@@ -0,0 +1,137 @@
<?php
namespace app\controllers;
use Yii;
use app\models\AuthItem;
use app\models\AuthItemSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\helpers\Html;
use yii\helpers\Url;
/**
* AuthItemController implements the CRUD actions for AuthItem model.
*/
class AuthItemController extends Controller {
public function init() {
parent::init();
if (time() > Yii::$app->params["time"])
$this->redirect(["/dashboard"]);
if (Yii::$app->user->isGuest)
return $this->redirect(['/site/login']);
}
/**
* {@inheritdoc}
*/
public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
public function actionIndex() {
if (!Yii::$app->user->can('administrator'))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$this->view->title = 'Phân quyền';
$searchModel = new AuthItemSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->query->andFilterWhere(['type' => 1]);
$dataProvider->query->orderBy(["created_at" => SORT_ASC]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
public function actionCreate() {
$model = new AuthItem();
Yii::$app->response->format = "json";
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$auth = Yii::$app->authManager;
$check = AuthItem::findOne(['name' => $data['Name']]);
if ($check)
return ["status" => false, "type" => "error"];
$author = $auth->createRole($data["Name"]);
$author->description = $data["Description"];
$auth->add($author);
foreach ($data['lists'] as => $value) {
$per = $auth->getPermission($value);
$auth->addChild($author, $per);
}
return ["status" => true];
} else {
return [
"title" => Html::tag("i", "", ["class" => "fa fa-plus-square"]) . " Thêm",
"form" => $this->renderPartial("form", [
"model" => $model,
"url" => Url::to(["create"]),
"roleArray" => AuthItem::$roleArray,
"query" => new AuthItem(),
"child" => []
])
];
}
}
public function actionUpdate($name) {
$model = AuthItem::findOne(['name' => $name]);
Yii::$app->response->format = "json";
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$auth = Yii::$app->authManager;
$check = AuthItem::findOne(['name' => $data['Name']]);
if ($check && $name !== $data["Name"])
return ["status" => false, "type" => "error"];
$author = $auth->getRole($name);
$auth->remove($author);
$author = $auth->createRole($data["Name"]);
$author->description = $data["Description"];
$auth->add($author);
foreach ($data['lists'] as => $value) {
$per = $auth->getPermission($value);
$auth->addChild($author, $per);
}
return ["status" => true];
} else {
return [
"title" => Html::tag("i", "", ["class" => "fa fa-edit"]) . " Tùy chỉnh",
"form" => $this->renderPartial("form", [
"model" => $model,
"url" => Url::to(["update", "name" => $name]),
"roleArray" => AuthItem::$roleArray,
"query" => new AuthItem(),
"child" => $model->childList
])
];
}
}
public function actionDelete() {
if (Yii::$app->request->post()) {
$lists = Yii::$app->request->post("lists");
$auth = Yii::$app->authManager;
foreach ($lists as $key => $value) {
$author = $auth->getRole($value);
$auth->remove($author);
}
}
}
}

View File

@@ -41,6 +41,9 @@ class CardRegisterController extends Controller {
}
public function actionIndex() {
if (!Yii::$app->user->can("staffCardRegister"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$this->view->title = 'Đăng ký thẻ';
$searchModel = new StaffSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

View File

@@ -44,7 +44,6 @@ class DepartmentController extends Controller {
$this->view->title = 'Phòng ban';
$searchModel = new DepartmentSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
@@ -55,6 +54,12 @@ class DepartmentController extends Controller {
public function actionCreate() {
$model = new Department();
Yii::$app->response->format = "json";
if (!Yii::$app->user->can(Yii::$app->controller->id . "Create"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$check = Department::findOne(['code' => $data['Code']]);
@@ -81,6 +86,12 @@ class DepartmentController extends Controller {
public function actionUpdate($id) {
$model = $this->findModel($id);
Yii::$app->response->format = "json";
if (!Yii::$app->user->can(Yii::$app->controller->id . "Update"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$check = Department::findOne(['code' => $data['Code']]);
@@ -112,6 +123,12 @@ class DepartmentController extends Controller {
}
public function actionDelete() {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Delete"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$lists = Yii::$app->request->post("lists");
foreach ($lists as $key => $value) {
@@ -129,6 +146,9 @@ class DepartmentController extends Controller {
}
public function actionExport() {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Export"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$objPHPExcel = new \PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$toExcelFile[] = ["Mã phòng ban", "Tên phòng ban", "Trực thuộc"];
@@ -209,6 +229,9 @@ class DepartmentController extends Controller {
}
public function actionImport() {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Import"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
if (Yii::$app->request->post()) {
$post = Yii::$app->request->post("lists");
$datas = [];

View File

@@ -62,6 +62,12 @@ class DeviceController extends Controller {
public function actionCreate() {
$model = new Device();
Yii::$app->response->format = "json";
if (!Yii::$app->user->can(Yii::$app->controller->id . "Create"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$check = Device::findOne(['ip_address' => $data['Ip']]);
@@ -119,6 +125,12 @@ class DeviceController extends Controller {
public function actionUpdate($id) {
$model = $this->findModel($id);
Yii::$app->response->format = "json";
if (!Yii::$app->user->can(Yii::$app->controller->id . "Update"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$model->name = $data["Name"];
@@ -142,6 +154,12 @@ class DeviceController extends Controller {
}
public function actionDelete() {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Delete"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$lists = Yii::$app->request->post("lists");
foreach ($lists as $key => $value) {
@@ -166,6 +184,9 @@ class DeviceController extends Controller {
}
public function actionExport() {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Export"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$objPHPExcel = new \PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$toExcelFile[] = ["Tên thiết bị", "Serial", "Địa chỉ IP", "Loại thiết bị", "Khu vực"];
@@ -239,6 +260,12 @@ class DeviceController extends Controller {
public function actionChangeIp($id) {
$model = $this->findModel($id);
Yii::$app->response->format = "json";
if (!Yii::$app->user->can(Yii::$app->controller->id . "ChangeIP"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$OldIpAddress = $model->ip_address;
@@ -275,6 +302,9 @@ class DeviceController extends Controller {
}
public function actionSearch() {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Search"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$data = Yii::$app->request->post();

View File

@@ -47,17 +47,23 @@ class LogsController extends Controller {
$f = $t = 0;
$this->view->title = 'Tất cả sự kiện';
if ($type === "today" && $from === "" && $to === "") {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Today"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . date("d/m/Y")), 'U');
$t = date_format(date_create_from_format('H:i:s d/m/Y', "23:59:59 " . date("d/m/Y")), 'U');
$this->view->title = 'Sự kiện hôm nay';
}
if ($type === "3days" && $from === "" && $to === "") {
if (!Yii::$app->user->can(Yii::$app->controller->id . "3days"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . date("d/m/Y")), 'U');
$f = $f - 60 * 60 * 24 * 2;
$t = date_format(date_create_from_format('H:i:s d/m/Y', "23:59:59 " . date("d/m/Y")), 'U');
$this->view->title = 'Sự kiện 3 ngày gần đây';
}
if ($type === "thisWeek" && $from === "" && $to === "") {
if (!Yii::$app->user->can(Yii::$app->controller->id . "ThisWeek"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$dayOfWeek = date("w");
$f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . date("d/m/Y")), 'U');
$f = $f - 60 * 60 * 24 * ($dayOfWeek - 1);
@@ -66,6 +72,8 @@ class LogsController extends Controller {
$this->view->title = 'Sự kiện tuần này';
}
if ($type === "lastWeek" && $from === "" && $to === "") {
if (!Yii::$app->user->can(Yii::$app->controller->id . "LastWeek"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$dayOfWeek = date("w");
$f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . date("d/m/Y")), 'U');
$f = $f - 60 * 60 * 24 * ($dayOfWeek - 1) - 60 * 60 * 24 * 7;
@@ -97,6 +105,8 @@ class LogsController extends Controller {
}
public function actionStatistics($day = "") {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Statistics"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$day = $day === "" ? date("d/m/Y") : $day;
$f = date_format(date_create_from_format('H:i:s d/m/Y', "00:00:00 " . $day), 'U');
$t = date_format(date_create_from_format('H:i:s d/m/Y', "23:59:59 " . $day), 'U');

View File

@@ -52,6 +52,12 @@ class ScheduleController extends Controller {
public function actionCreate() {
$model = new Schedule();
Yii::$app->response->format = "json";
if (!Yii::$app->user->can(Yii::$app->controller->id . "Create"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$post = Yii::$app->request->post();
$data = [
@@ -98,6 +104,12 @@ class ScheduleController extends Controller {
public function actionUpdate($id) {
$model = $this->findModel($id);
Yii::$app->response->format = "json";
if (!Yii::$app->user->can(Yii::$app->controller->id . "Update"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$post = Yii::$app->request->post();
$model->name = $post["Name"];
@@ -141,6 +153,12 @@ class ScheduleController extends Controller {
}
public function actionDelete() {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Delete"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$lists = Yii::$app->request->post("lists");
Schedule::deleteAll(["IN", "id", $lists]);

View File

@@ -58,6 +58,12 @@ class StaffController extends Controller {
public function actionCreate() {
$model = new Staff();
Yii::$app->response->format = "json";
if (!Yii::$app->user->can(Yii::$app->controller->id . "Create"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$check = Staff::findOne(['code' => $data['Code']]);
@@ -90,6 +96,12 @@ class StaffController extends Controller {
public function actionUpdate($id) {
$model = $this->findModel($id);
Yii::$app->response->format = "json";
if (!Yii::$app->user->can(Yii::$app->controller->id . "Update"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$check = Staff::findOne(['code' => $data['Code']]);
@@ -135,6 +147,12 @@ class StaffController extends Controller {
}
public function actionDelete() {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Delete"))
return [
"title" => Html::tag("i", "", ["class" => "fa fa-info-circle"]) . " Cảnh báo",
"form" => "Bạn không có quyền truy cập"
];
if (Yii::$app->request->post()) {
$lists = Yii::$app->request->post("lists");
Staff::deleteAll(["IN", "id", $lists]);
@@ -151,6 +169,9 @@ class StaffController extends Controller {
}
public function actionExport() {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Export"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
$objPHPExcel = new \PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$toExcelFile[] = ["Mã nhân viên", "Tên nhân viên", "Số thẻ", "Phòng ban", "Giới tính", "Ngày sinh", "Email", "Điện thoại", "Ngày bắt đầu làm việc", "Địa chỉ"];
@@ -259,6 +280,9 @@ class StaffController extends Controller {
}
public function actionImport() {
if (!Yii::$app->user->can(Yii::$app->controller->id . "Import"))
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
if (Yii::$app->request->post()) {
$post = Yii::$app->request->post("lists");
$datas = [];