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 Verified URLs #529

Merged
merged 60 commits into from
Sep 6, 2024
Merged

Add Verified URLs #529

merged 60 commits into from
Sep 6, 2024

Conversation

glenn-sorrentino
Copy link
Member

@glenn-sorrentino glenn-sorrentino commented Aug 29, 2024

When a user adds a link back to their Hush Line profile with the rel="me" attribute, a verified badge is added to the appropriate URL.

Example shown on my personal portfolio. In this screenshot you see a test link to my admin test account https://tips.hushline.app/to/admin.

Screenshot 2024-08-28 at 5 20 52 PM

On the server-side, we validate address submissions for URLs, and limit them to checking against tips.hushline.app addresses.

                # Trigger the rel=me verification for each URL field
                for i in range(1, 5):
                    url_to_verify = getattr(user, f"extra_field_value{i}", "").strip()
                    if url_to_verify:
                        try:
                            response = requests.get(url_to_verify, timeout=5)
                            response.raise_for_status()
                            profile_url = f"https://tips.hushline.app/to/{user.primary_username}"
                            if re.search(
                                rf'<a[^>]+href="{re.escape(profile_url)}"[^>]*rel="me"[^>]*>',
                                response.text,
                            ):
                                setattr(user, f"extra_field_verified{i}", True)
                            else:
                                setattr(user, f"extra_field_verified{i}", False)
                        except requests.exceptions.RequestException as e:
                            current_app.logger.error(f"Error fetching URL for field {i}: {e}")
                            setattr(user, f"extra_field_verified{i}", False)

                db.session.commit()

When the conditions validate, a new non-emoji icon appears in the website's fields in Settings and the Profile:

Screenshot 2024-08-28 at 5 20 28 PM

Screenshot 2024-08-28 at 5 28 29 PM

We also add new fields to the DB to track verification status per field:

    extra_field_verified1 = db.Column(db.Boolean, default=False)
    extra_field_verified2 = db.Column(db.Boolean, default=False)
    extra_field_verified3 = db.Column(db.Boolean, default=False)
    extra_field_verified4 = db.Column(db.Boolean, default=False)

hushline/settings.py Fixed Show fixed Hide fixed
hushline/settings.py Fixed Show fixed Hide fixed
hushline/settings.py Fixed Show fixed Hide fixed
hushline/settings.py Fixed Show fixed Hide fixed
hushline/model.py Outdated Show resolved Hide resolved
hushline/settings.py Outdated Show resolved Hide resolved
hushline/settings.py Outdated Show resolved Hide resolved
hushline/settings.py Outdated Show resolved Hide resolved
hushline/settings.py Outdated Show resolved Hide resolved
hushline/settings.py Outdated Show resolved Hide resolved
hushline/settings.py Outdated Show resolved Hide resolved
hushline/settings.py Outdated Show resolved Hide resolved
migrations/versions/83a6b3b09eca_add_verified_fields.py Outdated Show resolved Hide resolved
migrations/versions/83a6b3b09eca_add_verified_fields.py Outdated Show resolved Hide resolved
migrations/versions/83a6b3b09eca_add_verified_fields.py Outdated Show resolved Hide resolved
hushline/settings.py Outdated Show resolved Hide resolved
hushline/settings.py Outdated Show resolved Hide resolved
hushline/settings.py Outdated Show resolved Hide resolved
hushline/settings.py Outdated Show resolved Hide resolved
hushline/settings.py Outdated Show resolved Hide resolved
tests/test_profile.py Outdated Show resolved Hide resolved
Co-authored-by: Jeremy Moore <[email protected]>
jeremywmoore
jeremywmoore previously approved these changes Sep 5, 2024
Copy link
Collaborator

@jeremywmoore jeremywmoore 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, we will need a change in our infra repo to set the SERVER_NAME variable before this will work.

@micahflee micahflee added the deploy create dev deployment label Sep 5, 2024
Copy link

github-actions bot commented Sep 5, 2024

Terraform plan in terraform/dev in the hushline-dev-me workspace

With variables

branch = "me"
name   = "dev-me"
Plan: 2 to add, 0 to change, 0 to destroy. Changes to Outputs.
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+   create

Terraform will perform the following actions:

  # digitalocean_project.hush_line_dev will be created
