12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace App\Http\Controllers;
- use App\Models;
- use foo\bar;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Validator;
- // todo 返回值为 数字代码还是json还是其他格式待定
- class PermissionController extends Controller
- {
- /**
- * 分配用户可以查看的菜单的内容
- *
- * @param Request $request
- * @return string
- */
- public function AssignActionBars(Request $request)
- {
- $validator = Validator::make($request->all(), [
- "ownerType" => "required|max:32",
- "ownerId" => "required|integer|min:1",
- ]);
- if ($validator->fails()) {
- return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors());
- }
- // 这里的uid从中间件那里获得
- $currentUid = $request->input("currentUid");
- $ownerId = (int)$request->input("ownerId");
- $ownerType = $request->input("ownerType");
- $barIdsStr = trim($request->input("barIds"));
- $barIds = $barIdsStr == "" ? [] : explode(",", $barIdsStr);
- // 判断当前用户是否有权分配权限
- $userRole = new Models\UserRole();
- $role = $userRole->LoadRoleByUid($currentUid);
- if (!$role || $role["status"] != "normal" || $role["role"] != "admin") {
- // return $this->fail(PERMISSION_DENIED, $this->error[PERMISSION_DENIED]);
- }
- // 有权分配
- $userActionBar = new Models\UserActionBar();
- $result = $userActionBar->AssignUserActionBar($ownerType, $ownerId, $barIds);
- if ($result["code"] == 0) {
- return $this->success($result["data"]);
- }
- return $this->fail($result["code"], $this->error[$result["code"]]);
- }
- /**
- * 分配用户权限,是管理员或者普通用户的权限
- *
- * @param Request $request
- * @return string
- */
- public function AssignUserRole(Request $request)
- {
- $uid = $request->input("uid");
- $roles = $request->input("roles");
- $currentUid = 1;
- $userRole = new Models\UserRole();
- $role = $userRole->LoadRoleByUid($currentUid);
- if (!$role || $role->status != "normal" || $role->role & 1 == 0) {
- return "permission denied";
- }
- // 有权分配
- $userRole->AssignRoles($uid, $role);
- return"success";
- }
- }
|