Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ug remove future imports from explorer #620

Open
wants to merge 187 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
187 commits
Select commit Hold shift + click to select a range
1798f4c
[CU - #1ykyu7k] feat: add new model for Query Change Log
ShravanCool Mar 25, 2022
177cb92
[CU - #1ykyu7k] feat: added new view for query change logs
ShravanCool Mar 25, 2022
d4ffe88
[CU - #1ykyu7k] feat: added links for query change log template view
ShravanCool Mar 25, 2022
af283c5
[CU - #1ykyu7k] feat: added new tests for query change log view
ShravanCool Mar 25, 2022
8ab406d
[CU - #1ykyu7k] feat: added migrations for query change log model
ShravanCool Mar 25, 2022
8fc95b3
[CU - #1ykyu7k] refactor: code clean-up
ShravanCool Mar 25, 2022
2042cba
[CU - #1ykyu7k] [CU - #1ykyu7k] feat: added test settings file
ShravanCool Mar 25, 2022
e7ccbf6
[CU - #1ykyu7k] refactor: code clean-up
ShravanCool Mar 25, 2022
f4011ef
Merge pull request #1 from squadrun/shravan/#1ykyu7k_explorer_queries…
ShravanCool Mar 28, 2022
bda1251
[CU - ] feat: added new functions for checking replication lag
ShravanCool Apr 21, 2022
5a72a69
[CU - ] refactor: modified views and templates to include replication…
ShravanCool Apr 21, 2022
6b2eebe
[CU - ] refactor: code clean-up
ShravanCool Apr 21, 2022
ff6bec6
[CU - ] refactor: code clean-up
ShravanCool Apr 21, 2022
08c8189
[CU - ] feat: use 'ago' package to humanize timedelta
ShravanCool Apr 24, 2022
5d583ff
[CU - ] feat: added package 'ago' to requirements and set-up files
ShravanCool Apr 24, 2022
d11aa77
[CU - ] refactor: change threshold value as a constant
ShravanCool Apr 25, 2022
208ee6e
[CU - ] refactor: update warning message for replication lag
ShravanCool Apr 25, 2022
9d316ad
Merge pull request #2 from squadrun/shravan/show_replication_lag_expl…
ShravanCool Apr 25, 2022
46d1314
fixes py2/3 incompatibility of Query model
May 4, 2022
34ea7d6
Merge pull request #3 from squadrun/ks_py2_3_incompatibility_fix
May 4, 2022
dbd8e61
fixes deps not getting installed on package user's repo
May 4, 2022
00c87b1
Merge pull request #4 from squadrun/ks_py2_3_incompatibility_fix
May 4, 2022
0097a86
integrate clarity for explorer
May 27, 2022
9309fd5
[CU - #2a2abq2] clean up
May 27, 2022
62015a2
Merge pull request #5 from squadrun/srujana/#2a2abq2_integrate_clarity
srujanamanvi May 27, 2022
91533b1
[CU - #2a2abq2] add custom filters
May 30, 2022
efa912c
[CU - #2a2abq2] refactor
May 30, 2022
137d1e6
Merge pull request #6 from squadrun/srujana/#2a2abq2_integrate_clarity
srujanamanvi May 31, 2022
76cb1ee
[CU - #2a2abq2] remove duplicate block names
May 31, 2022
cd586af
Merge pull request #7 from squadrun/srujana/#2a2abq2_integrate_clarity
srujanamanvi May 31, 2022
123f1db
[CU - #2a2abq2] get user from request
May 31, 2022
b684780
Merge pull request #8 from squadrun/srujana/#2a2abq2_integrate_clarity
srujanamanvi May 31, 2022
eddcc24
[CU - #2a2abq2] get full name instead of short name
May 31, 2022
dc68915
Merge pull request #9 from squadrun/srujana/#2a2abq2_integrate_clarity
srujanamanvi May 31, 2022
7fa74e7
[CU - #2a2abq2] refactor
May 31, 2022
90d7393
Merge pull request #10 from squadrun/srujana/#2a2abq2_integrate_clarity
srujanamanvi May 31, 2022
41a264e
[CU - #2a2abq2] add username filter
Jun 1, 2022
61e2020
Merge pull request #11 from squadrun/srujana/#2a2abq2_integrate_clarity
srujanamanvi Jun 1, 2022
53ec2cd
[CU - ] refactor: change ago dependency to 0.0.93 exact match
ShravanCool Jul 7, 2022
0713ca9
Merge pull request #12 from squadrun/Shravan/fix_ago_dependency_issue
ShravanCool Jul 7, 2022
d2019e8
added new migration 0006 snapshot
Feb 7, 2023
6f0e7ef
Merge pull request #14 from squadrun/vg_migration_fix
vineetgupta0 Feb 7, 2023
778ba82
add info alert for revoking column access
Ujjwal-Squadstack Mar 15, 2023
378a339
add info alert for revoking column access
Ujjwal-Squadstack Mar 16, 2023
37f520e
Merge pull request #15 from squadrun/ug_add_info_alert_for_column_rem…
ayush--s Mar 16, 2023
ed51232
Merge branch 'master' of github.com:squadrun/django-sql-explorer into…
Ujjwal-Squadstack Mar 16, 2023
2a19ee3
add warning alert
Ujjwal-Squadstack Mar 16, 2023
764a198
Merge pull request #16 from squadrun/ug_add_info_alert_for_column_rem…
Ujjwal-Squadstack Mar 16, 2023
b086fcb
add paragraph
Ujjwal-Squadstack Mar 16, 2023
e1ea7d4
Merge pull request #17 from squadrun/ug_add_info_alert_for_column_rem…
Ujjwal-Squadstack Mar 16, 2023
54d476b
new connection added
HemendraSharma04 Apr 5, 2023
f88756e
debug
HemendraSharma04 Apr 5, 2023
dea5296
debug
HemendraSharma04 Apr 5, 2023
0130f5e
debug
HemendraSharma04 Apr 5, 2023
4beb391
debug
HemendraSharma04 Apr 6, 2023
b6b7d94
debug
HemendraSharma04 Apr 6, 2023
c44c4fc
debug
HemendraSharma04 Apr 6, 2023
cbbd881
bug fixed
HemendraSharma04 Apr 7, 2023
ecb62a6
debug
HemendraSharma04 Apr 7, 2023
4e04375
debug
HemendraSharma04 Apr 7, 2023
ba05ba5
debug
HemendraSharma04 Apr 7, 2023
0ec574d
debug
HemendraSharma04 Apr 7, 2023
f64fc78
debug again
HemendraSharma04 Apr 7, 2023
34f84ba
debug
HemendraSharma04 Apr 10, 2023
715270f
debug
HemendraSharma04 Apr 10, 2023
16f879d
test
HemendraSharma04 Apr 10, 2023
8aff032
test
HemendraSharma04 Apr 10, 2023
6f2645e
testing
HemendraSharma04 Apr 10, 2023
fa02c3a
code refactored
HemendraSharma04 Apr 11, 2023
8364d64
final
HemendraSharma04 Apr 11, 2023
7795949
final modifications
HemendraSharma04 Apr 12, 2023
85b50a3
modified code
HemendraSharma04 Apr 12, 2023
50511d2
minor bug fix
HemendraSharma04 Apr 12, 2023
989b90d
minor bug fix
HemendraSharma04 Apr 12, 2023
42dcdfa
Merge pull request #18 from HemendraSharma04/master
Ujjwal-Squadstack Apr 12, 2023
919d449
debug
HemendraSharma04 Apr 18, 2023
8bfbc3c
debug
HemendraSharma04 Apr 19, 2023
3171be7
debug
HemendraSharma04 Apr 19, 2023
a4d606f
debug
HemendraSharma04 Apr 19, 2023
b8c76d6
debug
HemendraSharma04 Apr 19, 2023
67570a8
test
HemendraSharma04 Apr 19, 2023
4707e55
revert template code
HemendraSharma04 Apr 19, 2023
3cc5e4e
template change
HemendraSharma04 Apr 19, 2023
839550b
view changes revert
HemendraSharma04 Apr 19, 2023
c0cceda
view changes revert
HemendraSharma04 Apr 19, 2023
04c40d5
view changes revert
HemendraSharma04 Apr 19, 2023
9f891f9
debug
HemendraSharma04 Apr 19, 2023
dd67de4
debug
HemendraSharma04 Apr 19, 2023
fbf7851
debug
HemendraSharma04 Apr 19, 2023
b1aa5b3
code refactored
HemendraSharma04 Apr 19, 2023
12f2fe0
debug exception
HemendraSharma04 Apr 19, 2023
404c18f
debug exception
HemendraSharma04 Apr 19, 2023
bc3eb7d
debug error
HemendraSharma04 Apr 19, 2023
f3d7c7c
debug error test
HemendraSharma04 Apr 19, 2023
cea79d8
final changes
HemendraSharma04 Apr 19, 2023
be0d644
final testing
HemendraSharma04 Apr 19, 2023
a164b36
final testing
HemendraSharma04 Apr 19, 2023
e59c6b7
final testing
HemendraSharma04 Apr 19, 2023
85764ca
final testing
HemendraSharma04 Apr 19, 2023
e908d3c
final testing exception handling
HemendraSharma04 Apr 19, 2023
80120de
final test
HemendraSharma04 Apr 19, 2023
da1ab6e
final test debug
HemendraSharma04 Apr 19, 2023
7f58938
message test
HemendraSharma04 Apr 20, 2023
7a21e12
message test
HemendraSharma04 Apr 20, 2023
4de7f0d
testing done
HemendraSharma04 Apr 20, 2023
ba13778
final cleanup
HemendraSharma04 Apr 20, 2023
326bfed
playground bug fix
HemendraSharma04 Apr 20, 2023
075b1be
Merge pull request #20 from HemendraSharma04/master
HemendraSharma04 May 11, 2023
a5cebaf
[CU - ] feat: added util functions to route requests to async_api db
ShravanCool Jun 7, 2023
aa3550f
[CU - ] feat: query requestlog tables in asyncapi db
ShravanCool Jun 7, 2023
17b8a09
[CU - ] feat: add cutoff_date for requestlog queries
ShravanCool Jul 4, 2023
b00f5d4
[CU - ] test: added tests for method adding cutoff-date for requestlog
ShravanCool Jul 5, 2023
8920e45
Merge pull request #21 from squadrun/shravan/cus-1216_add_requestlog_…
shailykhamesra Jul 5, 2023
d93dc06
[CU - ] feat: add where clause before group, order or limit clauses
ShravanCool Jul 5, 2023
5cbd54d
[CU - ] refactor: convert iterator to list
ShravanCool Jul 5, 2023
911be1e
[CU - ] refactor: use a common method to add query clauses
ShravanCool Jul 5, 2023
f441c6c
Merge pull request #22 from squadrun/shravan/cus-1216_add_requestlog_…
shailykhamesra Jul 5, 2023
3891d28
Merge branch 'master' of github.com:squadrun/django-sql-explorer
Ujjwal-Squadstack Jul 5, 2023
9c8676d
minor bug fix
HemendraSharma04 Jul 6, 2023
6d9a2d9
Merge branch 'squadrun:master' into hs_minor_bug_fix
HemendraSharma04 Jul 6, 2023
0b70c79
Merge pull request #23 from HemendraSharma04/hs_minor_bug_fix
HemendraSharma04 Jul 6, 2023
b5283a2
Merge branch 'master' of github.com:squadrun/django-sql-explorer
Ujjwal-Squadstack Jul 7, 2023
ae1f02f
[CU - ] fix: specify tablename in filter
ShravanCool Jul 7, 2023
d6a2a89
[CU - ] test: fix tests
ShravanCool Jul 7, 2023
b1e8217
Merge pull request #24 from squadrun/shravan/cus-1216_add_requestlog_…
shailykhamesra Jul 7, 2023
72c1c32
:sparkles: PII masking (email and phone number) | JSON and TEXT fields
mayank-jain-1010 Jul 10, 2023
596e958
:sparkles: Added check to run on non-pii types
mayank-jain-1010 Jul 11, 2023
b5ac4d3
:hammer: Test case check
mayank-jain-1010 Jul 11, 2023
900e940
:hammer: Resolved comments
mayank-jain-1010 Jul 12, 2023
3c773b5
:hammer: Comments resolved
mayank-jain-1010 Jul 12, 2023
f79ff04
:hammer: Fixed test
mayank-jain-1010 Jul 12, 2023
50247f7
:wrench: Reverted settings
mayank-jain-1010 Jul 12, 2023
1731ce4
:wrench: Comments addressed
mayank-jain-1010 Jul 12, 2023
e314dd7
Merge pull request #25 from squadrun/Mayank/#CU-85zte7gkb/mask-pii-fr…
mayank-jain-1010 Jul 13, 2023
d9bcc11
[CU - ] feat: remove the cutoff date filter
ShravanCool Jul 19, 2023
88b6f12
[CU - ] feat: added note regarding table info
ShravanCool Jul 19, 2023
24886f0
Merge pull request #26 from squadrun/shravan/cus-1592_remove_cutoff_d…
shailykhamesra Jul 19, 2023
62ddd47
player phone number masking implementation
ManikGarg008 Jul 24, 2023
fd76f70
added a null check
ManikGarg008 Jul 24, 2023
b6370f6
removed unwanted constant
ManikGarg008 Jul 24, 2023
e50c5e6
replaced a constant
ManikGarg008 Jul 24, 2023
3f2c7e0
Merge pull request #27 from squadrun/manik_#85ztjn6rh_mask_phone_number
ManikGarg008 Jul 25, 2023
a5eece9
added table level and runtime checks for masking pii
ManikGarg008 Jul 25, 2023
8ade8a1
Merge pull request #28 from squadrun/manik_#85ztjn6rh_mask_phone_number
ManikGarg008 Jul 25, 2023
276a0ba
Improved masking for Player PII
ManikGarg008 Aug 1, 2023
1a39109
Minor regexe pattern change for masking pii in username
ManikGarg008 Aug 1, 2023
285d880
Merge pull request #29 from squadrun/manik_#85ztn4m9d_improve_masking…
ManikGarg008 Aug 1, 2023
9c6ef43
fixed PII invisibility in download csv requests
ManikGarg008 Aug 9, 2023
e4fecf1
Merge pull request #30 from squadrun/manik_#85ztn4m9d_improve_masking…
ManikGarg008 Aug 9, 2023
0ed5163
Fixed Format Button
modo27 Oct 6, 2023
3b702fa
Merge pull request #31 from squadrun/md/#format_fix
modo27 Oct 6, 2023
b4907b2
fixing format
Vaibhav-Lodha Nov 1, 2023
34a935f
Merge pull request #32 from squadrun/fixing_format
Vaibhav-Lodha Nov 1, 2023
115bda8
added query execute for master db read only
raybittuiq Jan 5, 2024
d2548b2
Merge pull request #33 from squadrun/bittu-add-support-to-execute-on-…
raybittuiq Jan 16, 2024
ca98547
Merge branch 'master' of github.com:squadrun/django-sql-explorer
Ujjwal-Squadstack Feb 15, 2024
196e319
csrf_exempt
Ujjwal-Squadstack Feb 15, 2024
39a3216
Merge pull request #34 from squadrun/ug_csrf_exempt_for_django_1.10
Ujjwal-Squadstack Feb 15, 2024
f27f9cc
fix download_csv csrf
Ujjwal-Squadstack Feb 19, 2024
cd254fb
fix download_csv csrf
Ujjwal-Squadstack Feb 19, 2024
dc5ac56
Merge pull request #35 from squadrun/ug_csrf_exempt_for_django_1.10
ayushsquad Feb 19, 2024
99cef98
Update views.py
HemendraSharma04 Feb 22, 2024
4089471
Update views.py
HemendraSharma04 Feb 22, 2024
38363b9
Update views.py
HemendraSharma04 Feb 22, 2024
c598a71
update for django 1.11
HemendraSharma04 Mar 1, 2024
0d09987
update for django 1.11
HemendraSharma04 Mar 1, 2024
8909d3c
update for django 1.11
HemendraSharma04 Mar 1, 2024
a424bfe
Merge pull request #36 from HemendraSharma04/master
HemendraSharma04 Mar 4, 2024
5e01ef1
fix context issue by flattening the context
HemendraSharma04 Mar 5, 2024
47f3781
Merge pull request #38 from squadrun/hs_fix_context_rendering_issue
HemendraSharma04 Mar 5, 2024
9fc7f86
fix version
HemendraSharma04 Mar 5, 2024
28da008
Merge pull request #39 from squadrun/hs_fix_version
HemendraSharma04 Mar 5, 2024
9b1aef2
make temp request log tables visible on explorer
ananay-squad10 Mar 29, 2024
ddbcdc5
changed to note to include pii_masked_request_headers
ananay-squad10 Mar 29, 2024
a1ba38a
Merge pull request #40 from squadrun/Ananay_temp_request_log_tables
ananay-squad10 Mar 29, 2024
3007ef8
change reverse import from django.conf.urlresolvers to django.urls
HemendraSharma04 Apr 29, 2024
169cd21
fix
HemendraSharma04 Apr 29, 2024
7a1dbeb
fix
HemendraSharma04 Apr 29, 2024
e248f15
fix on_delete
HemendraSharma04 Apr 30, 2024
4264369
fix
HemendraSharma04 Apr 30, 2024
780cdc4
fix
HemendraSharma04 Apr 30, 2024
a03c9e5
debug
HemendraSharma04 Apr 30, 2024
62787d1
debug
HemendraSharma04 Apr 30, 2024
60a6e90
rel renamed to remote_field
HemendraSharma04 Apr 30, 2024
cecfcf2
debug
HemendraSharma04 Apr 30, 2024
45cbfac
Merge pull request #41 from squadrun/hs_fix_reverse_import
HemendraSharma04 Apr 30, 2024
8fd4e26
remove future dependencies
Ujjwal-Squadstack May 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
/dist
*.egg-info
.DS_Store
tmp
/build
*#
*~
.coverage
/htmlcov/
*.orig
*.orig
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Use an official Python runtime as a parent image
FROM python:3.5-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file into the container at /app
COPY requirements.txt /app/
COPY optional-requirements.txt /app/

# Install any needed packages specified in requirements.txt
RUN pip install Django==1.11.17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐

RUN pip install -r requirements.txt
RUN pip install -r optional-requirements.txt

# Copy the entire Django project directory into the container at /app
COPY . /app/
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3'
services:
db:
image: postgres:13
environment:
POSTGRES_DB: mydb
POSTGRES_USER: myuser
POSTGRES_PASSWORD: mypassword

web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/app
ports:
- "8000:8000"
depends_on:
- db
environment:
DEBUG: "True" # Set to "False" in production
DJANGO_DB_HOST: db
DJANGO_DB_PORT: 5432
DJANGO_DB_NAME: mydb
DJANGO_DB_USER: myuser
DJANGO_DB_PASSWORD: mypassword
links:
- db
2 changes: 1 addition & 1 deletion explorer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__version_info__ = {
'major': 0,
'minor': 9,
'micro': 2,
'micro': 23,
'releaselevel': 'final',
'serial': 0
}
Expand Down
4 changes: 3 additions & 1 deletion explorer/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

from django.contrib import admin
from explorer.models import Query
from explorer.actions import generate_report_action
Expand All @@ -7,7 +8,8 @@ class QueryAdmin(admin.ModelAdmin):
list_display = ('title', 'description', 'created_by_user',)
list_filter = ('title',)
raw_id_fields = ('created_by_user',)

actions = [generate_report_action()]


admin.site.register(Query, QueryAdmin)
39 changes: 30 additions & 9 deletions explorer/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,49 @@

# Required
EXPLORER_CONNECTION_NAME = getattr(settings, 'EXPLORER_CONNECTION_NAME', None)
EXPLORER_CONNECTION_PII_NAME = getattr(
settings, 'EXPLORER_CONNECTION_PII_NAME', None)
EXPLORER_CONNECTION_ASYNC_API_DB_NAME = getattr(
settings, 'EXPLORER_CONNECTION_ASYNC_API_DB_NAME', None)
EXPLORER_MASTER_DB_CONNECTION_NAME = getattr(settings, 'EXPLORER_MASTER_DB_CONNECTION', None)

# Change the behavior of explorer
EXPLORER_SQL_BLACKLIST = getattr(settings, 'EXPLORER_SQL_BLACKLIST', ('ALTER', 'RENAME ', 'DROP', 'TRUNCATE', 'INSERT INTO', 'UPDATE', 'REPLACE', 'DELETE', 'CREATE TABLE', 'SCHEMA', 'GRANT', 'OWNER TO'))
EXPLORER_SQL_WHITELIST = getattr(settings, 'EXPLORER_SQL_WHITELIST', ('CREATED', 'DELETED', 'REGEXP_REPLACE'))
EXPLORER_SQL_BLACKLIST = getattr(settings, 'EXPLORER_SQL_BLACKLIST', ('ALTER', 'RENAME ', 'DROP', 'TRUNCATE',
'INSERT INTO', 'UPDATE', 'REPLACE', 'DELETE', 'CREATE TABLE', 'SCHEMA', 'GRANT', 'OWNER TO'))
EXPLORER_SQL_WHITELIST = getattr(
settings, 'EXPLORER_SQL_WHITELIST', ('CREATED', 'DELETED', 'REGEXP_REPLACE'))
TABLE_NAMES_FOR_PII_MASKING = getattr(
settings, 'TABLE_NAMES_FOR_PII_MASKING', None)
EXPLORER_DEFAULT_ROWS = getattr(settings, 'EXPLORER_DEFAULT_ROWS', 1000)
EXPLORER_SCHEMA_EXCLUDE_APPS = getattr(settings, 'EXPLORER_SCHEMA_EXCLUDE_APPS', ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.admin'))
EXPLORER_SCHEMA_EXCLUDE_APPS = getattr(settings, 'EXPLORER_SCHEMA_EXCLUDE_APPS', (
'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.admin'))
EXPLORER_TRANSFORMS = getattr(settings, 'EXPLORER_TRANSFORMS', [])
EXPLORER_PERMISSION_VIEW = getattr(settings, 'EXPLORER_PERMISSION_VIEW', lambda u: u.is_staff)
EXPLORER_PERMISSION_CHANGE = getattr(settings, 'EXPLORER_PERMISSION_CHANGE', lambda u: u.is_staff)
EXPLORER_RECENT_QUERY_COUNT = getattr(settings, 'EXPLORER_RECENT_QUERY_COUNT', 10)
EXPLORER_PERMISSION_VIEW = getattr(
settings, 'EXPLORER_PERMISSION_VIEW', lambda u: u.is_staff)
EXPLORER_PERMISSION_CHANGE = getattr(
settings, 'EXPLORER_PERMISSION_CHANGE', lambda u: u.is_staff)
EXPLORER_RECENT_QUERY_COUNT = getattr(
settings, 'EXPLORER_RECENT_QUERY_COUNT', 10)
CSV_DELIMETER = getattr(settings, "EXPLORER_CSV_DELIMETER", ",")

# API access
EXPLORER_TOKEN = getattr(settings, 'EXPLORER_TOKEN', 'CHANGEME')
# These are callable to aid testability by dodging the settings cache.
# There is surely a better pattern for this, but this'll hold for now.
EXPLORER_GET_USER_QUERY_VIEWS = lambda: getattr(settings, 'EXPLORER_USER_QUERY_VIEWS', {})
EXPLORER_TOKEN_AUTH_ENABLED = lambda: getattr(settings, 'EXPLORER_TOKEN_AUTH_ENABLED', False)


def EXPLORER_GET_USER_QUERY_VIEWS(): return getattr(
settings, 'EXPLORER_USER_QUERY_VIEWS', {})


def EXPLORER_TOKEN_AUTH_ENABLED(): return getattr(
settings, 'EXPLORER_TOKEN_AUTH_ENABLED', False)


# Async task related. Note that the EMAIL_HOST settings must be set up for email to work.
ENABLE_TASKS = getattr(settings, "EXPLORER_TASKS_ENABLED", False)
S3_ACCESS_KEY = getattr(settings, "EXPLORER_S3_ACCESS_KEY", None)
S3_SECRET_KEY = getattr(settings, "EXPLORER_S3_SECRET_KEY", None)
S3_BUCKET = getattr(settings, "EXPLORER_S3_BUCKET", None)
FROM_EMAIL = getattr(settings, 'EXPLORER_FROM_EMAIL', '[email protected]')
FROM_EMAIL = getattr(settings, 'EXPLORER_FROM_EMAIL',
'[email protected]')
15 changes: 15 additions & 0 deletions explorer/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PII_MASKING_PATTERN_REPLACEMENT_DICT = {
r"(?:\+?\d{1,3}|0)?([6-9]\d{9})\b": "XXXXXXXXXXX", # For phone number
r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b": "[email protected]", # For email
}

TYPE_CODE_FOR_JSON = 3802
TYPE_CODE_FOR_TEXT = 25
TYPE_CODE_FOR_CHAR = 1043

PLAYER_PHONE_NUMBER_MASKING_TYPE_CODES = [TYPE_CODE_FOR_CHAR]

ALLOW_PHONE_NUMBER_MASKING_GROUP_ID = 10439

PATTERN_FOR_FINDING_PHONE_NUMBER = r"\+?\d{0,3}?([6-9]\d{9})(?:_\w+)?\b"
PATTERN_FOR_FINDING_EMAIL = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b"
21 changes: 16 additions & 5 deletions explorer/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
from django.forms.widgets import CheckboxInput
from explorer.models import Query, MSG_FAILED_BLACKLIST
from django.db import DatabaseError
import logging
import re
def _(x): return x

_ = lambda x: x

logger = logging.getLogger(__name__)


class SqlField(Field):
Expand All @@ -14,20 +18,27 @@ def validate(self, value):

:param value: The SQL for this Query model.
"""

super().validate(value)
query = Query(sql=value)

passes_blacklist, failing_words = query.passes_blacklist()

error = MSG_FAILED_BLACKLIST % ', '.join(failing_words) if not passes_blacklist else None
error = MSG_FAILED_BLACKLIST % ', '.join(
failing_words) if not passes_blacklist else None

if not error and not query.available_params():
try:
query.execute_query_only()
except DatabaseError as e:
error = str(e)

logger.info("error executing query: %s", e)
if (re.search("permission denied for table", str(e))):
error = None
else:
error = e

if error:

raise ValidationError(
_(error),
code="InvalidSql"
Expand All @@ -54,4 +65,4 @@ def created_by_user_id(self):

class Meta:
model = Query
fields = ['title', 'sql', 'description', 'created_by_user', 'snapshot']
fields = ['title', 'sql', 'description', 'created_by_user', 'snapshot']
77 changes: 58 additions & 19 deletions explorer/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion
Expand All @@ -14,34 +13,74 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name='Query',
name="Query",
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=255)),
('sql', models.TextField()),
('description', models.TextField(null=True, blank=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('last_run_date', models.DateTimeField(auto_now=True)),
('created_by_user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True)),
(
"id",
models.AutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
primary_key=True,
),
),
("title", models.CharField(max_length=255)),
("sql", models.TextField()),
("description", models.TextField(null=True, blank=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
("last_run_date", models.DateTimeField(auto_now=True)),
(
"created_by_user",
models.ForeignKey(
blank=True,
to=settings.AUTH_USER_MODEL,
null=True,
on_delete=django.db.models.deletion.CASCADE,
),
),
],
options={
'ordering': ['title'],
'verbose_name_plural': 'Queries',
"ordering": ["title"],
"verbose_name_plural": "Queries",
},
bases=(models.Model,),
),
migrations.CreateModel(
name='QueryLog',
name="QueryLog",
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('sql', models.TextField()),
('is_playground', models.BooleanField(default=False)),
('run_at', models.DateTimeField(auto_now_add=True)),
('query', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, blank=True, to='explorer.Query', null=True)),
('run_by_user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True)),
(
"id",
models.AutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
primary_key=True,
),
),
("sql", models.TextField()),
("is_playground", models.BooleanField(default=False)),
("run_at", models.DateTimeField(auto_now_add=True)),
(
"query",
models.ForeignKey(
on_delete=django.db.models.deletion.SET_NULL,
blank=True,
to="explorer.Query",
null=True,
),
),
(
"run_by_user",
models.ForeignKey(
blank=True,
to=settings.AUTH_USER_MODEL,
null=True,
on_delete=django.db.models.deletion.CASCADE,
),
),
],
options={
'ordering': ['-run_at'],
"ordering": ["-run_at"],
},
bases=(models.Model,),
),
Expand Down
1 change: 0 additions & 1 deletion explorer/migrations/0002_auto_20150501_1515.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations

Expand Down
1 change: 0 additions & 1 deletion explorer/migrations/0003_query_snapshot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations

Expand Down
1 change: 0 additions & 1 deletion explorer/migrations/0004_querylog_duration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models

Expand Down
31 changes: 31 additions & 0 deletions explorer/migrations/0005_querychangelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2022-03-25 05:46

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('explorer', '0004_querylog_duration'),
]

operations = [
migrations.CreateModel(
name='QueryChangeLog',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('old_sql', models.TextField(blank=True, null=True)),
('new_sql', models.TextField(blank=True, null=True)),
('run_at', models.DateTimeField(auto_now_add=True)),
('query', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='explorer.Query')),
('run_by_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['-run_at'],
},
),
]
18 changes: 18 additions & 0 deletions explorer/migrations/0006_auto_20230207_0103.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('explorer', '0005_querychangelog'),
]

operations = [
migrations.AlterField(
model_name='query',
name='snapshot',
field=models.BooleanField(default=False, help_text='Include in snapshot task (if enabled)'),
),
]
Loading