Skip to content

Commit b2ae37b

Browse files
committed
user_slug
1 parent eedd084 commit b2ae37b

File tree

20 files changed

+74
-65
lines changed

20 files changed

+74
-65
lines changed

lib/bencher_client/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ from_slug!(
253253
BranchSlug,
254254
TestbedSlug,
255255
BenchmarkSlug,
256-
MeasureSlug
256+
MeasureSlug,
257+
UserSlug
257258
);
258259

259260
macro_rules! from_resource_id {

lib/bencher_json/src/system/auth.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
use bencher_valid::{DateTime, Email, Jwt, Slug, UserName};
1+
use bencher_valid::{DateTime, Email, Jwt, UserName};
22
#[cfg(feature = "plus")]
33
use bencher_valid::{PlanLevel, Secret};
44
#[cfg(feature = "schema")]
55
use schemars::JsonSchema;
66
use serde::{Deserialize, Serialize};
77

8-
use crate::{JsonUser, OrganizationUuid};
8+
use crate::{JsonUser, OrganizationUuid, UserSlug};
99

1010
#[typeshare::typeshare]
1111
#[derive(Debug, Clone, Serialize, Deserialize)]
1212
#[cfg_attr(feature = "schema", derive(JsonSchema))]
1313
pub struct JsonSignup {
1414
pub name: UserName,
15-
pub slug: Option<Slug>,
15+
pub slug: Option<UserSlug>,
1616
pub email: Email,
1717
#[cfg(feature = "plus")]
1818
pub plan: Option<PlanLevel>,

lib/bencher_json/src/user/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub mod token;
2-
use bencher_valid::{Email, ResourceId, Slug, UserName};
2+
use bencher_valid::{Email, ResourceId, UserName};
33

44
#[cfg(feature = "schema")]
55
use schemars::JsonSchema;
@@ -24,7 +24,7 @@ crate::from_vec!(JsonUsers[JsonUser]);
2424
pub struct JsonUser {
2525
pub uuid: UserUuid,
2626
pub name: UserName,
27-
pub slug: Slug,
27+
pub slug: UserSlug,
2828
pub email: Email,
2929
pub admin: bool,
3030
pub locked: bool,
@@ -36,7 +36,7 @@ pub struct JsonUser {
3636
pub struct JsonPubUser {
3737
pub uuid: UserUuid,
3838
pub name: UserName,
39-
pub slug: Slug,
39+
pub slug: UserSlug,
4040
}
4141

4242
#[typeshare::typeshare]
@@ -49,7 +49,7 @@ pub struct JsonUpdateUser {
4949
pub name: Option<UserName>,
5050
/// The preferred new slug for the user.
5151
/// Maximum length is 64 characters.
52-
pub slug: Option<Slug>,
52+
pub slug: Option<UserSlug>,
5353
/// The new email for the user.
5454
pub email: Option<Email>,
5555
/// Update whether the user is an admin.

lib/bencher_schema/src/model/organization/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl InsertOrganization {
373373
let slug = ok_slug!(
374374
conn,
375375
&name,
376-
Some(query_user.slug.clone()),
376+
Some(query_user.slug.clone().into()),
377377
organization,
378378
QueryOrganization
379379
);

lib/bencher_schema/src/model/user/mod.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bencher_json::{
2-
DateTime, Email, JsonPubUser, JsonSignup, JsonUpdateUser, JsonUser, Jwt, Sanitize, Slug,
3-
UserName, UserUuid, organization::member::OrganizationRole,
2+
DateTime, Email, JsonPubUser, JsonSignup, JsonUpdateUser, JsonUser, Jwt, Sanitize, UserName,
3+
UserSlug, UserUuid, organization::member::OrganizationRole,
44
};
55
use bencher_token::TokenKey;
66
use diesel::{ExpressionMethods as _, QueryDsl as _, RunQueryDsl as _};
@@ -45,7 +45,7 @@ pub struct QueryUser {
4545
pub id: UserId,
4646
pub uuid: UserUuid,
4747
pub name: UserName,
48-
pub slug: Slug,
48+
pub slug: UserSlug,
4949
pub email: Email,
5050
pub admin: bool,
5151
pub locked: bool,
@@ -174,7 +174,7 @@ impl Sanitize for QueryUser {
174174
pub struct InsertUser {
175175
pub uuid: UserUuid,
176176
pub name: UserName,
177-
pub slug: Slug,
177+
pub slug: UserSlug,
178178
pub email: Email,
179179
pub admin: bool,
180180
pub locked: bool,
@@ -183,13 +183,18 @@ pub struct InsertUser {
183183
}
184184

185185
impl InsertUser {
186-
pub fn new(conn: &mut DbConnection, name: UserName, slug: Option<Slug>, email: Email) -> Self {
187-
let slug = ok_slug!(conn, &name, slug, user, QueryUser);
186+
pub fn new(
187+
conn: &mut DbConnection,
188+
name: UserName,
189+
slug: Option<UserSlug>,
190+
email: Email,
191+
) -> Self {
192+
let slug = ok_slug!(conn, &name, slug.map(Into::into), user, QueryUser);
188193
let timestamp = DateTime::now();
189194
Self {
190195
uuid: UserUuid::new(),
191196
name,
192-
slug,
197+
slug: slug.into(),
193198
email,
194199
admin: false,
195200
locked: false,
@@ -300,7 +305,7 @@ impl InsertUser {
300305
#[diesel(table_name = user_table)]
301306
pub struct UpdateUser {
302307
pub name: Option<UserName>,
303-
pub slug: Option<Slug>,
308+
pub slug: Option<UserSlug>,
304309
pub email: Option<Email>,
305310
pub admin: Option<bool>,
306311
pub locked: Option<bool>,

lib/bencher_valid/src/name_id.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ use crate::ValidError;
1212

1313
#[derive(Debug, Display, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
1414
#[serde(untagged)]
15-
pub enum NameId<U, S, T> {
15+
pub enum NameId<U, S, N> {
1616
Uuid(U),
1717
Slug(S),
18-
Name(T),
18+
Name(N),
1919
}
2020

2121
#[cfg(feature = "schema")]
22-
impl<U, S, T> JsonSchema for NameId<U, S, T>
22+
impl<U, S, N> JsonSchema for NameId<U, S, N>
2323
where
2424
U: JsonSchema,
2525
S: JsonSchema,
26-
T: JsonSchema,
26+
N: JsonSchema,
2727
{
2828
fn schema_name() -> String {
2929
"NameId".to_owned()
@@ -38,15 +38,15 @@ where
3838
// Otherwise, you get a runtime error: `can only flatten structs and maps (got a string)`
3939
// I believe this is a shortcoming of https://github.com/oxidecomputer/progenitor
4040
// For now, we just use the lowest common denominator's schema.
41-
T::json_schema(generator)
41+
N::json_schema(generator)
4242
}
4343
}
4444

45-
impl<U, S, T> FromStr for NameId<U, S, T>
45+
impl<U, S, N> FromStr for NameId<U, S, N>
4646
where
4747
U: FromStr,
4848
S: FromStr,
49-
T: FromStr,
49+
N: FromStr,
5050
{
5151
type Err = ValidError;
5252

@@ -55,19 +55,19 @@ where
5555
Ok(Self::Uuid(uuid))
5656
} else if let Ok(slug) = S::from_str(name_id) {
5757
Ok(Self::Slug(slug))
58-
} else if let Ok(name) = T::from_str(name_id) {
58+
} else if let Ok(name) = N::from_str(name_id) {
5959
Ok(Self::Name(name))
6060
} else {
6161
Err(ValidError::NameId(name_id.to_owned()))
6262
}
6363
}
6464
}
6565

66-
impl<'de, U, S, T> Deserialize<'de> for NameId<U, S, T>
66+
impl<'de, U, S, N> Deserialize<'de> for NameId<U, S, N>
6767
where
6868
U: FromStr,
6969
S: FromStr,
70-
T: FromStr,
70+
N: FromStr,
7171
{
7272
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
7373
where
@@ -79,17 +79,17 @@ where
7979
}
8080
}
8181

82-
struct NameIdVisitor<U, S, T> {
83-
marker: PhantomData<(U, S, T)>,
82+
struct NameIdVisitor<U, S, N> {
83+
marker: PhantomData<(U, S, N)>,
8484
}
8585

86-
impl<U, S, T> Visitor<'_> for NameIdVisitor<U, S, T>
86+
impl<U, S, N> Visitor<'_> for NameIdVisitor<U, S, N>
8787
where
8888
U: FromStr,
8989
S: FromStr,
90-
T: FromStr,
90+
N: FromStr,
9191
{
92-
type Value = NameId<U, S, T>;
92+
type Value = NameId<U, S, N>;
9393

9494
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
9595
formatter.write_str("a valid UUID, slug, or name.")

services/api/openapi.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10630,7 +10630,7 @@
1063010630
"$ref": "#/components/schemas/UserName"
1063110631
},
1063210632
"slug": {
10633-
"$ref": "#/components/schemas/Slug"
10633+
"$ref": "#/components/schemas/UserSlug"
1063410634
},
1063510635
"uuid": {
1063610636
"$ref": "#/components/schemas/UserUuid"
@@ -11480,7 +11480,7 @@
1148011480
"nullable": true,
1148111481
"allOf": [
1148211482
{
11483-
"$ref": "#/components/schemas/Slug"
11483+
"$ref": "#/components/schemas/UserSlug"
1148411484
}
1148511485
]
1148611486
}
@@ -12201,7 +12201,7 @@
1220112201
"description": "The preferred new slug for the user. Maximum length is 64 characters.",
1220212202
"allOf": [
1220312203
{
12204-
"$ref": "#/components/schemas/Slug"
12204+
"$ref": "#/components/schemas/UserSlug"
1220512205
}
1220612206
]
1220712207
}
@@ -12291,7 +12291,7 @@
1229112291
"$ref": "#/components/schemas/UserName"
1229212292
},
1229312293
"slug": {
12294-
"$ref": "#/components/schemas/Slug"
12294+
"$ref": "#/components/schemas/UserSlug"
1229512295
},
1229612296
"uuid": {
1229712297
"$ref": "#/components/schemas/UserUuid"
@@ -12660,6 +12660,9 @@
1266012660
"UserName": {
1266112661
"type": "string"
1266212662
},
12663+
"UserSlug": {
12664+
"$ref": "#/components/schemas/Slug"
12665+
},
1266312666
"UserUuid": {
1266412667
"type": "string",
1266512668
"format": "uuid"

services/cli/src/bencher/sub/organization/organization/create.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bencher_client::types::JsonNewOrganization;
2-
use bencher_json::{ResourceName, Slug};
2+
use bencher_json::{OrganizationSlug, ResourceName};
33

44
use crate::{
55
CliError,
@@ -10,7 +10,7 @@ use crate::{
1010
#[derive(Debug, Clone)]
1111
pub struct Create {
1212
pub name: ResourceName,
13-
pub slug: Option<Slug>,
13+
pub slug: Option<OrganizationSlug>,
1414
pub backend: AuthBackend,
1515
}
1616

services/cli/src/bencher/sub/organization/organization/update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "plus")]
22
use bencher_client::types::JsonOrganizationPatchNull;
33
use bencher_client::types::{JsonOrganizationPatch, JsonUpdateOrganization};
4-
use bencher_json::{OrganizationResourceId, ResourceName, Slug};
4+
use bencher_json::{OrganizationResourceId, OrganizationSlug, ResourceName};
55

66
use crate::{
77
CliError,
@@ -13,7 +13,7 @@ use crate::{
1313
pub struct Update {
1414
pub organization: OrganizationResourceId,
1515
pub name: Option<ResourceName>,
16-
pub slug: Option<Slug>,
16+
pub slug: Option<OrganizationSlug>,
1717
#[cfg(feature = "plus")]
1818
#[cfg_attr(feature = "plus", expect(clippy::option_option))]
1919
pub license: Option<Option<bencher_json::Jwt>>,

services/cli/src/bencher/sub/project/project/create.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bencher_client::types::{JsonNewProject, Visibility};
2-
use bencher_json::{OrganizationResourceId, ResourceName, Slug, Url};
2+
use bencher_json::{OrganizationResourceId, ProjectSlug, ResourceName, Url};
33

44
use crate::{
55
CliError,
@@ -11,7 +11,7 @@ use crate::{
1111
pub struct Create {
1212
pub organization: OrganizationResourceId,
1313
pub name: ResourceName,
14-
pub slug: Option<Slug>,
14+
pub slug: Option<ProjectSlug>,
1515
pub url: Option<Url>,
1616
pub visibility: Visibility,
1717
pub backend: AuthBackend,

0 commit comments

Comments
 (0)