* Introduce isViewer field * Update policies * Make users read-only feature * Remove not demoting current user validation * Update tests * Catch the unhandled promise rejection * Hide unnecessary ui elements for read-only user * Update app/scenes/Settings/People.js Co-authored-by: Tom Moor <tom.moor@gmail.com> * Remove redundant logic for admin only policies * Use can logic * Update snapshot * Remove lint error * Update snapshot * Minor fix * Update app/menus/UserMenu.js Co-authored-by: Tom Moor <tom.moor@gmail.com> * Update server/api/users.js Co-authored-by: Tom Moor <tom.moor@gmail.com> * Update app/components/DocumentListItem.js Co-authored-by: Tom Moor <tom.moor@gmail.com> * Update app/stores/UsersStore.js Co-authored-by: Tom Moor <tom.moor@gmail.com> * Use useCurrentTeam hook in functional component * Update translation * Update ternary * Remove punctuation * Move the functions to User model * Update share policy and shareMenu * Rename makeAdmin to promote * Create updateCounts function and Rank enum * Update tests * Remove enum * Use async await, remove enum and create computed accessor * Remove unused variable * Fix lint issues * Hide templates * Create shared/types and use rank type from it * Delete shared/utils/rank type file Co-authored-by: Tom Moor <tom.moor@gmail.com>
92 lines
2.3 KiB
JavaScript
92 lines
2.3 KiB
JavaScript
// @flow
|
|
import { observable } from "mobx";
|
|
import { observer, inject } from "mobx-react";
|
|
import * as React from "react";
|
|
import ApiKeysStore from "stores/ApiKeysStore";
|
|
import UiStore from "stores/UiStore";
|
|
|
|
import Button from "components/Button";
|
|
import CenteredContent from "components/CenteredContent";
|
|
import HelpText from "components/HelpText";
|
|
import Input from "components/Input";
|
|
import List from "components/List";
|
|
import PageTitle from "components/PageTitle";
|
|
import TokenListItem from "./components/TokenListItem";
|
|
|
|
type Props = {
|
|
apiKeys: ApiKeysStore,
|
|
ui: UiStore,
|
|
};
|
|
|
|
@observer
|
|
class Tokens extends React.Component<Props> {
|
|
@observable name: string = "";
|
|
|
|
componentDidMount() {
|
|
this.props.apiKeys.fetchPage({ limit: 100 });
|
|
}
|
|
|
|
handleUpdate = (ev: SyntheticInputEvent<*>) => {
|
|
this.name = ev.target.value;
|
|
};
|
|
|
|
handleSubmit = async (ev: SyntheticEvent<>) => {
|
|
try {
|
|
ev.preventDefault();
|
|
await this.props.apiKeys.create({ name: this.name });
|
|
this.name = "";
|
|
} catch (error) {
|
|
this.props.ui.showToast(error.message, { type: "error" });
|
|
}
|
|
};
|
|
|
|
render() {
|
|
const { apiKeys } = this.props;
|
|
const hasApiKeys = apiKeys.orderedData.length > 0;
|
|
|
|
return (
|
|
<CenteredContent>
|
|
<PageTitle title="API Tokens" />
|
|
<h1>API Tokens</h1>
|
|
|
|
<HelpText>
|
|
You can create an unlimited amount of personal tokens to authenticate
|
|
with the API. For more details about the API take a look at the{" "}
|
|
<a href="https://www.getoutline.com/developers">
|
|
developer documentation
|
|
</a>
|
|
.
|
|
</HelpText>
|
|
|
|
{hasApiKeys && (
|
|
<List>
|
|
{apiKeys.orderedData.map((token) => (
|
|
<TokenListItem
|
|
key={token.id}
|
|
token={token}
|
|
onDelete={token.delete}
|
|
/>
|
|
))}
|
|
</List>
|
|
)}
|
|
|
|
<form onSubmit={this.handleSubmit}>
|
|
<Input
|
|
onChange={this.handleUpdate}
|
|
placeholder="Token label (eg. development)"
|
|
value={this.name}
|
|
required
|
|
/>
|
|
<Button
|
|
type="submit"
|
|
value="Create Token"
|
|
disabled={apiKeys.isSaving}
|
|
/>
|
|
</form>
|
|
</CenteredContent>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default inject("apiKeys", "ui")(Tokens);
|