-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from hailocab/permission_system
Permission system
- Loading branch information
Showing
54 changed files
with
2,890 additions
and
2,091 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
source .env | ||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
Script to test concurrency (multithreading/multiprocess) issues with the workers. Use with caution. | ||
""" | ||
import json | ||
import atfork | ||
atfork.monkeypatch_os_fork_functions() | ||
import atfork.stdlib_fixer | ||
atfork.stdlib_fixer.fix_logging_module() | ||
|
||
import time | ||
from redash.data import worker | ||
from redash import models, data_manager, redis_connection | ||
|
||
if __name__ == '__main__': | ||
models.create_db(True, False) | ||
|
||
print "Creating data source..." | ||
data_source = models.DataSource.create(name="Concurrency", type="pg", options="dbname=postgres") | ||
|
||
print "Clear jobs/hashes:" | ||
redis_connection.delete("jobs") | ||
query_hashes = redis_connection.keys("query_hash_*") | ||
if query_hashes: | ||
redis_connection.delete(*query_hashes) | ||
|
||
starting_query_results_count = models.QueryResult.select().count() | ||
jobs_count = 5000 | ||
workers_count = 10 | ||
|
||
print "Creating jobs..." | ||
for i in xrange(jobs_count): | ||
query = "SELECT {}".format(i) | ||
print "Inserting: {}".format(query) | ||
data_manager.add_job(query=query, priority=worker.Job.LOW_PRIORITY, | ||
data_source=data_source) | ||
|
||
print "Starting workers..." | ||
workers = data_manager.start_workers(workers_count) | ||
|
||
print "Waiting for jobs to be done..." | ||
keep_waiting = True | ||
while keep_waiting: | ||
results_count = models.QueryResult.select().count() - starting_query_results_count | ||
print "QueryResults: {}".format(results_count) | ||
time.sleep(5) | ||
if results_count == jobs_count: | ||
print "Yay done..." | ||
keep_waiting = False | ||
|
||
data_manager.stop_workers() | ||
|
||
qr_count = 0 | ||
for qr in models.QueryResult.select(): | ||
number = int(qr.query.split()[1]) | ||
data_number = json.loads(qr.data)['rows'][0].values()[0] | ||
|
||
if number != data_number: | ||
print "Oops? {} != {} ({})".format(number, data_number, qr.id) | ||
qr_count += 1 | ||
|
||
print "Verified {} query results.".format(qr_count) | ||
|
||
print "Done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import peewee | ||
from redash import db | ||
from redash import models | ||
|
||
|
||
if __name__ == '__main__': | ||
db.connect_db() | ||
|
||
previous_default_permissions = models.User.DEFAULT_PERMISSIONS[:] | ||
previous_default_permissions.remove('view_query') | ||
models.User.update(permissions=peewee.fn.array_append(models.User.permissions, 'view_query')).where(peewee.SQL("'view_source' = any(permissions)")).execute() | ||
|
||
db.close_db(None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import logging | ||
import peewee | ||
from playhouse.migrate import Migrator | ||
from redash import db | ||
from redash import models | ||
from redash import settings | ||
|
||
if __name__ == '__main__': | ||
db.connect_db() | ||
|
||
if not models.DataSource.table_exists(): | ||
print "Creating data_sources table..." | ||
models.DataSource.create_table() | ||
|
||
default_data_source = models.DataSource.create(name="Default", | ||
type=settings.CONNECTION_ADAPTER, | ||
options=settings.CONNECTION_STRING) | ||
else: | ||
default_data_source = models.DataSource.select().first() | ||
|
||
migrator = Migrator(db.database) | ||
models.Query.data_source.null = True | ||
models.QueryResult.data_source.null = True | ||
try: | ||
with db.database.transaction(): | ||
migrator.add_column(models.Query, models.Query.data_source, "data_source_id") | ||
except peewee.ProgrammingError: | ||
print "Failed to create data_source_id column -- assuming it already exists" | ||
|
||
try: | ||
with db.database.transaction(): | ||
migrator.add_column(models.QueryResult, models.QueryResult.data_source, "data_source_id") | ||
except peewee.ProgrammingError: | ||
print "Failed to create data_source_id column -- assuming it already exists" | ||
|
||
print "Updating data source to existing one..." | ||
models.Query.update(data_source=default_data_source.id).execute() | ||
models.QueryResult.update(data_source=default_data_source.id).execute() | ||
|
||
with db.database.transaction(): | ||
print "Setting data source to non nullable..." | ||
migrator.set_nullable(models.Query, models.Query.data_source, False) | ||
|
||
with db.database.transaction(): | ||
print "Setting data source to non nullable..." | ||
migrator.set_nullable(models.QueryResult, models.QueryResult.data_source, False) | ||
|
||
db.close_db(None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from playhouse.migrate import Migrator | ||
from redash import db | ||
from redash import models | ||
|
||
|
||
if __name__ == '__main__': | ||
db.connect_db() | ||
migrator = Migrator(db.database) | ||
|
||
if not models.Group.table_exists(): | ||
print "Creating groups table..." | ||
models.Group.create_table() | ||
|
||
with db.database.transaction(): | ||
models.Group.insert(name='admin', permissions=['admin'], tables=['*']).execute() | ||
models.Group.insert(name='default', permissions=models.Group.DEFAULT_PERMISSIONS, tables=['*']).execute() | ||
|
||
migrator.drop_column(models.User, 'permissions') | ||
migrator.add_column(models.User, models.User.groups, 'groups') | ||
|
||
models.User.update(groups=['admin', 'default']).where(models.User.is_admin == True).execute() | ||
models.User.update(groups=['default']).where(models.User.is_admin == False).execute() | ||
|
||
db.close_db(None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.