Skip to content

Commit

Permalink
Merge pull request #283 from Wizarrrr/v3-beta
Browse files Browse the repository at this point in the history
V3 beta
  • Loading branch information
realashleybailey authored Oct 29, 2023
2 parents 10f4cfa + 6b82fe6 commit bef4661
Show file tree
Hide file tree
Showing 46 changed files with 10,216 additions and 28,543 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
<a href="https://features.wizarr.dev">
<img alt="Submit Feature Requests" src="https://img.shields.io/badge/fider-vote%20on%20features-success.svg"/>
</a>
<a href="https://github.com/Wizarrrr/wizarr/actions/workflows/ci.yml">
<img alt="Github Build" src="https://img.shields.io/github/actions/workflow/status/wizarrrr/wizarr/ci.yml"/>
<a href="https://github.com/Wizarrrr/wizarr/actions/workflows/release.yml">
<img alt="Github Build" src="https://img.shields.io/github/actions/workflow/status/wizarrrr/wizarr/release.yml"/>
</a>
</p>

Expand All @@ -53,6 +53,10 @@ Wizarr is a automatic user invitation system for Plex and Jellyfin. Create a uni

Wizarr V2 has moved to the v2 branch [here](https://github.com/Wizarrrr/wizarr/tree/v2), your still more than welcome to use v2 however it will no longer be supported, we recommend using our new version, trust us it's 🔥.

## V3 upgradable from V2?

V3 can now support upgrading from V2, please make a backup of your database.db for the safest upgrade path.

## Major Features Include

- Automatic Invitation to your Media Server (Plex, Jellyfin)
Expand Down
6 changes: 3 additions & 3 deletions apps/wizarr-backend/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"executor": "@nxlv/python:run-commands",
"options": {
"commands": [
"mkdir -p ../database",
"DB_DIR=../database poetry run flask run --debug"
"make-dir ../database",
"poetry run flask run --debug"
],
"cwd": "apps/wizarr-backend/wizarr_backend"
}
Expand Down Expand Up @@ -78,4 +78,4 @@
}
},
"tags": []
}
}
2 changes: 2 additions & 0 deletions apps/wizarr-backend/wizarr_backend/api/routes/server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ def get(self):
from app import app
from app.security import is_setup_required
from helpers.settings import get_settings
from helpers.requests import get_requests

