Skip to content

Commit b202335

Browse files
authored
Merge pull request #484 from GSA/nmb/5562-org-aliases
Add aliases field to Organization
2 parents 1e09589 + f63bb18 commit b202335

File tree

6 files changed

+70
-15
lines changed

6 files changed

+70
-15
lines changed

app/forms.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ class OrganizationForm(FlaskForm):
114114
validators=[Optional()],
115115
default="",
116116
)
117+
aliases = StringField(
118+
"Organization aliases (comma-separated)",
119+
validators=[Optional()],
120+
default="",
121+
)
117122

118123
def __init__(self, *args, **kwargs):
119124
self.organization_id = kwargs.pop("organization_id", None)

app/routes.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,13 @@ def remove_user(email):
306306
default="https://github.com/GSA/datagov-harvester/refs/heads/main/app/static/assets/img/placeholder-organization.png",
307307
help="Org Logo",
308308
)
309+
@click.option(
310+
"--aliases",
311+
default="",
312+
help="Comma-separated list of organization aliases",
313+
)
309314
@click.option("--id", help="Org ID: should correspond to CKAN ORG ID")
310-
def cli_add_org(name, slug, logo, id):
315+
def cli_add_org(name, slug, logo, id, aliases):
311316
# let the web UI handle the validation, mostly for slug uniqueness
312317
form_data = MultiDict(
313318
{
@@ -316,6 +321,7 @@ def cli_add_org(name, slug, logo, id):
316321
"logo": logo,
317322
"description": "",
318323
"organization_type": "",
324+
"aliases": aliases,
319325
}
320326
)
321327

@@ -327,13 +333,7 @@ def cli_add_org(name, slug, logo, id):
327333
click.echo(f" - {field}: {error}")
328334
return
329335

330-
org_contract = {
331-
"name": form.name.data,
332-
"slug": form.slug.data or None,
333-
"logo": form.logo.data,
334-
"description": form.description.data or None,
335-
"organization_type": form.organization_type.data or None,
336-
}
336+
org_contract = make_new_org_contract(form)
337337
if id:
338338
org_contract["id"] = id
339339

@@ -480,6 +480,7 @@ def make_new_org_contract(form):
480480
"logo": form.logo.data,
481481
"description": form.description.data or None,
482482
"organization_type": form.organization_type.data or None,
483+
"aliases": [alias.strip() for alias in (form.aliases.data or "").split(",")],
483484
}
484485

485486

@@ -505,13 +506,7 @@ def add_organization():
505506
else:
506507
form = OrganizationForm(db_interface=db)
507508
if form.validate_on_submit():
508-
new_org = {
509-
"name": form.name.data,
510-
"slug": form.slug.data,
511-
"logo": form.logo.data,
512-
"description": form.description.data or None,
513-
"organization_type": form.organization_type.data or None,
514-
}
509+
new_org = make_new_org_contract(form)
515510
org = db.add_organization(new_org)
516511
if org:
517512
flash(f"Added new organization with ID: {org.id}")

database/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Organization(db.Model):
4545
create_constraint=True,
4646
)
4747
)
48+
aliases = db.Column(db.ARRAY(db.String))
4849
sources = db.relationship(
4950
"HarvestSource",
5051
backref=backref("org", lazy="joined"),
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Add organization aliases
2+
3+
Revision ID: 1c80316df048
4+
Revises: c69d6790efff
5+
Create Date: 2025-11-14 19:13:05.929225
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
from sqlalchemy.dialects import postgresql
12+
13+
# revision identifiers, used by Alembic.
14+
revision = "1c80316df048"
15+
down_revision = "c69d6790efff"
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
with op.batch_alter_table("organization", schema=None) as batch_op:
23+
batch_op.add_column(sa.Column("aliases", sa.ARRAY(sa.String()), nullable=True))
24+
25+
# ### end Alembic commands ###
26+
27+
28+
def downgrade():
29+
# ### commands auto generated by Alembic - please adjust! ###
30+
with op.batch_alter_table("organization", schema=None) as batch_op:
31+
batch_op.drop_column("aliases")
32+
# ### end Alembic commands ###

tests/integration/app/test_forms.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@ def test_add_organization_strips_string_fields(self, app, client, interface):
2121
assert org.description == "A sample description"
2222
assert org.slug == "test-slug"
2323

24+
def test_add_organization_aliases(self, app, client, interface):
25+
app.config.update({"WTF_CSRF_ENABLED": False})
26+
with client.session_transaction() as sess:
27+
sess["user"] = "[email protected]"
28+
29+
data = {
30+
"name": "Test Org",
31+
"logo": "https://example.com/logo.png ",
32+
"description": "description ",
33+
"slug": "test",
34+
"aliases": "first, second",
35+
}
36+
res = client.post("/organization/add", data=data)
37+
38+
assert res.status_code == 302
39+
orgs = interface.get_all_organizations()
40+
org = orgs[0]
41+
assert len(org.aliases) == 2
42+
assert not org.aliases[-1].startswith(" ")
43+
2444
def test_add_organization_duplicate_slug_validation(self, app, client, interface):
2545
app.config.update({"WTF_CSRF_ENABLED": False})
2646
with client.session_transaction() as sess:

tests/playwright/test_organization.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def test_config_table_properties(self, upage):
3030
"fixture-org",
3131
"organization_type:",
3232
"Federal Government",
33+
"aliases:",
34+
"None",
3335
"id:",
3436
"d925f84d-955b-4cb7-812f-dcfd6681a18f",
3537
]

0 commit comments

Comments
 (0)