def save_grant(client_id, code, request, *args, **kwargs): expires = datetime.utcnow() + timedelta(seconds=100) grant = Grant(client_id=client_id, code=code['code'], redirect_uri=request.redirect_uri, scopes=request.scopes, user=get_session_user().key.integer_id(), expires=expires) grant.put() return grant
def save_grant(client_id, code, request, *args, **kwargs): expires = datetime.utcnow() + timedelta(seconds=3600) user = User.objects.get(id=current_user.id) grant = Grant( client_id=client_id, code=code['code'], redirect_uri=request.redirect_uri, _scopes=' '.join(request.scopes), user=user, user_id=user.id, expires=expires ) grant.save() return grant
def set_grant(client_id, code, request, *args, **kwargs): expires = datetime.utcnow() + timedelta(seconds=120000) redirect_params = {'code': code['code'], 'state': request.state} logger.debug('set grant - redirect_params: {}\n'.format( json.dumps(redirect_params))) redirect_uri = '{}?{}'.format(request.redirect_uri, urllib.urlencode(redirect_params)) grant = Grant( client_id=client_id, code=code['code'], redirect_uri=redirect_uri, scope=' '.join(request.scopes), userId=g.user.userId, expires=expires, ) logger.debug('grant', grant.__dict__) grant.save() return grant
def validate_user_roles(self, user, roles=[]): # There is no role restriction if not roles: return True for role in roles: if Grant.check_grant(user, role): return True return False
def update_fundingconnections(connections, ftype, direction): # Delete and connections that have been removed. new_connections = [connection['id'] for connection in connections if connection['id']] # TODO: See if you can make this generic to handle any set of connections for simplicity. # TODO: Maybe list comprehensions in stead depending on how cascade='delete-orphan' works. if ftype is 'investment': if direction is 'given': for connection in entity.investments_made: if connection.id not in new_connections: db.delete(connection) elif direction is 'received': for connection in entity.investments_received: if connection.id not in new_connections: db.delete(connection) elif ftype is 'grant': if direction is 'given': for connection in entity.grants_given: if connection.id not in new_connections: db.delete(connection) elif direction is 'received': for connection in entity.grants_received: if connection.id not in new_connections: db.delete(connection) db.commit() for connection in connections: if connection['id']: # Connection exists, update amount and year. oldconnection = Fundingconnection.query.get(connection['id']) if oldconnection.amount != connection['amount']: oldconnection.amount = connection['amount'] app.logger.debug('UPDATING ' + ftype + ' AMOUNT: ' + str(oldconnection.amount)) if oldconnection.year != connection['year']: oldconnection.year = connection['year'] app.logger.debug('UPDATING ' + ftype + ' YEAR: ' + str(oldconnection.year)) elif 'entity_id' in connection: # Connection doesn't exist, create it connect entities. otherentity = Entity.query.get(connection['entity_id']) if ftype is 'investment': newconnection = Investment(connection['amount'], connection['year']) if direction is 'given': entity.investments_made.append(newconnection) otherentity.investments_received.append(newconnection) elif direction is 'received': entity.investments_received.append(newconnection) otherentity.investments_made.append(newconnection) elif ftype is 'grant': newconnection = Grant(connection['amount'], connection['year']) if direction is 'given': entity.grants_given.append(newconnection) otherentity.grants_received.append(newconnection) elif direction is 'received': entity.grants_received.append(newconnection) otherentity.grants_given.append(newconnection) db.commit()
def save_grant(client_id, code, request, *args, **kwargs): expires = datetime.utcnow() + timedelta(seconds=100) grant = Grant(client_id=client_id, code=code['code'], redirect_uri=request.redirect_uri, _scopes=' '.join(request.scopes), user=current_user, expires=expires) db.session.add(grant) db.session.commit() return grant
def save_grant(client_id, code, request, *args, **kwargs): # decide the expires time yourself print("save grant") expires = datetime.utcnow() + timedelta(seconds=100) grant = Grant( client_id=client_id, code=code['code'], redirect_uri=request.redirect_uri, _scopes=' '.join(request.scopes), user=get_current_user(), expires=expires ) print(grant) db.session.add(grant) db.session.commit() return grant
def _grantsetter(self, client_id, code, req, *args, **kwargs): import uuid from models import Grant # decide the expires time yourself expires = datetime.utcnow() + timedelta(days=1) grant = Grant(id=str(uuid.uuid4()), client_id=client_id, code=code['code'], redirect_uri=req.redirect_uri, _scopes=' '.join(req.scopes), user=req.client.user_id if req and req.client else None, expires=expires) from flask import current_app as app session = app.db.session session.add(grant) session.commit() return grant
def grant(path, entity): cap_id = str(uuid.uuid4()) item = Grant(cap_id=cap_id, internal_path=path, db_entity=entity) item.save() return Capability(cap_url(cap_id))
def get_grant(client_id, code): logger.debug('get grant - client_id: {} code: {}\n'.format( client_id, code)) return next(Grant.query(client_id, code))
def load_grant(client_id, code): grant = Grant.query(Grant.client_id == client_id, Grant.code == code).fetch(1) if grant: return grant[0] return None