-
Notifications
You must be signed in to change notification settings - Fork 66.8k
Expand file tree
/
Copy pathPermissionsList.tsx
More file actions
156 lines (146 loc) · 5.87 KB
/
PermissionsList.tsx
File metadata and controls
156 lines (146 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { useRouter } from 'next/router'
import cx from 'classnames'
import { slug as githubSlug } from 'github-slugger'
import { CheckIcon, XIcon } from '@primer/octicons-react'
import { HeadingLink } from '@/frame/components/article/HeadingLink'
import { useTranslation } from '@/languages/components/useTranslation'
import { Link } from '@/frame/components/Link'
import { MainContextT } from '@/frame/components/context/MainContext'
import {
AutomatedPageContext,
AutomatedPageContextT,
} from '@/automated-pipelines/components/AutomatedPageContext'
import { AutomatedPage } from '@/automated-pipelines/components/AutomatedPage'
import { RestRedirect } from '@/rest/components/RestRedirect'
import styles from '@/github-apps/components/PermissionTable.module.scss'
const IAT_DOCS_REF =
'/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation'
const UAT_DOCS_REF =
'/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-with-a-github-app-on-behalf-of-a-user'
type PermissionOperationsT = {
slug: string
category: string
subcategory: string
verb: string
requestPath: string
access: 'admin' | 'write' | 'read'
'user-to-server': boolean
'server-to-server': boolean
'additional-permissions': []
}
export type PermissionT = {
displayTitle: string
resourceGroup: string
permissions: PermissionOperationsT[]
}
export type PermissionListT = Record<string, PermissionT>
type Props = {
items: PermissionListT
currentVersion: string
categoriesWithoutSubcategories: string[]
mainContext: MainContextT
automatedPageContext: AutomatedPageContextT
tokenTypes?: boolean
}
export function PermissionsList({
items,
currentVersion,
categoriesWithoutSubcategories,
automatedPageContext,
mainContext,
tokenTypes = false,
}: Props) {
const { locale } = useRouter()
const DEFAULT_VERSION = mainContext.nonEnterpriseDefaultVersion
const rootPath =
currentVersion === DEFAULT_VERSION ? `/${locale}` : `/${locale}/${currentVersion}`
// Translated strings
const { t } = useTranslation('rest')
const ENDPOINTS_TH = t('rest.overview.permissions.endpoints')
const ACCESS_TH = t('rest.overview.permissions.access')
const TOKENS_TH = t('rest.overview.permissions.tokens')
const ADDITIONAL_TH = t('rest.overview.permissions.additionalPermissions')
const UAT = t('rest.overview.permissions.uat')
const IAT = t('rest.overview.permissions.iat')
const content = Object.entries(items).map(([permissionName, permissionObject]) => {
const { displayTitle, permissions } = permissionObject
const adminPermissions = permissions.filter((permission) => permission.access === 'admin')
const writePermissions = permissions.filter((permission) => permission.access === 'write')
const readPermissions = permissions.filter((permission) => permission.access === 'read')
const sortedPermissions = [...adminPermissions, ...writePermissions, ...readPermissions]
return (
<div key={permissionName} className={cx(styles.parameterTable)}>
<HeadingLink as="h2" slug={githubSlug(displayTitle)}>
{displayTitle}
</HeadingLink>
<table>
<thead>
<tr>
<th className="text-left">{ENDPOINTS_TH}</th>
<th className="text-center">{ACCESS_TH}</th>
{tokenTypes ? <th className="text-center">{TOKENS_TH}</th> : null}
<th className="text-center">{ADDITIONAL_TH}</th>
</tr>
</thead>
<tbody>
{sortedPermissions.map((operation, index) => {
const { slug, verb, requestPath } = operation
const category = categoriesWithoutSubcategories.includes(operation.category)
? `${operation.category}`
: `${operation.category}/${operation.subcategory}`
const opPath = `${rootPath}/rest/${category}#${slug}`
const iat = operation['server-to-server'] ? (
<span className="label mt-2">
<Link href={`${rootPath}${IAT_DOCS_REF}`}>{IAT}</Link>
</span>
) : null
const uat = operation['user-to-server'] ? (
<span className="label no-underline">
<Link href={`${rootPath}${UAT_DOCS_REF}`}>{UAT}</Link>
</span>
) : null
const permissionsClass = operation['additional-permissions'].length
? ''
: 'text-center'
return (
<tr key={`${permissionName}-${operation.slug}-${index}`}>
<td>
<Link href={`${opPath}`}>
<span>{verb.toUpperCase()}</span> {`${requestPath}`}
</Link>
</td>
<td className="v-align-middle text-center">{operation.access}</td>
{tokenTypes ? (
<td className="v-align-middle text-center">
{uat}
<br />
{iat}
</td>
) : null}
<td className={permissionsClass}>
{operation['additional-permissions'] ? (
<Link href={opPath} title={t('screen_reader_text_checkmark_icon')}>
<CheckIcon aria-hidden="true" />
<span className="visually-hidden">
{t('screen_reader_text_checkmark_icon')}
</span>
</Link>
) : (
<XIcon />
)}
</td>
</tr>
)
})}
</tbody>
</table>
</div>
)
})
return (
<AutomatedPageContext.Provider value={automatedPageContext}>
<RestRedirect />
<AutomatedPage>{content}</AutomatedPage>
</AutomatedPageContext.Provider>
)
}