Skip to content

Commit

Permalink
Merge pull request #87 from qld-gov-au/develop
Browse files Browse the repository at this point in the history
QOLDEV-327 move database setup to command line
  • Loading branch information
ThrawnCA committed May 15, 2023
2 parents 0d19c23 + ea18dbf commit cb4e89e
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 599 deletions.
4 changes: 4 additions & 0 deletions .docker/scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ CLICK_ARGS="--yes" ckan_cli db clean
ckan_cli db init
ckan_cli db upgrade

# Add data request tables
ckan_cli datarequests init-db
ckan_cli datarequests update-db

# Create some base test data
. $APP_DIR/scripts/create-test-data.sh
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
matrix:
ckan-version: ["2.10", 2.9, 2.9-py2]

name: Continuous Integration build on CKAN ${{ matrix.ckan-version }}
name: Test on CKAN ${{ matrix.ckan-version }}
runs-on: ubuntu-latest
container: drevops/ci-builder
env:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ ckan.datarequests.show_datarequests_badge = [true|false]
```
ckan.datarequests.description_required = [True|False]
```
* Update the database schema
```
ckan -c <config> datarequests init_db
ckan -c <config> datarequests update_db
```
* Restart your apache2 reserver
```
sudo service apache2 restart
Expand Down
52 changes: 0 additions & 52 deletions ckanext/datarequests/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,8 @@ def create_datarequest(context, data_dict):
:rtype: dict
'''

model = context['model']
session = context['session']

# Init the data base
db.init_db(model)

# Check access
tk.check_access(constants.CREATE_DATAREQUEST, context, data_dict)

Expand Down Expand Up @@ -255,15 +251,11 @@ def show_datarequest(context, data_dict):
:rtype: dict
'''

model = context['model']
datarequest_id = data_dict.get('id', '')

if not datarequest_id:
raise tk.ValidationError(tk._('Data Request ID has not been included'))

# Init the data base
db.init_db(model)

# Check access
tk.check_access(constants.SHOW_DATAREQUEST, context, data_dict)

Expand Down Expand Up @@ -307,16 +299,12 @@ def update_datarequest(context, data_dict):
:rtype: dict
'''

model = context['model']
session = context['session']
datarequest_id = data_dict.get('id', '')

if not datarequest_id:
raise tk.ValidationError(tk._('Data Request ID has not been included'))

# Init the data base
db.init_db(model)

# Check access
tk.check_access(constants.UPDATE_DATAREQUEST, context, data_dict)

Expand Down Expand Up @@ -384,13 +372,9 @@ def list_datarequests(context, data_dict):
:rtype: dict
'''

model = context['model']
organization_show = tk.get_action('organization_show')
user_show = tk.get_action('user_show')

# Init the data base
db.init_db(model)

# Check access
tk.check_access(constants.LIST_DATAREQUESTS, context, data_dict)

Expand Down Expand Up @@ -498,17 +482,13 @@ def delete_datarequest(context, data_dict):
:rtype: dict
'''

model = context['model']
session = context['session']
datarequest_id = data_dict.get('id', '')

# Check id
if not datarequest_id:
raise tk.ValidationError(tk._('Data Request ID has not been included'))

# Init the data base
db.init_db(model)

# Check access
tk.check_access(constants.DELETE_DATAREQUEST, context, data_dict)

Expand Down Expand Up @@ -544,17 +524,13 @@ def close_datarequest(context, data_dict):
'''

model = context['model']
session = context['session']
datarequest_id = data_dict.get('id', '')

# Check id
if not datarequest_id:
raise tk.ValidationError(tk._('Data Request ID has not been included'))

# Init the data base
db.init_db(model)

# Check access
tk.check_access(constants.CLOSE_DATAREQUEST, context, data_dict)

Expand Down Expand Up @@ -607,17 +583,13 @@ def comment_datarequest(context, data_dict):
'''

model = context['model']
session = context['session']
datarequest_id = data_dict.get('datarequest_id', '')

# Check id
if not datarequest_id:
raise tk.ValidationError([tk._('Data Request ID has not been included')])

# Init the data base
db.init_db(model)

# Check access
tk.check_access(constants.COMMENT_DATAREQUEST, context, data_dict)

Expand Down Expand Up @@ -654,16 +626,12 @@ def show_datarequest_comment(context, data_dict):
:rtype: dict
'''

model = context['model']
comment_id = data_dict.get('id', '')

# Check id
if not comment_id:
raise tk.ValidationError([tk._('Comment ID has not been included')])

# Init the data base
db.init_db(model)

# Check access
tk.check_access(constants.SHOW_DATAREQUEST_COMMENT, context, data_dict)

Expand Down Expand Up @@ -700,16 +668,12 @@ def list_datarequest_comments(context, data_dict):
:rtype: list
'''

model = context['model']
datarequest_id = data_dict.get('datarequest_id', '')

# Check id
if not datarequest_id:
raise tk.ValidationError(tk._('Data Request ID has not been included'))

# Init the data base
db.init_db(model)

# Sort. By default, comments are returned in the order they are created
# This is something new in version 0.3.0. In previous versions, comments
# were returned in inverse order
Expand Down Expand Up @@ -747,16 +711,12 @@ def update_datarequest_comment(context, data_dict):
:rtype: dict
'''

model = context['model']
session = context['session']
comment_id = data_dict.get('id', '')

if not comment_id:
raise tk.ValidationError([tk._('Comment ID has not been included')])

# Init the data base
db.init_db(model)

# Check access
tk.check_access(constants.UPDATE_DATAREQUEST_COMMENT, context, data_dict)

Expand Down Expand Up @@ -793,16 +753,12 @@ def delete_datarequest_comment(context, data_dict):
:rtype: dict
'''

model = context['model']
session = context['session']
comment_id = data_dict.get('id', '')

if not comment_id:
raise tk.ValidationError([tk._('Comment ID has not been included')])

# Init the data base
db.init_db(model)

# Check access
tk.check_access(constants.DELETE_DATAREQUEST_COMMENT, context, data_dict)

Expand Down Expand Up @@ -835,16 +791,12 @@ def follow_datarequest(context, data_dict):
:rtype: bool
'''

model = context['model']
session = context['session']
datarequest_id = data_dict.get('id', '')

if not datarequest_id:
raise tk.ValidationError([tk._('Data Request ID has not been included')])

# Init the data base
db.init_db(model)

# Check access
tk.check_access(constants.FOLLOW_DATAREQUEST, context, data_dict)

Expand Down Expand Up @@ -887,16 +839,12 @@ def unfollow_datarequest(context, data_dict):
:rtype: bool
'''

model = context['model']
session = context['session']
datarequest_id = data_dict.get('id', '')

if not datarequest_id:
raise tk.ValidationError([tk._('Data Request ID has not been included')])

# Init the data base
db.init_db(model)

# Check access
tk.check_access(constants.UNFOLLOW_DATAREQUEST, context, data_dict)

Expand Down
33 changes: 33 additions & 0 deletions ckanext/datarequests/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# encoding: utf-8

import click

from . import db

# Click commands for CKAN 2.9 and above


@click.group()
def datarequests():
""" Data Request commands
"""
pass


@datarequests.command()
def init_db():
""" Create tables to store data requests.
"""
db.init_db()


@datarequests.command()
def update_db():
""" Make any database updates that may have been defined
after tables were created.
"""
db.update_db()


def get_commands():
return [datarequests]
2 changes: 1 addition & 1 deletion ckanext/datarequests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with CKAN Data Requests Extension. If not, see <http://www.gnu.org/licenses/>.

from ckan.common import config
import ckan.lib.helpers as h
from ckan.plugins.toolkit import config


def get_config_bool_value(config_name, default_value=False):
Expand Down
Loading

0 comments on commit cb4e89e

Please sign in to comment.