Skip to content

Commit fbbc857

Browse files
authored
Merge pull request #7852 from Turbo87/admin-yanking
Introduce `users.is_admin` column and allow admins to yank/unyank versions
2 parents c9f37d1 + 7d76174 commit fbbc857

File tree

17 files changed

+153
-22
lines changed

17 files changed

+153
-22
lines changed

app/components/version-list/row.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
{{/if}}
108108
</div>
109109

110-
{{#if this.isOwner}}
110+
{{#if this.canYank}}
111111
<YankButton @version={{@version}} local-class="yank-button" />
112112
{{/if}}
113113
</div>

app/components/version-list/row.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export default class VersionRow extends Component {
5151
return this.args.version.crate?.owner_user?.findBy('id', this.session.currentUser?.id);
5252
}
5353

54+
get canYank() {
55+
return this.isOwner || this.session.currentUser?.is_admin;
56+
}
57+
5458
@action setFocused(value) {
5559
this.focused = value;
5660
}

app/models/user.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default class User extends Model {
1111
@attr email_verified;
1212
@attr email_verification_sent;
1313
@attr name;
14+
@attr is_admin;
1415
@attr login;
1516
@attr avatar;
1617
@attr url;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE users DROP COLUMN is_admin;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE users ADD COLUMN is_admin BOOL DEFAULT false NOT NULL;

mirage/factories/user.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default Factory.extend({
2121

2222
emailVerified: null,
2323
emailVerificationToken: null,
24+
isAdmin: false,
2425

2526
afterCreate(model) {
2627
if (model.emailVerified === null) {

mirage/serializers/user.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default BaseSerializer.extend({
2323
if (removePrivateData) {
2424
delete hash.email;
2525
delete hash.email_verified;
26+
delete hash.is_admin;
2627
} else {
2728
hash.email_verification_sent = hash.email_verified || Boolean(hash.email_verification_token);
2829
}

src/controllers/version/yank.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ fn modify_yank(
7070
let owners = krate.owners(conn)?;
7171

7272
if Handle::current().block_on(user.rights(state, &owners))? < Rights::Publish {
73-
return Err(cargo_err("must already be an owner to yank or unyank"));
73+
if user.is_admin {
74+
let action = if yanked { "yanking" } else { "unyanking" };
75+
warn!("Admin {} is {action} crate {}", user.gh_login, krate.name);
76+
} else {
77+
return Err(cargo_err("must already be an owner to yank or unyank"));
78+
}
7479
}
7580

7681
if version.yanked == yanked {

src/models/user.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct User {
2222
pub gh_id: i32,
2323
pub account_lock_reason: Option<String>,
2424
pub account_lock_until: Option<NaiveDateTime>,
25+
pub is_admin: bool,
2526
}
2627

2728
/// Represents a new user record insertable to the `users` table

src/schema.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,12 @@ diesel::table! {
807807
///
808808
/// (Automatically generated by Diesel.)
809809
account_lock_until -> Nullable<Timestamp>,
810+
/// The `is_admin` column of the `users` table.
811+
///
812+
/// Its SQL type is `Bool`.
813+
///
814+
/// (Automatically generated by Diesel.)
815+
is_admin -> Bool,
810816
}
811817
}
812818

0 commit comments

Comments
 (0)