resp = {
"settings": get_settings(disallowed=["server_api_key"]),
"requests": get_requests(disallowed=["api_key"]),
"version": str(get_current_version()),
"update_available": need_update(),
"debug": True if app.debug else False,
Expand Down
3 changes: 2 additions & 1 deletion apps/wizarr-backend/wizarr_backend/app/migrator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ def run_migrations():

# Get the base directory
BASE_DIR = path.abspath(path.join(path.dirname(path.realpath(__file__)), "../", "../"))
MIGRATIONS_DIR = path.abspath(path.join(path.realpath(__file__), "../", "migrations"))

# Get the current migrations in the database
current_migrations = [migration.name for migration in Migrations.select()]

# Run the migrations in the migrations folder based on their filenames date and time from oldest to newest
for migration in sorted(listdir(path.join(BASE_DIR, "app", "migrator", "migrations"))):
for migration in sorted(listdir(MIGRATIONS_DIR)):
# Skip if it does not end with .py
if not migration.endswith(".py"):
continue
Expand Down
2 changes: 1 addition & 1 deletion apps/wizarr-backend/wizarr_backend/app/migrator/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def get_current_version():
# File path to the version file
version_file = path.join(path.dirname(path.realpath(__file__)), "../", "../", "../", "latest")
version_file = path.abspath(path.join(path.dirname(path.realpath(__file__)), "../", "../", "../", "../", "../", "latest"))

# Read the current version
with open(version_file, "r") as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def run():
db.execute_sql("DELETE FROM settings WHERE key = 'admin_password'")

# Create the new account using the old credentials
db.execute_sql(f"INSERT INTO accounts (username, password, role) VALUES ('{admin_username}', '{admin_password}', 'admin')")
db.execute_sql(f"INSERT INTO accounts (username, password, role, tutorial) VALUES ('{admin_username}', '{admin_password}', 'admin', 0)")

# Remove admin_key from the settings table
with db.transaction():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# CREATED ON VERSION: V3.4.2
# MIGRATION: 2023-10-28_19-21-23
# CREATED: Sat Oct 28 2023
#

from peewee import *
from playhouse.migrate import *

from app import db

# Do not change the name of this file,
# migrations are run in order of their filenames date and time

def run():
# Use migrator to perform actions on the database
migrator = SqliteMigrator(db)

# Add columns name server_id to requests table
with db.transaction():
# Check if the column exists
cursor = db.cursor()
cursor.execute("PRAGMA table_info(requests);")
columns = cursor.fetchall()
column_names = [column[1] for column in columns]

if 'name' not in column_names:
db.execute_sql("ALTER TABLE requests ADD COLUMN name TEXT")
else:
print("Column name already exists")

if 'server_id' not in column_names:
db.execute_sql("ALTER TABLE requests ADD COLUMN server_id TEXT DEFAULT 0")
else:
print("Column server_id already exists")


print("Migration 2023-10-28_19-21-23 complete")
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# CREATED ON VERSION: V3.4.2
# MIGRATION: 2023-10-29_16-35-41
# CREATED: Sun Oct 29 2023
#

from peewee import *
from playhouse.migrate import *

from app import db

# Do not change the name of this file,
# migrations are run in order of their filenames date and time

def run():
# Use migrator to perform actions on the database
migrator = SqliteMigrator(db)

# Add columns auth to users table
with db.transaction():
# Check if the column exists
cursor = db.cursor()
cursor.execute("PRAGMA table_info(users);")
columns = cursor.fetchall()
column_names = [column[1] for column in columns]

if 'auth' not in column_names:
db.execute_sql("ALTER TABLE users ADD COLUMN auth TEXT")
else:
print("Column auth already exists")

print("Migration 2023-10-29_16-35-41 complete")
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ def create_code():
if isinstance(invitation["specific_libraries"], list):
invitation["specific_libraries"] = ",".join(invitation["specific_libraries"])


# invitation["expires"] = None
# invitation["duration"] = None

# If expires is a string or int, convert it to a utc datetime plus the total minutes
if invitation["expires"] and isinstance(invitation["expires"], (str, int)):
invitation["expires"] = datetime.utcnow() + timedelta(minutes=int(str(invitation["expires"])))
Expand All @@ -127,6 +123,8 @@ def create_code():
if invitation["duration"] and isinstance(invitation["duration"], (str, int)):
invitation["duration"] = datetime.utcnow() + timedelta(minutes=int(str(invitation["duration"])))

invitation["created"] = datetime.utcnow()

# Create the invitation in the database
invite: Invitations = Invitations.create(**invitation)

Expand Down
16 changes: 16 additions & 0 deletions apps/wizarr-backend/wizarr_backend/helpers/requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from app.models.database import Requests
from playhouse.shortcuts import model_to_dict
from json import loads, dumps

def get_requests(disallowed: list[str] = None):
# Get all requests from the database
requests = list(Requests.select().dicts())

# Remove disallowed requests keys
if disallowed is not None:
for request in requests:
for key in disallowed:
del request[key]

# Return the requests
return loads(dumps(requests, indent=4, sort_keys=True, default=str))
7 changes: 5 additions & 2 deletions apps/wizarr-backend/wizarr_backend/helpers/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ def global_sync_users_to_media_server() -> dict[str]:
# Sync users from the media server to the database
if server_type == "plex":
sync_plex_users()
elif server_type == "jellyfin":

if server_type == "jellyfin":
sync_jellyfin_users()

# Return response
Expand All @@ -235,7 +236,8 @@ def global_get_user_profile_picture(user_id: str) -> str:
# Get the user"s profile picture from the media server
if server_type == "plex":
return get_plex_profile_picture(user_id)
elif server_type == "jellyfin":

if server_type == "jellyfin":
return get_jellyfin_profile_picture(user_id)

# Raise an error if the user"s profile picture is None
Expand Down Expand Up @@ -342,6 +344,7 @@ def global_invite_user_to_media_server(**kwargs) -> dict[str]:
Users.expires: invite.duration,
Users.auth: kwargs.get("token", None),
Users.email: user.email if server_type == "plex" else kwargs.get("email", None),
Users.created: datetime.utcnow()
})

# Add the user to the database
Expand Down
Loading

0 comments on commit bef4661

Please sign in to comment.