Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- __pycache__/search_engine.cpython-311.pyc +0 -0
- app/__pycache__/api.cpython-311.pyc +0 -0
- app/__pycache__/config.cpython-311.pyc +0 -0
- app/__pycache__/xero_client.cpython-311.pyc +0 -0
- app/__pycache__/xero_routes.cpython-311.pyc +0 -0
- app/xero_client.py +35 -25
- app/xero_routes.py +3 -3
- flask_session/aa71dde20eaf768ca7e5f90a25563ea6 +0 -0
- run.py +1 -1
__pycache__/search_engine.cpython-311.pyc
CHANGED
Binary files a/__pycache__/search_engine.cpython-311.pyc and b/__pycache__/search_engine.cpython-311.pyc differ
|
|
app/__pycache__/api.cpython-311.pyc
CHANGED
Binary files a/app/__pycache__/api.cpython-311.pyc and b/app/__pycache__/api.cpython-311.pyc differ
|
|
app/__pycache__/config.cpython-311.pyc
CHANGED
Binary files a/app/__pycache__/config.cpython-311.pyc and b/app/__pycache__/config.cpython-311.pyc differ
|
|
app/__pycache__/xero_client.cpython-311.pyc
CHANGED
Binary files a/app/__pycache__/xero_client.cpython-311.pyc and b/app/__pycache__/xero_client.cpython-311.pyc differ
|
|
app/__pycache__/xero_routes.cpython-311.pyc
CHANGED
Binary files a/app/__pycache__/xero_routes.cpython-311.pyc and b/app/__pycache__/xero_routes.cpython-311.pyc differ
|
|
app/xero_client.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
import logging
|
2 |
-
|
3 |
import json
|
4 |
import time
|
5 |
import requests
|
6 |
from functools import wraps
|
7 |
from flask import current_app, redirect, url_for, session, request
|
|
|
|
|
8 |
|
9 |
logger = logging.getLogger(__name__)
|
10 |
|
@@ -80,7 +82,7 @@ def initialize_zoho_sdk(grant_token=None, accounts_server_url=None):
|
|
80 |
config = current_app.config
|
81 |
|
82 |
# Use the dynamically provided accounts_server_url or default to .in
|
83 |
-
base_accounts_url = accounts_server_url if accounts_server_url else 'https://accounts.
|
84 |
token_url = f'{base_accounts_url}/oauth/v2/token'
|
85 |
logger.info(f"Using token exchange URL: {token_url}")
|
86 |
|
@@ -119,21 +121,28 @@ def initialize_zoho_sdk(grant_token=None, accounts_server_url=None):
|
|
119 |
logger.debug("initialize_zoho_sdk called without grant token. No action taken.")
|
120 |
|
121 |
def _get_stored_token():
|
122 |
-
"""Reads token data from
|
123 |
-
token_path = current_app.config['ZOHO_TOKEN_PERSISTENCE_PATH']
|
124 |
-
if not os.path.exists(token_path):
|
125 |
-
return None
|
126 |
try:
|
127 |
-
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
130 |
return None
|
131 |
|
132 |
def _save_token(token_data):
|
133 |
-
"""Saves token data to
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
def _refresh_access_token():
|
139 |
"""Uses the refresh token to get a new access token from the correct data center."""
|
@@ -147,7 +156,7 @@ def _refresh_access_token():
|
|
147 |
config = current_app.config
|
148 |
|
149 |
# Use the stored accounts_server or default for backward compatibility
|
150 |
-
base_accounts_url = stored_token.get('accounts_server', 'https://accounts.
|
151 |
token_url = f'{base_accounts_url}/oauth/v2/token'
|
152 |
logger.info(f"Using token refresh URL: {token_url}")
|
153 |
|
@@ -189,19 +198,21 @@ def get_access_token():
|
|
189 |
return token.get('access_token')
|
190 |
|
191 |
def is_zoho_token_available():
|
192 |
-
"""Checks if a refresh token has been persisted in
|
193 |
token = _get_stored_token()
|
194 |
return token is not None and 'refresh_token' in token
|
195 |
|
196 |
def clear_zoho_token():
|
197 |
-
"""Removes the persisted token
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
|
|
|
|
205 |
|
206 |
def zoho_token_required(function):
|
207 |
"""
|
@@ -213,5 +224,4 @@ def zoho_token_required(function):
|
|
213 |
session['next_url'] = request.url
|
214 |
return redirect(url_for("zoho.login"))
|
215 |
return function(*args, **kwargs)
|
216 |
-
return decorator
|
217 |
-
|
|
|
1 |
import logging
|
2 |
+
# os is no longer needed for token persistence
|
3 |
import json
|
4 |
import time
|
5 |
import requests
|
6 |
from functools import wraps
|
7 |
from flask import current_app, redirect, url_for, session, request
|
8 |
+
# Import the mongo instance from your extensions file
|
9 |
+
from .extensions import mongo
|
10 |
|
11 |
logger = logging.getLogger(__name__)
|
12 |
|
|
|
82 |
config = current_app.config
|
83 |
|
84 |
# Use the dynamically provided accounts_server_url or default to .in
|
85 |
+
base_accounts_url = accounts_server_url if accounts_server_url else 'https://accounts.zohocloud.ca'
|
86 |
token_url = f'{base_accounts_url}/oauth/v2/token'
|
87 |
logger.info(f"Using token exchange URL: {token_url}")
|
88 |
|
|
|
121 |
logger.debug("initialize_zoho_sdk called without grant token. No action taken.")
|
122 |
|
123 |
def _get_stored_token():
|
124 |
+
"""Reads token data from MongoDB."""
|
|
|
|
|
|
|
125 |
try:
|
126 |
+
# Use a consistent identifier for the single token document
|
127 |
+
token_doc = mongo.db.zoho_tokens.find_one({'_id': 'zoho_oauth_token'})
|
128 |
+
if token_doc:
|
129 |
+
# The _id is not part of the token data itself, remove it
|
130 |
+
token_doc.pop('_id', None)
|
131 |
+
return token_doc
|
132 |
+
except Exception as e:
|
133 |
+
logger.error(f"Error reading Zoho token from MongoDB: {e}", exc_info=True)
|
134 |
return None
|
135 |
|
136 |
def _save_token(token_data):
|
137 |
+
"""Saves token data to MongoDB."""
|
138 |
+
try:
|
139 |
+
mongo.db.zoho_tokens.update_one(
|
140 |
+
{'_id': 'zoho_oauth_token'},
|
141 |
+
{'$set': token_data},
|
142 |
+
upsert=True
|
143 |
+
)
|
144 |
+
except Exception as e:
|
145 |
+
logger.error(f"Error saving Zoho token to MongoDB: {e}", exc_info=True)
|
146 |
|
147 |
def _refresh_access_token():
|
148 |
"""Uses the refresh token to get a new access token from the correct data center."""
|
|
|
156 |
config = current_app.config
|
157 |
|
158 |
# Use the stored accounts_server or default for backward compatibility
|
159 |
+
base_accounts_url = stored_token.get('accounts_server', 'https://accounts.zohocloud.ca')
|
160 |
token_url = f'{base_accounts_url}/oauth/v2/token'
|
161 |
logger.info(f"Using token refresh URL: {token_url}")
|
162 |
|
|
|
198 |
return token.get('access_token')
|
199 |
|
200 |
def is_zoho_token_available():
|
201 |
+
"""Checks if a refresh token has been persisted in MongoDB."""
|
202 |
token = _get_stored_token()
|
203 |
return token is not None and 'refresh_token' in token
|
204 |
|
205 |
def clear_zoho_token():
|
206 |
+
"""Removes the persisted token from MongoDB to effectively log out."""
|
207 |
+
try:
|
208 |
+
result = mongo.db.zoho_tokens.delete_one({'_id': 'zoho_oauth_token'})
|
209 |
+
if result.deleted_count > 0:
|
210 |
+
logger.info("Zoho token removed from MongoDB successfully.")
|
211 |
+
else:
|
212 |
+
logger.warning("Attempted to clear Zoho token, but none was found in MongoDB.")
|
213 |
+
except Exception as e:
|
214 |
+
logger.error(f"Error removing Zoho token from MongoDB: {e}", exc_info=True)
|
215 |
+
|
216 |
|
217 |
def zoho_token_required(function):
|
218 |
"""
|
|
|
224 |
session['next_url'] = request.url
|
225 |
return redirect(url_for("zoho.login"))
|
226 |
return function(*args, **kwargs)
|
227 |
+
return decorator
|
|
app/xero_routes.py
CHANGED
@@ -63,7 +63,7 @@ def login():
|
|
63 |
'access_type': 'offline',
|
64 |
'redirect_uri': config['ZOHO_REDIRECT_URL']
|
65 |
}
|
66 |
-
accounts_url = 'https://accounts.
|
67 |
auth_url = f"{accounts_url}?{urllib.parse.urlencode(params)}"
|
68 |
return redirect(auth_url)
|
69 |
|
@@ -95,14 +95,14 @@ def logout():
|
|
95 |
|
96 |
|
97 |
@zoho_bp.route("/api/inventory")
|
98 |
-
@zoho_token_required
|
99 |
def inventory_sync_page():
|
100 |
"""Renders the page that will display the sync progress bar."""
|
101 |
return render_template("inventory_sync.html", title="Inventory Sync")
|
102 |
|
103 |
|
104 |
@zoho_bp.route("/api/inventory/stream")
|
105 |
-
@zoho_token_required
|
106 |
def fetch_inventory_stream():
|
107 |
"""
|
108 |
Performs the inventory sync and streams progress updates to the client.
|
|
|
63 |
'access_type': 'offline',
|
64 |
'redirect_uri': config['ZOHO_REDIRECT_URL']
|
65 |
}
|
66 |
+
accounts_url = 'https://accounts.zohocloud.ca/oauth/v2/auth'
|
67 |
auth_url = f"{accounts_url}?{urllib.parse.urlencode(params)}"
|
68 |
return redirect(auth_url)
|
69 |
|
|
|
95 |
|
96 |
|
97 |
@zoho_bp.route("/api/inventory")
|
98 |
+
# @zoho_token_required
|
99 |
def inventory_sync_page():
|
100 |
"""Renders the page that will display the sync progress bar."""
|
101 |
return render_template("inventory_sync.html", title="Inventory Sync")
|
102 |
|
103 |
|
104 |
@zoho_bp.route("/api/inventory/stream")
|
105 |
+
# @zoho_token_required
|
106 |
def fetch_inventory_stream():
|
107 |
"""
|
108 |
Performs the inventory sync and streams progress updates to the client.
|
flask_session/aa71dde20eaf768ca7e5f90a25563ea6
CHANGED
Binary files a/flask_session/aa71dde20eaf768ca7e5f90a25563ea6 and b/flask_session/aa71dde20eaf768ca7e5f90a25563ea6 differ
|
|
run.py
CHANGED
@@ -4,4 +4,4 @@ os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
|
|
4 |
app = create_app()
|
5 |
|
6 |
if __name__ == '__main__':
|
7 |
-
app.run(host="0.0.0.0",debug=
|
|
|
4 |
app = create_app()
|
5 |
|
6 |
if __name__ == '__main__':
|
7 |
+
app.run(host="0.0.0.0",debug=False, port=7860)
|