Beispiel #1
0
 co(function*(){
     var right =  yield thunkQuery(Right.select().where(req.params));
     if(!_.first(right)){
         throw new HttpError(404, 'Not found');
     }
     return right;
 }).then(function(data){
Beispiel #2
0
    co(function* () {
      var isExists = yield thunkQuery(Role_rights.select().where(req.params));
      if (_.first(isExists)) {
          throw new HttpError(403, 106);
      }

      var Right = yield thunkQuery(Rights.select().where(Rights.id.equals(req.params.rightID)));
      if (!_.first(Right)){
        throw new HttpError(400, 'This right does not exist');
      }

      var Role = yield thunkQuery(Roles.select().where(Roles.id.equals(req.params.roleID)));
      Role = _.first(Role);

      if (!Role){
        throw new HttpError(400, 'This role does not exist');
      }

      if (Role && !Role.isSystem){
        throw new HttpError(400, 'You can add right only to system roles. For simple roles use access matrices');
      }
    
      var result = yield thunkQuery(Role_rights.insert(req.params));

      return result;
    }).then(function (data) {
Beispiel #3
0
    co(function* (){
      existMatrix = yield thunkQuery(AccessMatrix.select().from(AccessMatrix).where(AccessMatrix.id.equals(req.body.matrixId)));
      if(!_.first(existMatrix)){
        throw new HttpError(403, 'Matrix with this id does not exist');
      }

      existRole = yield thunkQuery(Role.select().from(Role).where(Role.id.equals(req.body.roleId)));
      if(!_.first(existRole)){
        throw new HttpError(403, 'Role with this id does not exist');
      }

      existRight = yield thunkQuery(Right.select().from(Right).where(Right.id.equals(req.body.rightId)));
      if(!_.first(existRight)){
        throw new HttpError(403, 'Right with this id does not exist');
      }

      return yield thunkQuery(AccessPermission.insert(req.body).returning(AccessPermission.id));
    }).then(function(data){
Beispiel #4
0
    co(function* () {
      var _counter = thunkQuery(Right.select(Right.count('counter')), _.omit(req.query, 'offset', 'limit', 'order'));
      var right = thunkQuery(Right.select(), req.query);

      return yield [_counter, right];
    }).then(function (data) {