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

Add domain override functionality for background colors and cover images #594

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

aekeus
Copy link
Member

@aekeus aekeus commented Oct 18, 2023

This commit introduces the ability to override the background color and cover image URL for specific domains. This is achieved through the addition of a new domain_overrides table in a new database and corresponding management scripts. The perform_overrides function has been added to apply these overrides when processing cover images. The necessary database configuration has been added to the config.py file. The psycopg2-binary package has been added to the requirements to handle PostgreSQL database interactions. Unit tests have been updated to cover the new functionality.

This commit introduces the ability to override the background color and cover image URL for specific domains. This is achieved through the addition of a new `domain_overrides` table in the database and corresponding management scripts. The `perform_overrides` function has been added to apply these overrides when processing cover images. The necessary database configuration has been added to the `config.py` file. The `psycopg2-binary` package has been added to the requirements to handle PostgreSQL database interactions. Unit tests have been updated to cover the new functionality.
LorenzoMinto
LorenzoMinto previously approved these changes Oct 18, 2023
Copy link
Collaborator

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

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

Okay, so assuming we're going to introduce a dashboard for managing this, then this LGTM (otherwise it seems like overkill). It'd be awesome if we could eventually manage all the source information from there, rather than having our sources.*.csv files being the source of truth.

My only other concern is that the image urls tend to change semi regularly, so I'd expect overrides to often 404 after a while. Not sure if there's an easy solution, but maybe we could store the actual image in our DB (though I guess we'd need to serve them ourselves).

bin/manage.py Outdated

# if the type is cover_url, the value must be a url
if type == 'cover_url':
assert(value[:4] == 'http')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe worth enforcing https:?

@@ -297,6 +299,23 @@ def process_cover_image(item):

return domain, padded_image_url, background_color

def domain_overrides(config):
# connect to the database
db = psycopg2.connect(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not much of a python programmer, but is there some kind of auto-dispose statement?

# may be something I'm imagining, rather than a real thing but can we do:
with psycopg2.connect(....) as db:
    ...
    return rows


result = perform_overrides(result, overrides)

assert(result['http://brave.com']['background_color'] == '#000000')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be worth adding tests that subdomains/other origins don't get overridden.

@aurangzaib048
Copy link
Member

I think we no more needed this PR, Can we close it? @aekeus

@aekeus
Copy link
Member Author

aekeus commented Oct 30, 2023

Let's wait to see the results of the image work. This may be necessary to change the background colors.

@fallaciousreasoning
Copy link
Collaborator

fallaciousreasoning commented Oct 30, 2023

Sorry @aurangzaib048 why don't we need this now? I think fixing the transparency in the cover images will help, but there are definitely images we're going to want to override.

For example, this USA Today image is a bandwidth shattering 16x16
image

And as @aekeus says, we're definitely going to want to override the background color"
image

Once the transparency fix lands, this is going to be a red C on a red background 😆

@aurangzaib048
Copy link
Member

aurangzaib048 commented Nov 1, 2023

@fallaciousreasoning We don’t need this PR, but we need this kind of things for overriding. We are working on the overriding the URL or Background color in different way. Here: https://bravesoftware.slack.com/archives/C05QN258KJ7/p1698155086350469

@LorenzoMinto
Copy link
Member

@aurangzaib048 I thought the admin dashboard was a GUI to manage the overrides

@aurangzaib048
Copy link
Member

Yeah that’s correct, but that will be another repo which will be used to do such types of things. @LorenzoMinto

@aekeus
Copy link
Member Author

aekeus commented Nov 1, 2023

This PR will do the work of injecting the background color or cover url during the aggregation. It is a complement (not a replacement) for the UI @aurangzaib048 . This PR still needs a bit of work (moving the migrations around etc...).

- Removed domain override management instructions from README.md and added instructions for running tests.
- Reordered psycopg2-binary in requirements.dev.txt and requirements.txt for better organization.
- Refactored import statements in cover_images.py for better readability.
- Improved formatting in cover_images.py and utils.py for better readability.
- Updated tests in test.py to include more comprehensive checks for domain overrides.
@aekeus aekeus changed the title [DRAFT] Add domain override functionality for background colors and cover images Add domain override functionality for background colors and cover images Nov 28, 2023
@aekeus aekeus requested a review from porteron November 28, 2023 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants