'Updates the role with the give datasource permissions.
Permissions not in the request will be revoked. This endpoint should
be available to admins only. Expects JSON in the format:
\'role_name\': \'{role_name}\',
\'database\': [{
\'datasource_type\': \'{table|druid}\',
\'name\': \'{database_name}\',
\'schema\': [{
\'name\': \'{schema_name}\',
\'datasources\': [\'{datasource name}, {datasource name}\']'

@has_access_api
@expose(u'/override_role_permissions/', methods=[u'POST'])
def override_role_permissions(self):

    data = request.get_json(force=True)
    role_name = data[u'role_name']
    databases = data[u'database']
    db_ds_names = set()
    for dbs in databases:
        for schema in dbs[u'schema']:
            for ds_name in schema[u'datasources']:
                fullname = utils.get_datasource_full_name(dbs[u'name'], ds_name, schema=schema[u'name'])
                db_ds_names.add(fullname)
    existing_datasources = ConnectorRegistry.get_all_datasources(db.session)
    datasources = [d for d in existing_datasources if (d.full_name in db_ds_names)]
    role = sm.find_role(role_name)
    role.permissions = []
    granted_perms = []
    for datasource in datasources:
        view_menu_perm = sm.find_permission_view_menu(view_menu_name=datasource.perm, permission_name=u'datasource_access')
        if (view_menu_perm and view_menu_perm.view_menu):
            role.permissions.append(view_menu_perm)
            granted_perms.append(view_menu_perm.view_menu.name)
    db.session.commit()
    return self.json_response({u'granted': granted_perms, u'requested': list(db_ds_names)}, status=201)
