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

Move sitewide settings to environment variables (PP-494) #1648

Merged
merged 8 commits into from
Feb 8, 2024

Conversation

jonathangreen
Copy link
Member

@jonathangreen jonathangreen commented Feb 1, 2024

Description

Move our sitewide settings to environment variables, and remove the sitewide settings controller. Since this is the last bit of the configuration settings to get switched over, remove the old settings controller as well.

🚨 Before this one can be merged we need:

Changes to sitewide config:

  • LOG_LEVEL, LOG_APP_NAME and DATABASE_LOG_LEVEL removed because they were no longer used.
  • EXCLUDED_AUDIO_DATA_SOURCES removed, as its not used on any of our sites, and it was added long ago when testing overdrive content.
  • MEASUREMENT_REAPER removed, since we don't have any need to disable this reaper.
  • PUSH_NOTIFICATIONS_STATUS removed, since its enabled everywhere now anyway.
  • BEARER_TOKEN_SIGNING_SECRET is merged with SECRET_KEY, since they have a similar function and it doesn't seem like we need both of them.
  • STATIC_FILE_CACHE_TIME removed, since we don't serve static files with the CM anymore.
  • CUSTOM_TOS_HREF and CUSTOM_TOS_TEXT removed because we don't use them anywhere.

Motivation and Context

Close to the end of the work for PP-4.

How Has This Been Tested?

  • Running locally
  • Tests in CI

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

Copy link

codecov bot commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6540ea0) 89.53% compared to head (5fa96fb) 89.97%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1648      +/-   ##
==========================================
+ Coverage   89.53%   89.97%   +0.44%     
==========================================
  Files         245      244       -1     
  Lines       28817    28447     -370     
  Branches     6595     6493     -102     
