-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
for MPP-3817: prevent all Relay operations when user.is_active = False
- Loading branch information
Showing
16 changed files
with
321 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@import "~@mozilla-protocol/core/protocol/css/includes/lib"; | ||
|
||
.error { | ||
background-color: $color-red-60; | ||
color: $color-white; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { NextPage } from "next"; | ||
|
||
import { Layout } from "../../components/layout/Layout"; | ||
import { useL10n } from "../../hooks/l10n"; | ||
import styles from "./account_inactive.module.scss"; | ||
|
||
const AccountInactive: NextPage = () => { | ||
const l10n = useL10n(); | ||
return ( | ||
<Layout> | ||
<div className={styles["error"]}> | ||
{l10n.getString("api-error-account-is-inactive")} | ||
</div> | ||
</Layout> | ||
); | ||
}; | ||
|
||
export default AccountInactive; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from argparse import ArgumentParser | ||
from typing import Any | ||
|
||
from django.contrib.auth.models import User | ||
from django.core.management.base import BaseCommand | ||
|
||
from allauth.socialaccount.models import SocialAccount | ||
|
||
from emails.models import Profile | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Deactivates a user to effectively block all usage of Relay." | ||
|
||
def add_arguments(self, parser: ArgumentParser) -> None: | ||
parser.add_argument("--key", type=str, help="User API key") | ||
parser.add_argument("--email", type=str, help="User email address") | ||
parser.add_argument("--uid", type=str, help="User FXA UID") | ||
|
||
def handle(self, *args: Any, **options: Any) -> str: | ||
api_key: str | None = options.get("key") | ||
email: str | None = options.get("email") | ||
uid: str | None = options.get("uid") | ||
|
||
user: User | ||
|
||
if api_key: | ||
try: | ||
profile = Profile.objects.get(api_token=api_key) | ||
user = profile.user | ||
user.is_active = False | ||
user.save() | ||
msg = f"SUCCESS: deactivated user with api_token: {api_key}" | ||
except Profile.DoesNotExist: | ||
msg = "ERROR: Could not find user with that API key." | ||
self.stderr.write(msg) | ||
return msg | ||
|
||
if email: | ||
try: | ||
user = User.objects.get(email=email) | ||
user.is_active = False | ||
user.save() | ||
msg = f"SUCCESS: deactivated user with email: {email}" | ||
except User.DoesNotExist: | ||
msg = "ERROR: Could not find user with that email address." | ||
self.stderr.write(msg) | ||
return msg | ||
|
||
if uid: | ||
try: | ||
user = SocialAccount.objects.get(uid=uid).user | ||
user.is_active = False | ||
user.save() | ||
msg = f"SUCCESS: deactivated user with FXA UID: {uid}" | ||
except SocialAccount.DoesNotExist: | ||
msg = "ERROR: Could not find user with that FXA UID." | ||
self.stderr.write(msg) | ||
return msg | ||
return msg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.