Overview
The SJAA Membership application uses a database-backed configuration system called AppConfig to manage application settings. This replaces environment variables for application functionality settings, allowing administrators to update configuration through a web UI without requiring application redeployment.Why AppConfig?
Traditional approach (environment variables):- Requires server access to change settings
- Needs application restart for changes to take effect
- No audit trail of configuration changes
- Security risks if
.envfiles are accidentally committed
- Change settings through admin web UI at
/app_configs - Changes take effect immediately (cached for 5 minutes)
- Encrypted storage for sensitive values
- No redeployment needed
- Role-based access control (requires
permitpermission)
Configuration Categories
AppConfig organizes settings into three categories:SMTP Email Settings
Email server configuration for sending notifications, renewal reminders, and other system emails.PayPal Payment Settings
PayPal API credentials for processing membership renewals and donations.Google API Settings
Credentials and identifiers for Google Workspace integration (Groups, Calendar, OAuth).Managing Configuration
Web UI (Recommended)
- Log in as an admin with
permitpermission - Navigate to Data → App Configuration (
/app_configs) - View all settings organized by category
- Click on any value to edit it
- Update the value and save
For encrypted fields, the value is displayed as
[Encrypted - Set] or [Not Set]. Leave the field blank when editing to keep the existing value, or enter a new value to update it.First-Time Setup
If no configuration exists, you’ll see a button to Initialize Configuration from Environment Variables.What does initialization do?
What does initialization do?
- Creates all 13 configuration entries in the database
- Populates values from environment variables (if set in
.env) - Uses sensible defaults for values not in environment variables
- Equivalent to running
docker compose run --rm app bin/rails db:seed
- Initial application setup
- Migrating from environment variables to AppConfig
- Resetting configuration to defaults
Programmatic Access
Access configuration values in Ruby code:Helper Methods
TheGoogleHelper module provides convenient methods for accessing Google-related configuration:
Security
Encrypted Values
Sensitive configuration values are encrypted at rest using Rails 7’s built-in ActiveRecord encryption:- SMTP Password: Email server password
- PayPal Credentials: Client ID and secret
- Google OAuth Config: Base64-encoded client configuration
- Google API Key: Calendar API access key
Setting Up Encryption
Production environment:Access Control
Only admins with thepermit permission can access /app_configs. This is enforced through Pundit policy:
Performance
Caching
Configuration values are cached in memory for 5 minutes to minimize database queries:Cache Management
Cache is automatically cleared when:- A configuration value is updated
- A configuration record is deleted
Database Schema
AppConfig uses a simple database table:Migration from Environment Variables
If you’re migrating from environment variables to AppConfig, see the Migration Guide for detailed instructions.Quick Migration Steps
- Deploy the migration to create
app_configstable - Use the web UI to initialize configuration from existing environment variables
- Verify settings work correctly
- Optionally remove old environment variables from
.env(keep deployment-related vars)
Common Tasks
Update SMTP Settings
- Navigate to
/app_configs - Find SMTP Email Settings section
- Click on the value you want to change
- Update and save
- Changes take effect immediately
Update PayPal Credentials
- Navigate to
/app_configs - Find PayPal Payment Settings section
- Click on the encrypted value (shows
[Encrypted - Set]) - Enter the new client ID or secret
- Save - value is encrypted automatically
Configure Google Calendar
- Navigate to
/app_configs - Find Google API Settings section
- Click on
google_all_events_calendar_id - Enter your calendar ID (format:
xyz@group.calendar.google.com) - Save
Test Configuration Changes
After updating configuration:Troubleshooting
Configuration Not Taking Effect
Problem: Changed a setting but the app still uses the old value Solution:Cannot Access /app_configs
Problem: “You are not authorized to perform this action” error Solution: Ensure your admin account has thepermit permission:
Encryption Errors in Production
Problem: “Missing Active Record encryption credential” error Solution: Configure Rails credentials for encryption:Lost Configuration After Reset
Problem: Configuration disappeared afterdb:reset
Solution: Re-initialize using the seed button:
- Navigate to
/app_configs - Click Initialize Configuration from Environment Variables
- Verify settings were restored
API Reference
Class Methods
Convenience Methods
Cache Management
Instance Methods
Best Practices
When to Use AppConfig
✅ Use AppConfig for:- Application functionality settings (SMTP, API keys, group emails)
- Values that change occasionally
- Settings that require encryption
- Configuration managed by non-technical admins
- Sensitive data that should be encrypted
- Deployment and infrastructure settings
- Values that differ between environments (dev, staging, prod)
- Settings needed before database is available
- Example:
DATABASE_URL,RAILS_ENV,GITHUB_TOKEN
Security Guidelines
- Never commit
.envfiles to version control - Always encrypt sensitive values (passwords, API keys, secrets)
- Limit access to
/app_configsto admins withpermitpermission - Configure encryption in production environments
- Audit changes by reviewing database timestamps and modified values
Performance Tips
- Cache is automatic - don’t worry about it for most use cases
- Batch updates if changing multiple settings at once
- Clear cache after bulk updates to see changes immediately
- Monitor cache hit rates in production if needed
Summary
AppConfig provides a robust, secure, and user-friendly way to manage application configuration:- Web-based UI for easy updates without server access
- Encrypted storage for sensitive credentials
- Automatic caching for optimal performance
- Role-based access for security
- Migration path from environment variables
- Flexible API for programmatic access
/app_configs is all you need to manage application settings safely and efficiently.