==========================================
- Hits        25802    25596     -206     
+ Misses       2040     1895     -145     
+ Partials      975      956      -19     
Flag Coverage Δ
Api 75.45% <52.80%> (+0.16%) ⬆️
Core 60.04% <92.95%> (+0.72%) ⬆️
migration 27.04% <32.39%> (+0.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jonathangreen jonathangreen force-pushed the feature/sitewide-settings branch from 14d438d to 5fad772 Compare February 1, 2024 18:04
api/app.py Outdated
os.environ["PALACE_SECRET_KEY"] = "".join(
secrets.choice(string.ascii_lowercase) for i in range(24)
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the debug run function. Just allows us to run a debug environment with app.py without having to specify a SECRET_KEY every time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Might be useful to clarify in the comment that this is only safe because this is a debug environment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one will go away when #1664 goes in

core/util/notifications.py Show resolved Hide resolved
tests/api/test_controller_cm.py Show resolved Hide resolved
@jonathangreen jonathangreen requested a review from a team February 1, 2024 20:53
@jonathangreen
Copy link
Member Author

This one is ready for review now, but I'm leaving it in draft until the additional PR in the description are ready to go, so it doesn't get merged early.

Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. A few questions/comments, but no show stoppers.

README.md Outdated
#### General

- `PALACE_BASE_URL`: The base URL of the application. Used to create absolute links. (optional)
- `PALACE_SECRET_KEY`: A secret key used for used to provide cryptographic signing, and should be set to a unique,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated words: key [used for] [used to] provide

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this part of the README, in favor of the work in #1664

Comment on lines +78 to +79
sitewide_tos_href=Configuration.DEFAULT_TOS_HREF,
sitewide_tos_text=Configuration.DEFAULT_TOS_TEXT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be configurable, in case a non-Palace entity wants to run this code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we were running the Library Simplified code, we never actually set these did we? It wasn't until Palace when we customized them. I was thinking that we can make this configurable if/when someone needs it.

Happy to make them env vars though, if you disagree.

api/app.py Outdated
@@ -61,12 +59,12 @@ def get_locale():
PalaceXrayProfiler.configure(app)


def initialize_admin(_db=None):
def initialize_admin(_db: Session | None = None, secret_key: str | None = None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The secret key is required. Should we allow a None here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This went away with the work in #1664

api/app.py Outdated
os.environ["PALACE_SECRET_KEY"] = "".join(
secrets.choice(string.ascii_lowercase) for i in range(24)
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Might be useful to clarify in the comment that this is only safe because this is a debug environment.

Comment on lines -102 to -119
{
"key": CUSTOM_TOS_HREF,
"label": _("Custom Terms of Service link"),
"required": False,
"default": DEFAULT_TOS_HREF,
"description": _(
"If your inclusion in the SimplyE mobile app is governed by terms other than the default, put the URL to those terms in this link so that librarians will have access to them. This URL will be used for all libraries on this circulation manager."
),
},
{
"key": CUSTOM_TOS_TEXT,
"label": _("Custom Terms of Service link text"),
"required": False,
"default": DEFAULT_TOS_TEXT,
"description": _(
"Custom text for the Terms of Service link in the footer of these administrative interface pages. This is primarily useful if you're not connecting this circulation manager to the SimplyE mobile app. This text will be used for all libraries on this circulation manager."
),
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these get mapped to PALACE_ env vars, in case a non-palace entity wants to run the code? We could still use the default href and/or text, if they were not specified.

)
)
return
return super(ReaperMonitor, self).run()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some lingering Python 2 goodness.

Comment on lines 44 to 65
def test_script_run(self, holds_fixture: HoldsNotificationFixture):
db = holds_fixture.db
patron1 = db.patron()
work1 = db.work(with_license_pool=True)
work2 = db.work(with_license_pool=True)
hold1, _ = work1.active_license_pool().on_hold_to(patron1, position=0)
hold2, _ = work2.active_license_pool().on_hold_to(patron1, position=0)

with patch("core.jobs.holds_notification.PushNotifications") as mock_notf:
holds_fixture.monitor.run()
assert mock_notf.send_holds_notifications.call_count == 1
assert mock_notf.send_holds_notifications.call_args_list == [
call([hold1, hold2])
]

# Sitewide notifications are turned off
mock_notf.send_holds_notifications.reset_mock()
ConfigurationSetting.sitewide(
db.session, Configuration.PUSH_NOTIFICATIONS_STATUS
).value = ConfigurationConstants.FALSE
holds_fixture.monitor.run()
assert mock_notf.send_holds_notifications.call_count == 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to get rid of this whole test or just the part related to the defunct Configuration.PUSH_NOTIFICATIONS_STATUS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Added back in the non-config part of this test.

@jonathangreen jonathangreen force-pushed the feature/sitewide-settings branch from 49c4897 to 7b6a693 Compare February 7, 2024 23:31
@jonathangreen jonathangreen changed the base branch from main to feature/keys-table February 8, 2024 01:25
@jonathangreen jonathangreen force-pushed the feature/sitewide-settings branch from 7b6a693 to dd46877 Compare February 8, 2024 01:25
@jonathangreen jonathangreen force-pushed the feature/sitewide-settings branch from 5212a4f to 8feade0 Compare February 8, 2024 14:25
Base automatically changed from feature/keys-table to main February 8, 2024 18:07
@jonathangreen jonathangreen force-pushed the feature/sitewide-settings branch from 0a60402 to d4fb355 Compare February 8, 2024 18:23
@jonathangreen jonathangreen added UI Update This PR requires an admin UI update Deployment Changes Requires changes to deployment configuration. labels Feb 8, 2024
@jonathangreen jonathangreen marked this pull request as ready for review February 8, 2024 19:48
@jonathangreen jonathangreen merged commit 20bdf4a into main Feb 8, 2024
28 checks passed
@jonathangreen jonathangreen deleted the feature/sitewide-settings branch February 8, 2024 19:56
@jonathangreen jonathangreen added the incompatible changes Changes that require a new major version label Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deployment Changes Requires changes to deployment configuration. incompatible changes Changes that require a new major version UI Update This PR requires an admin UI update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants