-
Notifications
You must be signed in to change notification settings - Fork 0
permission fixes #42
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
Merged
Merged
permission fixes #42
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -281,27 +281,54 @@ def inject_user_date_format(): | |
| app.register_blueprint(main) | ||
|
|
||
| with app.app_context(): | ||
| # Check database write permissions before proceeding | ||
| try: | ||
| from sqlalchemy import text | ||
| # Test database connectivity and write permissions | ||
| with db.engine.connect() as conn: | ||
| # Try a simple write operation to test permissions | ||
| conn.execute(text('CREATE TABLE IF NOT EXISTS permission_test (id INTEGER)')) | ||
| conn.execute(text('DROP TABLE IF EXISTS permission_test')) | ||
| conn.commit() | ||
| print("✅ Database write permissions verified") | ||
| except Exception as e: | ||
| print(f"❌ Database permission error: {e}") | ||
| print("🔧 Please check database file permissions:") | ||
| print(" - sudo chown -R 1000:1000 ./data") | ||
| print(" - chmod 755 ./data") | ||
| print(" - chmod 664 ./data/subscriptions.db (if exists)") | ||
| # Don't exit, continue trying to initialize | ||
|
|
||
| # Run automatic database migrations before creating tables | ||
| migrate_database() | ||
|
|
||
| db.create_all() | ||
| try: | ||
| db.create_all() | ||
| print("✅ Database tables created/verified") | ||
| except Exception as e: | ||
| print(f"❌ Failed to create database tables: {e}") | ||
| raise | ||
|
|
||
| # Create default admin user if no admin users exist | ||
| from app.models import User, UserSettings | ||
| admin_exists = User.query.filter_by(is_admin=True).first() | ||
| if not admin_exists: | ||
| default_user = User(username='admin', email='[email protected]', is_admin=True) | ||
| default_user.set_password('changeme') | ||
| db.session.add(default_user) | ||
| db.session.commit() | ||
|
|
||
| # Create default settings for admin user | ||
| admin_settings = UserSettings(user_id=default_user.id, date_format='eu') | ||
| db.session.add(admin_settings) | ||
| db.session.commit() | ||
|
|
||
| print("Default admin user created: username='admin', password='changeme'") | ||
| print("Please change the default password immediately!") | ||
| try: | ||
| from app.models import User, UserSettings | ||
| admin_exists = User.query.filter_by(is_admin=True).first() | ||
| if not admin_exists: | ||
| default_user = User(username='admin', email='[email protected]', is_admin=True) | ||
| default_user.set_password('changeme') | ||
| db.session.add(default_user) | ||
| db.session.commit() | ||
|
|
||
| # Create default settings for admin user | ||
| admin_settings = UserSettings(user_id=default_user.id, date_format='eu') | ||
| db.session.add(admin_settings) | ||
| db.session.commit() | ||
|
|
||
| print("✅ Default admin user created: username='admin', password='changeme'") | ||
| print("⚠️ Please change the default password immediately!") | ||
| except Exception as e: | ||
| print(f"❌ Failed to create default admin user: {e}") | ||
| # This is not critical, continue running | ||
|
|
||
| # Lazy scheduler + perf timer combined (Flask 3 removed before_first_request) | ||
| @app.before_request | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating and dropping a test table on every application startup adds unnecessary overhead. Consider using a simpler write test like inserting into an existing table or checking database file permissions instead.