2021-04-03 17:26:43 +00:00
import { t } from "@lingui/macro" ;
2021-02-09 16:04:55 +00:00
import { customElement , html , property , TemplateResult } from "lit-element" ;
import { AKResponse } from "../../api/Client" ;
2021-02-09 09:22:49 +00:00
import { TableColumn } from "../../elements/table/Table" ;
import { TablePage } from "../../elements/table/TablePage" ;
2021-02-09 16:04:55 +00:00
import "../../elements/buttons/SpinnerButton" ;
2021-02-10 19:12:15 +00:00
import "../../elements/buttons/Dropdown" ;
2021-03-18 11:14:27 +00:00
import "../../elements/forms/DeleteForm" ;
2021-04-02 10:12:14 +00:00
import "../../elements/forms/ModalForm" ;
import "../../elements/forms/ProxyForm" ;
2021-02-10 19:12:15 +00:00
import { until } from "lit-html/directives/until" ;
2021-03-02 14:12:26 +00:00
import { PAGE_SIZE } from "../../constants" ;
2021-03-16 20:32:39 +00:00
import { Source , SourcesApi } from "authentik-api" ;
2021-03-08 10:14:00 +00:00
import { DEFAULT_CONFIG } from "../../api/Config" ;
2021-04-02 10:12:14 +00:00
import { ifDefined } from "lit-html/directives/if-defined" ;
import "./ldap/LDAPSourceForm" ;
2021-04-02 11:12:31 +00:00
import "./saml/SAMLSourceForm" ;
2021-04-02 13:15:19 +00:00
import "./oauth/OAuthSourceForm" ;
2021-02-09 16:04:55 +00:00
2021-02-09 09:22:49 +00:00
@customElement ( "ak-source-list" )
export class SourceListPage extends TablePage < Source > {
pageTitle ( ) : string {
2021-04-03 22:10:56 +00:00
return t ` Sources ` ;
2021-02-09 09:22:49 +00:00
}
pageDescription ( ) : string | undefined {
2021-04-03 22:10:56 +00:00
return t ` External Sources which can be used to get Identities into authentik, for example Social Providers like Twiter and GitHub or Enterprise Providers like ADFS and LDAP. ` ;
2021-02-09 09:22:49 +00:00
}
pageIcon ( ) : string {
return "pf-icon pf-icon-middleware" ;
}
searchEnabled ( ) : boolean {
return true ;
}
@property ( )
order = "name" ;
2021-02-09 16:04:55 +00:00
apiEndpoint ( page : number ) : Promise < AKResponse < Source > > {
2021-03-08 10:14:00 +00:00
return new SourcesApi ( DEFAULT_CONFIG ) . sourcesAllList ( {
2021-02-09 09:22:49 +00:00
ordering : this.order ,
page : page ,
2021-03-08 10:14:00 +00:00
pageSize : PAGE_SIZE ,
2021-02-09 09:22:49 +00:00
search : this.search || "" ,
} ) ;
}
columns ( ) : TableColumn [ ] {
return [
2021-04-04 14:56:16 +00:00
new TableColumn ( t ` Name ` , "name" ) ,
new TableColumn ( t ` Type ` ) ,
2021-02-09 09:22:49 +00:00
new TableColumn ( "" ) ,
] ;
}
2021-04-08 20:25:57 +00:00
renderRowsAbove ( ) : TemplateResult {
return html ` <tbody role="rowgroup">
< tr role = "row" >
< td role = "cell" >
< span >
< div > $ { t ` authentik Built-in ` } < / div >
< small > $ { t ` Built-in ` } < / small >
< / span >
< / td >
< td role = "cell" > - < / td >
< td role = "cell" >
< / td >
< / tr >
< / tbody > ` ;
}
2021-02-09 09:22:49 +00:00
row ( item : Source ) : TemplateResult [ ] {
return [
2021-02-19 18:29:17 +00:00
html ` <a href="#/core/sources/ ${ item . slug } ">
2021-02-09 09:22:49 +00:00
< div > $ { item . name } < / div >
2021-04-03 17:26:43 +00:00
$ { item . enabled ? html ` ` : html ` <small> ${ t ` Disabled ` } </small> ` }
2021-02-09 09:22:49 +00:00
< / a > ` ,
2021-03-08 10:14:00 +00:00
html ` ${ item . verboseName } ` ,
2021-02-09 09:22:49 +00:00
html `
2021-04-02 10:12:14 +00:00
< ak - forms - modal >
< span slot = "submit" >
2021-04-03 17:26:43 +00:00
$ { t ` Update ` }
2021-04-02 10:12:14 +00:00
< / span >
< span slot = "header" >
2021-04-03 17:26:43 +00:00
$ { t ` Update ${ item . verboseName } ` }
2021-04-02 10:12:14 +00:00
< / span >
< ak - proxy - form
slot = "form"
. args = $ { {
"sourceSlug" : item . slug
} }
2021-04-03 09:32:17 +00:00
type = $ { ifDefined ( item . component ) } >
2021-04-02 10:12:14 +00:00
< / a k - p r o x y - f o r m >
< button slot = "trigger" class = "pf-c-button pf-m-secondary" >
2021-04-03 17:26:43 +00:00
$ { t ` Edit ` }
2021-04-02 10:12:14 +00:00
< / button >
< / a k - f o r m s - m o d a l >
2021-03-18 11:14:27 +00:00
< ak - forms - delete
. obj = $ { item }
2021-04-03 17:26:43 +00:00
objectLabel = $ { t ` Source ` }
2021-03-18 11:14:27 +00:00
. delete = $ { ( ) = > {
return new SourcesApi ( DEFAULT_CONFIG ) . sourcesAllDelete ( {
slug : item.slug || ""
} ) ;
} } >
< button slot = "trigger" class = "pf-c-button pf-m-danger" >
2021-04-03 17:26:43 +00:00
$ { t ` Delete ` }
2021-03-18 11:14:27 +00:00
< / button >
< / a k - f o r m s - d e l e t e > ` ,
2021-02-09 09:22:49 +00:00
] ;
}
2021-02-10 19:12:15 +00:00
renderToolbar ( ) : TemplateResult {
return html `
< ak - dropdown class = "pf-c-dropdown" >
< button class = "pf-m-primary pf-c-dropdown__toggle" type = "button" >
2021-04-03 17:26:43 +00:00
< span class = "pf-c-dropdown__toggle-text" > $ { t ` Create ` } < / span >
2021-02-10 19:12:15 +00:00
< i class = "fas fa-caret-down pf-c-dropdown__toggle-icon" aria - hidden = "true" > < / i >
< / button >
< ul class = "pf-c-dropdown__menu" hidden >
2021-04-02 11:27:18 +00:00
$ { until ( new SourcesApi ( DEFAULT_CONFIG ) . sourcesAllTypes ( ) . then ( ( types ) = > {
2021-02-10 19:12:15 +00:00
return types . map ( ( type ) = > {
return html ` <li>
2021-04-02 11:12:31 +00:00
< ak - forms - modal >
< span slot = "submit" >
2021-04-03 17:26:43 +00:00
$ { t ` Create ` }
2021-04-02 11:12:31 +00:00
< / span >
< span slot = "header" >
2021-04-03 17:26:43 +00:00
$ { t ` Create ${ type . name } ` }
2021-04-02 11:12:31 +00:00
< / span >
< ak - proxy - form
slot = "form"
2021-04-02 21:12:17 +00:00
type = $ { type . component } >
2021-04-02 11:12:31 +00:00
< / a k - p r o x y - f o r m >
< button slot = "trigger" class = "pf-c-dropdown__menu-item" >
$ { type . name } < br >
2021-02-10 19:12:15 +00:00
< small > $ { type . description } < / small >
< / button >
2021-04-02 11:12:31 +00:00
< / a k - f o r m s - m o d a l >
2021-02-10 19:12:15 +00:00
< / li > ` ;
} ) ;
} ) , html ` <ak-spinner></ak-spinner> ` ) }
< / ul >
< / a k - d r o p d o w n >
$ { super . renderToolbar ( ) } ` ;
}
2021-02-09 09:22:49 +00:00
}