+   resource "digitalocean_project" "hush_line_dev" {
+       created_at  = (known after apply)
+       description = "Development instance based on the me branch"
+       environment = "Development"
+       id          = (known after apply)
+       is_default  = false
+       name        = "dev-me"
+       owner_id    = (known after apply)
+       owner_uuid  = (known after apply)
+       purpose     = "Web Application"
+       resources   = (known after apply)
+       updated_at  = (known after apply)
    }

  # module.app.digitalocean_app.app will be created
+   resource "digitalocean_app" "app" {
+       active_deployment_id = (known after apply)
+       created_at           = (known after apply)
+       default_ingress      = (known after apply)
+       id                   = (known after apply)
+       live_url             = (known after apply)
+       project_id           = (known after apply)
+       updated_at           = (known after apply)
+       urn                  = (known after apply)

+       dedicated_ips (known after apply)

+       spec {
+           domains  = (known after apply)
+           features = [
+               "buildpack-stack=ubuntu-22",
            ]
+           name     = "dev-me"
+           region   = "sfo"

+           alert {
+               disabled = false
+               rule     = "DEPLOYMENT_FAILED"
            }

+           domain (known after apply)

+           ingress (known after apply)

+           service {
+               dockerfile_path    = "Dockerfile"
+               http_port          = 8080
+               instance_count     = 1
+               instance_size_slug = "apps-s-1vcpu-0.5gb"
+               internal_ports     = (known after apply)
+               name               = "app"
+               run_command        = (known after apply)

+               github {
+                   branch         = "me"
+                   deploy_on_push = true
+                   repo           = "scidsg/hushline"
                }

+               health_check {
+                   http_path = "/health.json"
                }

+               routes (known after apply)
            }
        }
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Changes to Outputs:
+   app_live_url = (known after apply)

✅ Plan applied in Deploy/Destroy Branch Dev Environment #245

Outputs
app_live_url = "https://dev-me-n3eol.ondigitalocean.app"

Copy link
Collaborator

@micahflee micahflee left a comment

Choose a reason for hiding this comment

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

I tested it and it looks great, but I think this should include one small change.

Our extra fields links themselves should include rel="me"! Right now it's rel="noopener noreferrer" but we should add a me to that so that people can e.g. link to their Hush Line profile from Mastodon or other services that use it, and those will be marked as verified links on those services.

And of course, the whole SERVER_NAME thing. I tried to deploy a test server and it broke because of this. So the infra side needs to be fixed first. And the dev deploys in particular could tricky... @jeremywmoore ?

@glenn-sorrentino
Copy link
Member Author

I tested it and it looks great, but I think this should include one small change.

Our extra fields links themselves should include rel="me"! Right now it's rel="noopener noreferrer" but we should add a me to that so that people can e.g. link to their Hush Line profile from Mastodon or other services that use it, and those will be marked as verified links on those services.

And of course, the whole SERVER_NAME thing. I tried to deploy a test server and it broke because of this. So the infra side needs to be fixed first. And the dev deploys in particular could tricky... @jeremywmoore ?

Added in 9d030d3

@jeremywmoore
Copy link
Collaborator

I tested it and it looks great, but I think this should include one small change.

Our extra fields links themselves should include rel="me"! Right now it's rel="noopener noreferrer" but we should add a me to that so that people can e.g. link to their Hush Line profile from Mastodon or other services that use it, and those will be marked as verified links on those services.

And of course, the whole SERVER_NAME thing. I tried to deploy a test server and it broke because of this. So the infra side needs to be fixed first. And the dev deploys in particular could tricky... @jeremywmoore ?

Added in 9d030d3

I'm working on this, DO can inject the domain name into the app via magic envelope var.

@jeremywmoore jeremywmoore added deploy create dev deployment and removed deploy create dev deployment labels Sep 6, 2024
Copy link

github-actions bot commented Sep 6, 2024

🚀 App successfully deployed to https://dev-me-n3eol.ondigitalocean.app!

@micahflee micahflee merged commit 82677d3 into main Sep 6, 2024
9 checks passed
@micahflee micahflee deleted the me branch September 6, 2024 19:57
@github-actions github-actions bot removed the deploy create dev deployment label Sep 6, 2024
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.

3 participants