Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-sorrentino committed Nov 10, 2024
1 parent bb1c4ec commit be78ce2
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 6 deletions.
1 change: 1 addition & 0 deletions hushline/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class OrganizationSetting(Model):
BRAND_LOGO = "brand_logo"
BRAND_NAME = "brand_name"
BRAND_PRIMARY_COLOR = "brand_primary_color"
DIRECTORY_INTRO = "directory_intro"

# non-default values
BRAND_LOGO_VALUE = "brand/logo.png"
Expand Down
13 changes: 12 additions & 1 deletion hushline/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
from .db import db
from .email import SMTPConfig, create_smtp_config, send_email
from .forms import ComplexPassword
from .model import AuthenticationLog, InviteCode, Message, SMTPEncryption, User, Username
from .model import (
AuthenticationLog,
InviteCode,
Message,
OrganizationSetting,
SMTPEncryption,
User,
Username,
)

# Logging setup
logging.basicConfig(level=logging.INFO, format="%(asctime)s:%(levelname)s:%(message)s")
Expand Down Expand Up @@ -518,10 +526,13 @@ def logout() -> Response:
@app.route("/directory")
def directory() -> Response | str:
logged_in = "user_id" in session
# Fetch intro text from OrganizationSetting and get the value field
intro_text = OrganizationSetting.fetch_one(OrganizationSetting.DIRECTORY_INTRO).value
return render_template(
"directory.html",
usernames=get_directory_usernames(),
logged_in=logged_in,
intro_text=intro_text,
)

@app.route("/directory/get-session-user.json")
Expand Down
30 changes: 30 additions & 0 deletions hushline/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
UpdateBrandAppNameForm,
UpdateBrandLogoForm,
UpdateBrandPrimaryColorForm,
UpdateDirectoryIntroTextForm,
)


Expand Down Expand Up @@ -235,6 +236,13 @@ async def index() -> str | Response:
flash("🫥 User not found.")
return redirect(url_for("login"))

# Initialize the directory intro text form with existing value
directory_intro_text_value = OrganizationSetting.fetch_one(
OrganizationSetting.DIRECTORY_INTRO
).value if OrganizationSetting.fetch_one(OrganizationSetting.DIRECTORY_INTRO) else ""
update_directory_intro_text_form = UpdateDirectoryIntroTextForm(
directory_intro_text=directory_intro_text_value
)
directory_visibility_form = DirectoryVisibilityForm(
show_in_directory=user.primary_username.show_in_directory
)
Expand Down Expand Up @@ -366,6 +374,7 @@ async def index() -> str | Response:
default_forwarding_enabled=bool(current_app.config.get("NOTIFICATIONS_ADDRESS")),
# Premium-specific data
business_tier_display_price=business_tier_display_price,
update_directory_intro_text_form=update_directory_intro_text_form,
)

@bp.route("/toggle-2fa", methods=["POST"])
Expand Down Expand Up @@ -800,4 +809,25 @@ async def alias(username_id: int) -> Response | str:
profile_form=profile_form,
)

@bp.route("/update-directory-intro", methods=["POST"])
@admin_authentication_required
def update_directory_intro_text() -> Response:
form = UpdateDirectoryIntroTextForm()
if form.validate_on_submit():
intro_text = form.directory_intro_text.data
OrganizationSetting.upsert(
key=OrganizationSetting.DIRECTORY_INTRO, value=intro_text
)
db.session.commit()
flash("✅ Directory introduction text updated successfully.", "success")
else:
flash("❌ Failed to update introduction text. Please check your input.", "error")
# Re-render the form with the current input if validation fails
return render_template(
"settings/index.html",
update_directory_intro_text_form=form,
)

return redirect(url_for("settings.index"))

return bp
7 changes: 7 additions & 0 deletions hushline/settings/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,10 @@ class UpdateBrandLogoForm(FlaskForm):

class DeleteBrandLogoForm(FlaskForm):
submit = SubmitField("Delete Logo", name="submit_logo", widget=Button())


class UpdateDirectoryIntroTextForm(FlaskForm):
directory_intro_text = TextAreaField(
"Directory Introduction Text", validators=[DataRequired()]
)
submit = SubmitField("Update Intro Text")
1 change: 1 addition & 0 deletions hushline/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,7 @@ input[type="file"]::file-selector-button {
padding: 0.725rem 1rem;
margin: 0.5rem 0;
line-height: 1;
width: fit-content;
}

input[type="file"]::file-selector-button {
Expand Down
10 changes: 5 additions & 5 deletions hushline/templates/directory.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
content %}
<h2>User Directory</h2>
{% if directory_verified_tab_enabled %} {% if not logged_in %}
{% if intro_text %}
<p class="helper section-intro">{{ intro_text }}</p>
{% else %}
<p class="helper section-intro">
👋
<a href="https://hushline.app" target="_blank">Hush Line</a>
connects whistleblowers with lawyers, journalists, business leaders, and more.
We advise speaking to a legal professional before taking any confidential
information from your workplace.
👋 <a href="https://hushline.app" target="_blank">Hush Line</a> connects whistleblowers with lawyers, journalists, business leaders, and more. We advise speaking to a legal professional before taking any confidential information from your workplace.
</p>
{% endif %}
{% endif %}
<div class="directory-tabs">
<ul class="tab-list" role="tablist">
<li role="presentation">
Expand Down
12 changes: 12 additions & 0 deletions hushline/templates/settings/branding.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ <h3>App Name</h3>
<button type="submit" class="btn">Update Name</button>
</form>

<h3>Directory Introduction Text</h3>
<form
method="POST"
action="{{ url_for('settings.update_directory_intro_text') }}"
class="formBody"
>
{{ update_directory_intro_text_form.hidden_tag() }}
<label for="directory-intro-text">Introduction Text</label>
{{ update_directory_intro_text_form.directory_intro_text(rows=3, id="directory-intro-text") }}
{{ update_directory_intro_text_form.submit(class="btn") }}
</form>

{% if user.is_admin %}
<h3>Logo</h3>
<form
Expand Down

0 comments on commit be78ce2

Please sign in to comment.