Implement org profile fallback

When an org doesn't have its own profile, but its owner does,
we fallback on that profile.

This allows for "user" orgs, where a user keeps his projects
anchored under an org, but all profile information under the user.
This commit is contained in:
Alexis Sellier
2021-07-21 16:39:58 +02:00
parent 07d2cf48eb
commit 2928e2fe14
8 changed files with 82 additions and 33 deletions
+21
View File
@@ -3,6 +3,7 @@ import type { TransactionResponse } from '@ethersproject/providers';
import type { ContractReceipt } from '@ethersproject/contracts';
import { OperationType } from "@gnosis.pm/safe-core-sdk-types";
import { Profile } from '@app/profile';
import { assert } from '@app/error';
import * as utils from '@app/utils';
import type { Config } from '@app/config';
@@ -141,6 +142,10 @@ export class Org {
return projects;
}
async getProfile(config: Config): Promise<Profile> {
return Org.getProfile(this.address, config);
}
static async getAnchor(orgAddr: string, urn: string, config: Config): Promise<string | null> {
const org = new ethers.Contract(
orgAddr,
@@ -207,6 +212,22 @@ export class Org {
}
}
// Return only org profile if there is one, otherwise tries to get the profile
// of its owner.
static async getProfile(address: string, config: Config): Promise<Profile> {
const profile = await Profile.get(address, config);
if (profile.ens) {
return profile;
}
const org = await Org.get(address, config);
if (org) {
return Profile.get(org.owner, config);
}
return profile;
}
// Return only Orgs that have a specific user as owner
static async getOrgsByOwner(owner: string, config: Config): Promise<Org[]> {
const orgsResult = await utils.querySubgraph(config.orgs.subgraph, GetOrgsByOwner, { owners: [owner] });
+30 -20
View File
@@ -85,6 +85,10 @@
width: 64px;
height: 64px;
}
.title {
display: flex;
align-items: center;
}
.links {
display: flex;
align-items: center;
@@ -127,7 +131,7 @@
{:then org}
{#if org}
<main>
{#await Profile.get(address, config)}
{#await org.getProfile(config)}
<div class="centered">
<Loading center />
</div>
@@ -139,6 +143,9 @@
<div class="info">
<span class="title bold">
{parseEnsLabel(profile.name, config) ?? address}
{#if profile.address === org.owner}
<span class="badge">org</span>
{/if}
</span>
<div class="links">
{#if profile.url}
@@ -176,25 +183,28 @@
{/if}
</div>
<!-- Name -->
<div class="label">Name</div>
<div>
{#if profile.name}
<Link to={`/registrations/${parseEnsLabel(profile.name, config)}`}>{profile.name}</Link>
{:else}
<span class="subtle">Not set</span>
{/if}
</div>
<div>
{#await isAuthorized(org)}
<!-- Loading -->
{:then authorized}
{#if authorized}
<button class="tiny secondary" on:click={setName}>
Set
</button>
<!-- Only show the name if we aren't already using the name of the owner -->
{#if profile.address === org.address}
<div class="label">Name</div>
<div>
{#if profile.name}
<Link to={`/registrations/${parseEnsLabel(profile.name, config)}`}>{profile.name}</Link>
{:else}
<span class="subtle">Not set</span>
{/if}
{/await}
</div>
</div>
<div>
{#await isAuthorized(org)}
<!-- Loading -->
{:then authorized}
{#if authorized}
<button class="tiny secondary" on:click={setName}>
Set
</button>
{/if}
{/await}
</div>
{/if}
</div>
{#await org.getMembers(config)}
@@ -224,7 +234,7 @@
{:then projects}
{#each projects as project}
<div class="project">
<Project {project} org={org.address} {config} seed={profile.seed} />
<Project {project} org={org.address} config={profile.config(config)} />
</div>
{/each}
{:catch err}