diff --git a/README.md b/README.md index ff32298057..368f712adb 100644 --- a/README.md +++ b/README.md @@ -201,34 +201,6 @@ Clone the repo and set up the server according to the steps listed. Make sure yo pip3 install -r requirements/tests.txt ``` -#### Enable/Disable modules - -- Enable/Disable a specific module - -``` -python manage.py module --name module_name --switch on/off -``` - -**_Example :_** - -``` -python manage.py module --name ticket_include --switch on -python manage.py module -n ticket_include -s off -``` - -- Enable/Disable all modules - -``` -python manage.py module --name module_name --switch on/off -``` - -**_Example :_** - -``` -python manage.py module --name all --switch on -python manage.py module -n all -s off -``` - #### Running unit tests * If you have docker installed and want to run tests faster, run diff --git a/app/api/events.py b/app/api/events.py index 5a4fbaead4..31b3bd09c1 100644 --- a/app/api/events.py +++ b/app/api/events.py @@ -33,7 +33,6 @@ from app.models.faq_type import FaqType from app.models.feedback import Feedback from app.models.microlocation import Microlocation -from app.models.module import Module from app.models.order import Order from app.models.role import Role from app.models.role_invite import RoleInvite @@ -64,24 +63,9 @@ from app.models.users_events_role import UsersEventsRoles -def validate_event(user, modules, data): +def validate_event(user, data): if not user.can_create_event(): raise ForbiddenError({'source': ''}, "Please verify your Email") - elif not modules.ticket_include: - raise ForbiddenError({'source': ''}, "Ticketing is not enabled in the system") - if ( - data.get('can_pay_by_paypal', False) - or data.get('can_pay_by_cheque', False) - or data.get('can_pay_by_bank', False) - or data.get('can_pay_by_stripe', False) - ): - if not modules.payment_include: - raise ForbiddenError({'source': ''}, "Payment is not enabled in the system") - if data.get('is_donation_enabled', False) and not modules.donation_include: - raise ForbiddenError( - {'source': '/data/attributes/is-donation-enabled'}, - "Donation is not enabled in the system", - ) if data.get('state', None) == 'published' and not user.can_publish_event(): raise ForbiddenError({'source': ''}, "Only verified accounts can publish events") @@ -338,8 +322,7 @@ def before_post(self, args, kwargs, data=None): :return: """ user = User.query.filter_by(id=kwargs['user_id']).first() - modules = Module.query.first() - validate_event(user, modules, data) + validate_event(user, data) if data['state'] != 'draft': validate_date(None, data) @@ -690,8 +673,7 @@ def before_patch(self, args, kwargs, data=None): :return: """ user = User.query.filter_by(id=current_user.id).one() - modules = Module.query.first() - validate_event(user, modules, data) + validate_event(user, data) def before_update_object(self, event, data, view_kwargs): """ diff --git a/app/api/modules.py b/app/api/modules.py deleted file mode 100644 index 717a986498..0000000000 --- a/app/api/modules.py +++ /dev/null @@ -1,39 +0,0 @@ -from flask_rest_jsonapi import ResourceDetail - -from app.api.bootstrap import api -from app.api.schema.modules import ModuleSchema -from app.models import db -from app.models.module import Module - - -class ModuleDetail(ResourceDetail): - """ - module detail by id - """ - - def before_get(self, args, kwargs): - """ - before get method to get the resource id for fetching details - :param args: - :param kwargs: - :return: - """ - kwargs['id'] = 1 - - def before_patch(self, args, kwargs, data=None): - """ - before patch method to verify if admin enables the donations in system - :param args: - :param kwargs: - :param data: - :return: - """ - - decorators = (api.has_permission('is_admin', methods='PATCH', id='1'),) - methods = ['GET', 'PATCH'] - schema = ModuleSchema - data_layer = { - 'session': db.session, - 'model': Module, - 'methods': {'before_patch': before_patch}, - } diff --git a/app/api/routes.py b/app/api/routes.py index cc473675ab..748c5cef0e 100644 --- a/app/api/routes.py +++ b/app/api/routes.py @@ -120,7 +120,6 @@ MicrolocationRelationshipOptional, MicrolocationRelationshipRequired, ) -from app.api.modules import ModuleDetail from app.api.notifications import ( NotificationActionDetail, NotificationActionList, @@ -425,9 +424,6 @@ # settings api.route(SettingDetail, 'setting_detail', '/settings/', '/settings') -# modules -api.route(ModuleDetail, 'module_detail', '/modules/', '/modules') - # pages api.route(PageList, 'page_list', '/pages') api.route(PageDetail, 'page_detail', '/pages/') diff --git a/app/api/schema/modules.py b/app/api/schema/modules.py deleted file mode 100644 index cc920ee8a2..0000000000 --- a/app/api/schema/modules.py +++ /dev/null @@ -1,27 +0,0 @@ -from marshmallow_jsonapi import fields -from marshmallow_jsonapi.flask import Schema - -from app.api.helpers.utilities import dasherize -from utils.common import use_defaults - - -@use_defaults() -class ModuleSchema(Schema): - """ - Admin Api schema for modules Model - """ - - class Meta: - """ - Meta class for module Api Schema - """ - - type_ = 'module' - self_view = 'v1.module_detail' - self_view_kwargs = {'id': ''} - inflect = dasherize - - id = fields.Str(dump_only=True) - ticket_include = fields.Boolean(default=False) - payment_include = fields.Boolean(default=False) - donation_include = fields.Boolean(default=False) diff --git a/app/models/module.py b/app/models/module.py deleted file mode 100644 index a3f084593a..0000000000 --- a/app/models/module.py +++ /dev/null @@ -1,14 +0,0 @@ -from app.models import db - - -class Module(db.Model): - """File model class""" - - __tablename__ = 'modules' - id = db.Column(db.Integer, primary_key=True) - ticket_include = db.Column(db.Boolean, default=False) - payment_include = db.Column(db.Boolean, default=False) - donation_include = db.Column(db.Boolean, default=False) - - def __repr__(self): - return '' % self.id diff --git a/docs/api/api_blueprint_source.apib b/docs/api/api_blueprint_source.apib index e786287751..12374d39f4 100644 --- a/docs/api/api_blueprint_source.apib +++ b/docs/api/api_blueprint_source.apib @@ -91,8 +91,6 @@ The Open Event API Server - - diff --git a/docs/api/blueprint/modules.apib b/docs/api/blueprint/modules.apib deleted file mode 100644 index 6c9d9802f8..0000000000 --- a/docs/api/blueprint/modules.apib +++ /dev/null @@ -1,98 +0,0 @@ -# Group Modules - -| Parameter | Description | Type | Required | -|:----------|-------------|------|----------| -| `donation-include` | Enable/Disable donation module | Boolean | **no** | -| `payment-include` | Enable/Disable payment module | Boolean | **no** | -| `ticket-include` | Enable/Disable ticket module | Boolean | **no** | - -**ADMIN** - -Switch on and off the modules. Admin access required. - - -## Modules Details [/v1/modules{?page%5bsize%5d,page%5bnumber%5d,sort,filter}] -+ Parameters - + page%5bsize%5d (optional, integer, `10`) - Maximum number of resources in a single paginated response. - + page%5bnumber%5d (optional, integer, `2`) - Page number to fetched for the paginated response. - + sort (optional, string, `app-name`) - Sort the resources according to the given attribute in ascending order. Append '-' to sort in descending order. - + filter (optional, string, `[]`) - Filter according to the flask-rest-jsonapi filtering system. Please refer: http://flask-rest-jsonapi.readthedocs.io/en/latest/filtering.html for more. - -### Show Modules[GET] - -+ Request - - + Headers - - Accept: application/vnd.api+json - - Authorization: JWT - -+ Response 200 (application/vnd.api+json) - - { - "data": { - "attributes": { - "donation-include": false, - "ticket-include": true, - "payment-include": true - }, - "type": "module", - "id": "1", - "links": { - "self": "/v1/modules/1" - } - }, - "jsonapi": { - "version": "1.0" - }, - "links": { - "self": "/v1/modules/1" - } - } - - -### Update Modules [PATCH] - -+ Request (application/vnd.api+json) - - + Headers - - Authorization: JWT - - + Body - - { - "data": { - "attributes": { - "donation-include": "false", - "ticket-include": "true", - "payment-include": "true" - }, - "type": "module", - "id": "1" - } - } - -+ Response 200 (application/vnd.api+json) - - { - "data": { - "attributes": { - "donation-include": false, - "ticket-include": true, - "payment-include": true - }, - "type": "module", - "id": "1", - "links": { - "self": "/v1/modules/1" - } - }, - "jsonapi": { - "version": "1.0" - }, - "links": { - "self": "/v1/modules/1" - } - } diff --git a/manage.py b/manage.py index 2230c033fc..65756b329c 100644 --- a/manage.py +++ b/manage.py @@ -11,7 +11,6 @@ from app.api.helpers.tasks import resize_event_images_task, resize_speaker_images_task from app.models import db from app.models.event import Event, get_new_event_identifier -from app.models.module import Module from app.models.speaker import Speaker from populate_db import populate from tests.all.integration.auth_helper import create_super_admin @@ -85,26 +84,6 @@ def fix_digit_identifier(): db.session.commit() -@manager.option('-n', '--name', dest='name', default='all') -@manager.option('-s', '--switch', dest='switch', default='off') -def module(name, switch): - keys = [i.name for i in Module.__table__.columns][1:] - convey = {"on": True, "off": False} - if switch not in ['on', 'off']: - print("Choose either state On/Off") - - elif name == 'all': - for key in keys: - setattr(Module.query.first(), key, convey[switch]) - print("Module %s turned %s" % (key, switch)) - elif name in keys: - setattr(Module.query.first(), name, convey[switch]) - print("Module %s turned %s" % (name, switch)) - else: - print("Invalid module selected") - db.session.commit() - - @manager.option('-e', '--event', help='Event ID. Eg. 1') def fix_speaker_images(event): from app.helpers.sessions_speakers.speakers import speaker_image_sizes diff --git a/migrations/versions/rev-2020-07-24-21:26:41-286869159bb5_.py b/migrations/versions/rev-2020-07-24-21:26:41-286869159bb5_.py new file mode 100644 index 0000000000..e1fe17e46c --- /dev/null +++ b/migrations/versions/rev-2020-07-24-21:26:41-286869159bb5_.py @@ -0,0 +1,34 @@ +"""empty message + +Revision ID: 286869159bb5 +Revises: 8aef207c014f +Create Date: 2020-07-24 21:26:41.814719 + +""" + +from alembic import op +import sqlalchemy as sa +import sqlalchemy_utils + + +# revision identifiers, used by Alembic. +revision = '286869159bb5' +down_revision = '8aef207c014f' + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('modules') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('modules', + sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column('ticket_include', sa.BOOLEAN(), autoincrement=False, nullable=True), + sa.Column('payment_include', sa.BOOLEAN(), autoincrement=False, nullable=True), + sa.Column('donation_include', sa.BOOLEAN(), autoincrement=False, nullable=True), + sa.PrimaryKeyConstraint('id', name='modules_pkey') + ) + # ### end Alembic commands ### diff --git a/populate_db.py b/populate_db.py index 7756f531ba..e47dfc6270 100644 --- a/populate_db.py +++ b/populate_db.py @@ -23,7 +23,6 @@ from app.models.image_size import ImageSizes from app.models.message_setting import MessageSettings from app.models.microlocation import Microlocation -from app.models.module import Module # Admin Panel Permissions from app.models.panel_permission import PanelPermission @@ -124,10 +123,6 @@ def create_speaker_image_sizes(): ) -def create_modules(): - get_or_create(Module, donation_include=False) - - def create_event_topics(): event_topic = [ 'Health & Wellness', @@ -412,8 +407,6 @@ def populate(): create_user_permissions() print('Creating settings...') create_settings() - print('Creating modules...') - create_modules() print('Creating event image size...') create_event_image_sizes() print('Creating speaker image size...') @@ -446,7 +439,6 @@ def populate_without_print(): create_panel_permissions() create_user_permissions() create_settings() - create_modules() create_event_image_sizes() create_speaker_image_sizes() create_event_topics() diff --git a/tests/factories/module.py b/tests/factories/module.py deleted file mode 100644 index 8ab1344ee8..0000000000 --- a/tests/factories/module.py +++ /dev/null @@ -1,11 +0,0 @@ -from app.models.module import Module -from tests.factories.base import BaseFactory - - -class ModuleFactory(BaseFactory): - class Meta: - model = Module - - donation_include = True - ticket_include = True - payment_include = True diff --git a/tests/hook_main.py b/tests/hook_main.py index 251fa9bfb7..593eb25cae 100644 --- a/tests/hook_main.py +++ b/tests/hook_main.py @@ -51,7 +51,6 @@ from tests.factories.track import TrackFactory from tests.factories.ticket_tag import TicketTagFactory from tests.factories.role import RoleFactory -from tests.factories.module import ModuleFactory from tests.factories.ticket_fee import TicketFeesFactory from tests.factories.role_invite import RoleInviteFactory from tests.factories.custom_placeholder import CustomPlaceholderFactory @@ -355,8 +354,6 @@ def event_post(transaction): :return: """ with stash['app'].app_context(): - module = ModuleFactory() - db.session.add(module) RoleFactory(name=OWNER) # TODO: Change to get_or_create in event after_created db.session.commit() @@ -395,8 +392,6 @@ def event_patch(transaction): :return: """ with stash['app'].app_context(): - module = ModuleFactory() - db.session.add(module) event = EventFactoryBasic() db.session.add(event) db.session.commit() @@ -2827,33 +2822,6 @@ def settings_patch(transaction): db.session.commit() -# ------------------------- Modules ------------------------- -@hooks.before("Modules > Modules Details > Show Modules") -def modules_get_list(transaction): - """ - GET /modules - :param transaction: - :return: - """ - with stash['app'].app_context(): - module = ModuleFactory() - db.session.add(module) - db.session.commit() - - -@hooks.before("Modules > Modules Details > Update Modules") -def modules_patch(transaction): - """ - PATCH /modules - :param transaction: - :return: - """ - with stash['app'].app_context(): - module = ModuleFactory() - db.session.add(module) - db.session.commit() - - # ------------------------- Discount Codes ------------------------- @hooks.before( "Discount Codes > Event Discount Code Collection > List All Event Discount Codes"