Skip to content
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

Issue 07-Various quality of life changes #12

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions README-Windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Existing users (some have roles assigned, some don't):
Dev Userson | [email protected] | Active: False | Roles: ['Senior Dev/Getting Started']
Bruce Lee | [email protected] | Active: False | Roles: []
Scott Swain | [email protected] | Active: False | Roles: ['Dev/Getting Started']

```
# REGISTER
Invoke-WebRequest -Uri http://127.0.0.1:5000/register -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"username":"Bozo Clown", "email":"[email protected]", "password":"sosecure"}'

# LOGIN
Invoke-WebRequest -Uri http://127.0.0.1:5000/login -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"email":"[email protected]", "password":"sosecure"}'

# TOGGLE ACTIVE
Invoke-WebRequest -Uri http://127.0.0.1:5000/toggle-active -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"email":"[email protected]"}'

# SHOW USER PROFILE
Invoke-WebRequest -Uri http://127.0.0.1:5000/profile -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"username":"Scott Swain", "email":""}'

# SHOW ALL USERS (deprecated to the next two calls)
Invoke-WebRequest -Uri http://127.0.0.1:5000/users -Method GET -Headers @{"Content-Type" = "application/json"}

# SHOW ALL USERS with ALL ROLES
Invoke-WebRequest -Uri http://127.0.0.1:5000/users-roles -Method GET -Headers @{"Content-Type" = "application/json"}

# ACCESS REPORT
(Note: can replace "all_users" below with "active_users" or "inactive_users")
Invoke-WebRequest -Uri http://127.0.0.1:5000/access-report -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"limit_to":"all_users"}'

# DELETE USER
Invoke-WebRequest -Uri http://127.0.0.1:5000/delete-user -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"email":"[email protected]"}'

# CREATE ROLE(S)
Invoke-WebRequest -Uri http://127.0.0.1:5000/create-roles -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"roles_depts":["Senior Dev,Getting Started", "Dev,Getting Started"]}'

# ASSIGN ROLE(S)
(Note: any number of users can be assigned any number of role/dept combinations.)
Invoke-WebRequest -Uri http://127.0.0.1:5000/assign-roles -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"emails_roles_depts":["[email protected],Senior Dev,Getting Started", "[email protected],Dev,Getting Started"]}'
```
132 changes: 95 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,48 @@ These directions assume you will use `poetry` for dependency and environment man
poetry install
```

## Set up your secrets

### Create environment file
Create a file named .env in your project root.
Contents:
```
SECRET_KEY=mysecret
DATABASE_URI=sqlite:///users.db
TEST_DATABASE_URI=sqlite:///:memory:
FLASK_ENV=development
```
Note: Changes to the values in this file will be cached, so be sure to restart the application to get new values.

### Modify config.py
This file resides in the /project root/app folder.
Notice the following function accepts two arguments:
```
os.getenv(key, default value)
```
Depending on how secure you want your application to be, you may wish to modify the second argument to be less revealing, like so:
```
SECRET_KEY = os.getenv("SECRET_KEY", "mysecret")
# would change to:
SECRET_KEY = os.getenv("SECRET_KEY", "notmysecret")
```

### Make sure your .env file is not uploaded to GitHub
Find the .gitignore file.
It is one folder "up" from your project root folder.
In that file, look for the # Environments section.
It should have at least the exclusions you see here:
```
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
```

## Building the software

### Linting
Expand Down Expand Up @@ -252,45 +294,61 @@ We are going to make six figure bet on you. You are going to put your career in
We deeply appreciate the time you are taking to ensure joining Victory is of benefit to all concerned (yourself, Victory and our clients).

# Users in database (some have roles assigned, some don't)

See API call below titled "SHOW ALL USERS with ALL ROLES"

Dev Userson | [email protected] | Active: False | Roles: ['Senior Dev/Getting Started']
Bruce Lee | [email protected] | Active: False | Roles: []
Scott Swain | [email protected] | Active: False | Roles: ['Dev/Getting Started']
- Dev Userson | [email protected] | Active: False | Roles: ['Senior Dev/Getting Started']
- Bruce Lee | [email protected] | Active: False | Roles: []
- Scott Swain | [email protected] | Active: False | Roles: ['Dev/Getting Started']

# API calls

Dev Userson | [email protected] | Active: False | Roles: ['Senior Dev/Getting Started']
Bruce Lee | [email protected] | Active: False | Roles: []
Scott Swain | [email protected] | Active: False | Roles: ['Dev/Getting Started']

REGISTER
Invoke-WebRequest -Uri http://127.0.0.1:5000/register -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"username":"Bozo Clown", "email":"[email protected]", "password":"sosecure"}'

LOGIN
Invoke-WebRequest -Uri http://127.0.0.1:5000/login -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"email":"[email protected]", "password":"sosecure"}'

TOGGLE ACTIVE
Invoke-WebRequest -Uri http://127.0.0.1:5000/toggle-active -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"email":"[email protected]"}'

SHOW USER PROFILE
Invoke-WebRequest -Uri http://127.0.0.1:5000/profile -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"username":"Scott Swain", "email":""}'

SHOW ALL USERS (deprecated to the next two calls)
Invoke-WebRequest -Uri http://127.0.0.1:5000/users -Method GET -Headers @{"Content-Type" = "application/json"}

SHOW ALL USERS with ALL ROLES
Invoke-WebRequest -Uri http://127.0.0.1:5000/users-roles -Method GET -Headers @{"Content-Type" = "application/json"}

ACCESS REPORT
Invoke-WebRequest -Uri http://127.0.0.1:5000/access-report -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"limit_to":"all_users"}'

DELETE USER
Invoke-WebRequest -Uri http://127.0.0.1:5000/delete-user -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"email":"[email protected]"}'

CREATE ROLE(S)
Invoke-WebRequest -Uri http://127.0.0.1:5000/create-roles -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"roles_depts":["Senior Dev,Getting Started", "Dev,Getting Started"]}'
```
# REGISTER
curl -X POST http://127.0.0.1:5000/register \
-H "Content-Type: application/json" \
-d '{"username":"Bozo Clown", "email":"[email protected]", "password":"sosecure"}'

ASSIGN ROLE(S)
Invoke-WebRequest -Uri http://127.0.0.1:5000/assign-roles -Method POST -Headers @{"Content-Type" = "application/json"} -Body '{"emails_roles_depts":["[email protected],Senior Dev,Getting Started", "[email protected],Dev,Getting Started"]}'
# LOGIN
curl -X POST http://127.0.0.1:5000/login \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]", "password":"sosecure"}'

# TOGGLE ACTIVE
curl -X POST http://127.0.0.1:5000/toggle-active \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]"}'

# SHOW USER PROFILE
curl -X POST http://127.0.0.1:5000/profile \
-H "Content-Type: application/json" \
-d '{"username":"Scott Swain", "email":""}'

# SHOW ALL USERS (deprecated)
curl -X GET http://127.0.0.1:5000/users \
-H "Content-Type: application/json"

# SHOW ALL USERS with ALL ROLES
curl -X GET http://127.0.0.1:5000/users-roles \
-H "Content-Type: application/json"

# ACCESS REPORT
# (Note: can replace "all_users" below with "active_users" or "inactive_users")
curl -X POST http://127.0.0.1:5000/access-report \
-H "Content-Type: application/json" \
-d '{"limit_to":"all_users"}'

# DELETE USER
curl -X POST http://127.0.0.1:5000/delete-user \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]"}'

# CREATE ROLE(S)
curl -X POST http://127.0.0.1:5000/create-roles \
-H "Content-Type: application/json" \
-d '{"roles_depts":["Senior Dev,Getting Started", "Dev,Getting Started"]}'

# ASSIGN ROLE(S)
# (Note: any number of users can be assigned any number of role/dept combinations.)
curl -X POST http://127.0.0.1:5000/assign-roles \
-H "Content-Type: application/json" \
-d '{"emails_roles_depts":["[email protected],Senior Dev,Getting Started", "[email protected],Dev,Getting Started", "[email protected],Dev,Finance Dept"]}'
```
12 changes: 4 additions & 8 deletions app/config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import os
from dotenv import load_dotenv

load_dotenv()


class Config:
# SECRET_KEY = os.getenv("SECRET_KEY", "mysecret")
# old: SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URI", "sqlite:///users.db")
SECRET_KEY = os.getenv("SECRET_KEY")
# old:
SECRET_KEY = os.getenv("SECRET_KEY", "mysecret")
SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URI", "sqlite:///users.db")
# new:
# SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URI')
SQLALCHEMY_TRACK_MODIFICATIONS = False


Expand All @@ -23,7 +20,6 @@ class ProductionConfig(Config):

class TestingConfig(Config):
TESTING = True
# SQLALCHEMY_DATABASE_URI = os.getenv('TEST_DATABASE_URI', 'sqlite:///:memory:')
SQLALCHEMY_DATABASE_URI = os.getenv("TEST_DATABASE_URI")
SQLALCHEMY_DATABASE_URI = os.getenv("TEST_DATABASE_URI", "sqlite:///:memory:")
SQLALCHEMY_TRACK_MODIFICATIONS = False
WTF_CSRF_ENABLED = False # Disable CSRF for easier testing
1 change: 1 addition & 0 deletions app/routes/user_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json

# Configure logger to print to shell.
# (move this to a separate file so it can be referenced by multiple modules)
logger = logging.getLogger("alembic.env")
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
Expand Down
7 changes: 4 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
from app import create_app, db
from app.config import DevelopmentConfig, ProductionConfig

# Load environment variables from .env file
# Load environment vars from .env file.
load_dotenv()

# Set up the app
# Set up the app.
config_class = (
DevelopmentConfig if os.getenv("FLASK_ENV") == "development" else ProductionConfig
)
app = create_app(config_class=config_class)

# Import models after the app is created
# Import models after the app is created.
from app.models import User, UserActiveStatusChange

if __name__ == "__main__":
with app.app_context():
print("\nApplication started successfully.\n")
print("Registered tables:")
for table in db.metadata.tables:
print(f"- {table}")
Expand Down
Loading