Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't show deleted users, they are not helpful. Show all connected ac… #4322

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class UserResult(BaseModel):
id: int
display_name: str | None
default_account: ConnectedAccountResult | None
deleted: bool
connected_accounts: list[ConnectedAccountResult]
accepted_publisher_agreement_at: datetime | None
roles: list[UserRoleResult]
github_repos: list["GithubRepositoryResult"] | None
Expand Down Expand Up @@ -182,6 +182,10 @@ def all(db, page, page_size, filterString: str | None = None) -> FlathubUsersRes
offset = (page - 1) * page_size
query = db.session.query(FlathubUser)

query = query.filter(
FlathubUser.deleted.is_(False),
)

if filterString is not None and len(filterString) > 0:
query = query.filter(
or_(
Expand Down Expand Up @@ -221,7 +225,7 @@ def all(db, page, page_size, filterString: str | None = None) -> FlathubUsersRes
KdeAccount.email.ilike(f"%{filterString}%"),
)
),
)
),
)

users = query.order_by(FlathubUser.id).offset(offset).limit(page_size).all()
Expand Down Expand Up @@ -275,9 +279,11 @@ def to_result(self, db, owned_apps=None, get_github_repos=False) -> UserResult:
return UserResult(
id=self.id,
display_name=self.display_name,
deleted=self.deleted,
accepted_publisher_agreement_at=self.accepted_publisher_agreement_at,
default_account=default_account_result,
connected_accounts=[
account.to_result() for account in self.connected_accounts(db)
],
github_repos=[repo.to_result() for repo in github_repos],
owned_apps=(
None if owned_apps is None else [app.to_result() for app in owned_apps]
Expand Down
78 changes: 46 additions & 32 deletions frontend/pages/admin/users/[user].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
ConnectedAccountProvider,
Permission,
UserInfo,
UserResultConnectedAccountsItem,
UserResultDefaultAccount,
useUserUsersUserIdGet,
} from "src/codegen"
import Breadcrumbs from "src/components/Breadcrumbs"
Expand Down Expand Up @@ -100,38 +102,23 @@ export default function UserAdmin({ userId }) {
<div className="space-y-4">
<h2 className="text-2xl font-extrabold">Default Account</h2>
<div className="grid grid-cols-1 gap-4 md:grid-cols-3 lg:grid-cols-4">
<Card>
<CardHeader>
<CardTitle>
{" "}
<ProviderProfileLink
{...query.data.data.default_account}
/>
</CardTitle>
</CardHeader>
<CardContent className="space-y-2">
<div>
Email: {query.data.data.default_account.email}
</div>
<div>
Display Name:{" "}
{query.data.data.default_account.display_name}
</div>
<div>
Last Used:{" "}
{format(
query.data.data.default_account.last_used,
"PP",
)}{" "}
(
{formatDistanceToNow(
query.data.data.default_account.last_used,
{ addSuffix: true },
)}
)
</div>
</CardContent>
</Card>
<AccountCard account={query.data.data.default_account} />
</div>
</div>
)}

{query.data.data.connected_accounts && (
<div className="space-y-4">
<h2 className="text-2xl font-extrabold">
Connected Accounts
</h2>
<div className="grid grid-cols-1 gap-4 md:grid-cols-3 lg:grid-cols-4">
{query.data.data.connected_accounts.map((account) => (
<AccountCard
key={`${account.id}-${account.provider}`}
account={account}
/>
))}
</div>
</div>
)}
Expand Down Expand Up @@ -213,3 +200,30 @@ export const getStaticPaths: GetStaticPaths = async () => {
fallback: "blocking",
}
}

const AccountCard = ({
account,
}: {
account: UserResultDefaultAccount | UserResultConnectedAccountsItem
}) => {
return (
<Card>
<CardHeader>
<CardTitle>
<ProviderProfileLink {...account} />
</CardTitle>
</CardHeader>
<CardContent className="space-y-2">
<div>Email: {account.email}</div>
<div>Display Name: {account.display_name}</div>
<div>
Last Used: {format(account.last_used, "PP")} (
{formatDistanceToNow(account.last_used, {
addSuffix: true,
})}
)
</div>
</CardContent>
</Card>
)
}
11 changes: 0 additions & 11 deletions frontend/pages/admin/users/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,6 @@ const UserTable = ({ data }: { data: FlathubUsersResult }) => {
return format(row.default_account.last_used, "PP")
},
},
{
id: "deleted",
header: "Deleted",
cell: ({ row }) => {
return (
row.original.deleted && (
<HiExclamationTriangle className="w-6 h-6 text-flathub-electric-red" />
)
)
},
},
]

const table = useReactTable<UserResult>({
Expand Down
1 change: 1 addition & 0 deletions frontend/src/codegen/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export * from "./userInfoDisplayname"
export * from "./userOwnedAppResult"
export * from "./userResult"
export * from "./userResultAcceptedPublisherAgreementAt"
export * from "./userResultConnectedAccountsItem"
export * from "./userResultDefaultAccount"
export * from "./userResultDisplayName"
export * from "./userResultGithubRepos"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/codegen/model/userResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* OpenAPI spec version: 0.1.0
*/
import type { UserResultAcceptedPublisherAgreementAt } from "./userResultAcceptedPublisherAgreementAt"
import type { UserResultConnectedAccountsItem } from "./userResultConnectedAccountsItem"
import type { UserResultDefaultAccount } from "./userResultDefaultAccount"
import type { UserResultDisplayName } from "./userResultDisplayName"
import type { UserResultGithubRepos } from "./userResultGithubRepos"
Expand All @@ -13,8 +14,8 @@ import type { UserRoleResult } from "./userRoleResult"

export interface UserResult {
accepted_publisher_agreement_at: UserResultAcceptedPublisherAgreementAt
connected_accounts: UserResultConnectedAccountsItem[]
default_account: UserResultDefaultAccount
deleted: boolean
display_name: UserResultDisplayName
github_repos: UserResultGithubRepos
id: number
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/codegen/model/userResultConnectedAccountsItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Generated by orval 🍺
* Do not edit manually.
* Flathub API
* OpenAPI spec version: 0.1.0
*/
import type { GithubAccountResult } from "./githubAccountResult"
import type { GitlabAccountResult } from "./gitlabAccountResult"
import type { GnomeAccountResult } from "./gnomeAccountResult"
import type { GoogleAccountResult } from "./googleAccountResult"
import type { KdeAccountResult } from "./kdeAccountResult"

export type UserResultConnectedAccountsItem =
| GithubAccountResult
| GitlabAccountResult
| GnomeAccountResult
| GoogleAccountResult
| KdeAccountResult
Loading