# Legal Pages Setup Guide

## Overview

The `legal` app provides production-ready Privacy Policy and Terms of Service pages for your BMC Employee Utility App submission to Apple App Store and Google Play Store.

## What's Included

✅ **Privacy Policy** (`/legal/privacy/`)
- Covers data collection practices
- Explains data usage and retention
- Details security measures
- Compliant with App Store guidelines

✅ **Terms of Service** (`/legal/terms/`)
- Employee-focused agreement
- Account responsibilities
- Service availability disclaimers
- Intellectual property and liability limitations

✅ **Responsive Design**
- Mobile-friendly layout
- Works on all devices
- Clean, professional styling
- Dark-friendly color scheme (BMC brand green #39b54a)

✅ **Performance Optimized**
- Pages cached for 24 hours (configurable)
- No database queries needed
- Minimal server overhead
- SEO-friendly metadata

## Installation

### 1. App is Already Registered

The `legal` app has been added to `INSTALLED_APPS` in `BMC/settings.py`:
```python
INSTALLED_APPS = [
    ...
    'legal',
    ...
]
```

### 2. URLs are Already Included

Routes have been added to `BMC/urls.py`:
```python
path('legal/', include('legal.urls')),
```

### 3. Access the Pages

Navigate to these URLs:
- **Privacy Policy**: `/legal/privacy/` or `/en/legal/privacy/`, `/vi/legal/privacy/`
- **Terms of Service**: `/legal/terms/` or `/en/legal/terms/`, `/vi/legal/terms/`

## Customization

### Update Placeholder Information

The templates contain placeholders marked with `<span class="placeholder">[PLACEHOLDER_NAME]</span>`.

Edit these files to replace placeholders:

#### 1. **privacy.html** - Replacements needed:
```html
<span class="placeholder">[CONTACT_EMAIL]</span>
→ Replace with: your-email@bmcgroup.com.vn

<span class="placeholder">[COMPANY_MAILING_ADDRESS]</span>
→ Replace with: Your company's physical address
```

#### 2. **terms.html** - Replacements needed:
```html
<span class="placeholder">[GOVERNING_LAW_JURISDICTION]</span>
→ Replace with: Vietnam (or your jurisdiction)

<span class="placeholder">[JURISDICTION_COURTS]</span>
→ Replace with: District Courts of Vietnam

<span class="placeholder">[CONTACT_EMAIL]</span>
→ Replace with: your-email@bmcgroup.com.vn

<span class="placeholder">[COMPANY_MAILING_ADDRESS]</span>
→ Replace with: Your company's physical address
```

### Example Customization

Edit `legal/templates/legal/privacy.html`:
```html
<!-- BEFORE -->
<p><strong>Contact Email:</strong> <span class="placeholder">[CONTACT_EMAIL]</span></p>

<!-- AFTER -->
<p><strong>Contact Email:</strong> legal@bmcgroup.com.vn</p>
```

### Change Company Name

Currently uses "BMC Group". To change:

1. **In base.html**: Update `<h1>BMC Group</h1>`
2. **In privacy.html**: Update company references
3. **In terms.html**: Update company references

### Translate to Vietnamese

The pages support internationalization (i18n). To add Vietnamese versions:

1. Create `/legal/templates/legal/privacy_vi.html`
2. Create `/legal/templates/legal/terms_vi.html`
3. Update `legal/views.py` to detect language and load appropriate template

Or use Django's translation framework:
```python
from django.utils.translation import gettext_lazy as _
```

### Style Customization

Edit styles in `base.html` `<style>` section:

**Change accent color** (currently #39b54a - BMC green):
```css
header h1 {
    color: #39b54a;  /* ← Change this */
}
```

**Change layout width**:
```css
.container {
    max-width: 900px;  /* ← Increase/decrease */
}
```

**Change font**:
```css
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 
                 'Helvetica Neue', Arial, sans-serif;  /* ← Modify list */
}
```

## Configuration

### Caching

Pages are cached for **24 hours** (86400 seconds). To change:

Edit `legal/views.py`:
```python
@method_decorator(cache_page(86400))  # ← Change this number
def dispatch(self, *args, **kwargs):
    return super().dispatch(*args, **kwargs)
```

**Cache durations** (in seconds):
- 60 = 1 minute
- 3600 = 1 hour
- 86400 = 24 hours
- 604800 = 1 week

### Disable Caching (Development)

Comment out or remove the `@method_decorator(cache_page(...))` line:
```python
# @method_decorator(cache_page(86400))
def dispatch(self, *args, **kwargs):
    return super().dispatch(*args, **kwargs)
```

### SEO Metadata

Customize page titles and descriptions in `legal/views.py`:

```python
def get_context_data(self, **kwargs):
    context = super().get_context_data(**kwargs)
    context['page_title'] = 'Privacy Policy'  # ← Change title
    context['meta_description'] = 'Custom description here'  # ← Change meta
    return context
```

## Testing

### Run Tests

```bash
python manage.py test legal
```

Tests verify:
- Pages return HTTP 200 OK
- Pages contain expected content
- URLs reverse correctly

### Manual Testing

1. **Privacy Policy**: Visit `/legal/privacy/`
   - Should display full privacy policy
   - Should include placeholder warnings (yellow boxes)

2. **Terms of Service**: Visit `/legal/terms/`
   - Should display full terms
   - Should include placeholder warnings

3. **Navigation**: Both pages should show navigation links at top

4. **Mobile**: Test on mobile device/browser
   - Should be readable
   - Should not require horizontal scrolling
   - Should maintain formatting

## Production Deployment

### Before Going Live

1. ✅ Update all placeholder values
2. ✅ Review legal text for accuracy
3. ✅ Verify contact email is correct
4. ✅ Test on mobile devices
5. ✅ Set appropriate cache duration
6. ✅ Add to App Store submission
7. ✅ Add to Google Play submission

### App Store/Play Store Links

Add these links to your app submission:
- **Privacy Policy**: `https://bmcgroup.com.vn/legal/privacy/`
- **Terms of Service**: `https://bmcgroup.com.vn/legal/terms/`

Or in i18n format:
- **Privacy Policy**: `https://bmcgroup.com.vn/en/legal/privacy/`
- **Terms of Service**: `https://bmcgroup.com.vn/en/legal/terms/`

### Monitoring

Check periodically:
- Links still work
- Pages load quickly (check cache effectiveness)
- No broken placeholders remain
- Update "Last Updated" date when making changes

## Troubleshooting

### Pages Show "[PLACEHOLDER]" Boxes

**Problem**: Placeholder warnings are still visible
**Solution**: Edit templates and replace all `<span class="placeholder">[...]</span>` with actual values

### Pages Not Accessible

**Problem**: Getting 404 error
**Solution**: 
1. Verify 'legal' is in `INSTALLED_APPS`
2. Verify URLs are included in `BMC/urls.py`
3. Check URL spelling: `/legal/privacy/` and `/legal/terms/`

### Styles Look Wrong

**Problem**: Colors or layout incorrect
**Solution**: 
1. Check CSS in `base.html` isn't overridden by global styles
2. Clear browser cache: Ctrl+Shift+Delete
3. Check for typos in color hex codes

### Pages Slow to Load

**Problem**: Pages taking time on first load
**Solution**: 
1. Pages should load fast after first request due to caching
2. If still slow, check database connection
3. Ensure DEBUG=False in production

## File Structure

```
legal/
├── __init__.py
├── apps.py
├── models.py          # (empty - no database models)
├── views.py           # Two views: PrivacyPolicyView, TermsOfServiceView
├── urls.py            # URL routing: /privacy/, /terms/
├── admin.py           # (empty - no admin interface)
├── tests.py           # Test cases
├── SETUP_GUIDE.md     # This file
└── templates/legal/
    ├── base.html      # Master template
    ├── privacy.html   # Privacy Policy page
    └── terms.html     # Terms of Service page
```

## Support

For questions or updates needed:

1. **Review text**: Edit relevant template file
2. **Change colors**: Update CSS in `base.html`
3. **Add translations**: Create new template files with language code
4. **Modify layout**: Edit HTML structure in templates

## Maintenance

### Periodic Reviews

Recommend reviewing content:
- **Quarterly**: Check for regulatory updates
- **Annually**: Update "Last Updated" date
- **On feature change**: Add/remove data collection items if app features change

### Version Control

Track changes in your Git history:
```bash
git add legal/
git commit -m "feat: add legal pages for app store submission"
```

## Additional Resources

- **Apple App Store Guidelines**: https://developer.apple.com/app-store/review/guidelines/
- **Google Play Policies**: https://play.google.com/about/developer-content-policy/
- **Django Template Documentation**: https://docs.djangoproject.com/en/4.0/topics/templates/
- **Django Caching**: https://docs.djangoproject.com/en/4.0/topics/cache/

---

**Setup completed**: Your legal pages are ready for production! 🚀
