static function addRoutes($app, $authenticateForRole)
 {
     //* /role/ routes - admin users only
     $app->group('/role', $authenticateForRole('admin'), function () use($app) {
         /*
          * id
          */
         $app->map("/get/:roleId/", function ($roleId) use($app) {
             RoleController::getRole($app, $roleId);
         })->via('GET', 'POST');
         /*
          * role, desc
          */
         $app->post("/insert/", function () use($app) {
             RoleController::addRole($app);
         });
         /*
          * id, role, desc
          */
         $app->post("/update/:roleId/", function ($roleId) use($app) {
             RoleController::saveRole($app, $roleId);
         });
         /*
          * id
          */
         $app->map("/delete/:roleId/", function ($roleId) use($app) {
             RoleController::deleteRole($app, $roleId);
         })->via('DELETE', 'POST');
         /*
          * roleId, fieldId
          */
         $app->post("/unassign-field/", function () use($app) {
             RoleController::unassignField($app);
         });
         /*
          * roleId, fieldId
          */
         $app->post("/assign-field/", function () use($app) {
             RoleController::assignField($app);
         });
         /*
          * roleId, groupId
          */
         $app->post("/unassign-group/", function () use($app) {
             RoleController::unassignGroup($app);
         });
         /*
          * roleId, groupId
          */
         $app->post("/assign-group/", function () use($app) {
             RoleController::assignGroup($app);
         });
     });
 }
Example #2
0
Crave::requireFiles(MODEL, array('BaseModel', 'RoleModel'));
Crave::requireFiles(CONTROLLER, array('RoleController'));
if (isset($_REQUEST['intent'])) {
    $intent = $_REQUEST['intent'];
} else {
    echo JsonResponse::error('Intent not set!');
    exit;
}
if ($intent == "assignRole") {
    if (isset($_REQUEST['userid'], $_REQUEST['role_id'], $_REQUEST['permission_id'])) {
        $role_array = array();
        $role_array[PermissionRoleTable::userid] = $_REQUEST['userid'];
        $role_array[PermissionRoleTable::staff_role_id] = $_REQUEST['role_id'];
        $role_array[PermissionRoleTable::staff_permission_id] = $_REQUEST['permission_id'];
        $conductor = new RoleController();
        $response = $conductor->addRole($role_array);
        if ($response[P_STATUS] == STATUS_OK) {
            echo JsonResponse::message(STATUS_OK, 'Role added successfully!');
            exit;
        } else {
            echo JsonResponse::error($response[P_MESSAGE]);
            exit;
        }
    } else {
        echo JsonResponse::error('Incomplete request parameters!');
        exit;
    }
} elseif ($intent == "dismissRole") {
    if (isset($_REQUEST['permission_role_id'])) {
        $conductor = new RoleController();
        $response = $conductor->dismissRole($_REQUEST['permission_role_id']);