Skip to content

Commit

Permalink
Create Admin Subscription on Workspace create
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin1111 committed Oct 18, 2023
1 parent e19ebd7 commit 5cd6ef4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/workspaces/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def update_or_create_workspace(user, access_token):

FyleCredential.objects.update_or_create(refresh_token=auth_tokens.refresh_token, workspace_id=workspace.id, cluster_domain=cluster_domain)
async_task('apps.workspaces.tasks.async_add_admins_to_workspace', workspace.id, user.user_id)
async_task('apps.workspaces.tasks.async_create_admin_subcriptions', workspace.id)

return workspace

Expand Down
15 changes: 15 additions & 0 deletions apps/workspaces/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,18 @@ def async_update_fyle_credentials(fyle_org_id: str, refresh_token: str):
if fyle_credentials:
fyle_credentials.refresh_token = refresh_token
fyle_credentials.save()


def async_create_admin_subcriptions(workspace_id: int) -> None:
"""
Create admin subscriptions
:param workspace_id: workspace id
:return: None
"""
fyle_credentials = FyleCredential.objects.get(workspace_id=workspace_id)
platform = PlatformConnector(fyle_credentials)
payload = {
'is_enabled': True,
'webhook_url': '{}/workspaces/{}/fyle/exports/'.format(settings.API_URL, workspace_id)
}
platform.subscriptions.post(payload)
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ djangorestframework==3.11.2
django-sendgrid-v5==1.2.0
enum34==1.1.10
future==0.18.2
fyle==0.33.1
fyle-accounting-mappings==1.26.1
fyle-integrations-platform-connector==1.34.0
fyle-integrations-platform-connector==1.35.0
fyle-rest-auth==1.5.0
gevent==22.10.2
gunicorn==20.1.0
Expand Down
3 changes: 3 additions & 0 deletions sql/functions/delete-workspace.sql
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ BEGIN
RAISE NOTICE E'\n\n\n\n\n\n\n\n\nSwitch to integration_settings db and run the below query to delete the integration';
RAISE NOTICE E'select delete_integration(''%'');\n\n\n\n\n\n\n\n\n\n\n', _org_id;

RAISE NOTICE E'\n\n\n\n\n\n\n\n\nSwitch to prod db and run the below query to update the subscription';
RAISE NOTICE E'begin; update platform_schema.admin_subscriptions set is_enabled = false where org_id = ''%'';\n\n\n\n\n\n\n\n\n\n\n', _org_id;

RETURN;
END
$$ LANGUAGE plpgsql;

0 comments on commit 5cd6ef4

Please sign in to comment.