Added api admin.

This commit is contained in:
Martin Edenhofer 2016-08-16 10:19:06 +02:00
parent 730c900ee5
commit ffdc782e18
3 changed files with 208 additions and 0 deletions

View file

@ -0,0 +1,112 @@
class Index extends App.ControllerContent
requiredPermission: 'admin.api'
events:
'click .action': 'action'
'change .js-TokenAccess input': 'toggleTokenAccess'
'change .js-PasswordAccess input': 'togglePasswordAccess'
'click .js-appNew': 'appNew'
elements:
'.js-TokenAccess input': 'TokenAccess'
'.js-PasswordAccess input': 'PasswordAccess'
constructor: ->
super
@title 'API', true
App.Setting.fetchFull(
@render
force: false
)
render: =>
# serach area settings
settings = App.Setting.search(
filter:
area: 'API::Base'
)
@html App.view('api')(
settings: settings
)
if @subscribeApplicationId
App.Setting.unsubscribe(@subscribeApplicationId)
table = =>
new App.ControllerTable(
el: @$('.js-appList')
model: App.Application
table_id: 'applications'
objects: App.Application.all()
bindRow:
events:
'click': @appEdit
)
table()
#App.Application.fetchFull(
# table
# clear: true
#)
@subscribeApplicationId = App.Application.subscribe(table, initFetch: true, clear: true)
release: =>
super
if @subscribeApplicationId
App.Application.unsubscribe(@subscribeApplicationId)
action: (e) ->
e.preventDefault()
id = $(e.target).parents('[data-id]').data('id')
type = $(e.target).data('type')
if type is 'uninstall'
httpType = 'DELETE'
if httpType
@ajax(
id: 'packages'
type: httpType
url: "#{@apiPath}/packages",
data: JSON.stringify(id: id)
processData: false
success: =>
@load()
)
toggleTokenAccess: =>
value = @TokenAccess.prop('checked')
App.Setting.set('api_token_access', value)
togglePasswordAccess: =>
value = @PasswordAccess.prop('checked')
App.Setting.set('api_password_access', value)
appNew: (e) ->
e.preventDefault()
new App.ControllerGenericNew(
pageData:
object: 'Application'
genericObject: 'Application'
callback: =>
@render()
container: @el.closest('.content')
)
appEdit: (id, e) =>
e.preventDefault()
item = App.Application.find(id)
new App.ControllerGenericEdit(
id: item.id
pageData:
object: 'Application'
genericObject: 'Application'
callback: =>
@render()
container: @el.closest('.content')
)
App.Config.set('API', { prio: 1200, name: 'API', parent: '#system', target: '#system/api', controller: Index, permission: ['admin.api'] }, 'NavBarAdmin')

View file

@ -0,0 +1,17 @@
class App.Application extends App.Model
@configure 'Application', 'name', 'scopes', 'redirect_uri'
@extend Spine.Model.Ajax
@url: @apiPath + '/applications'
@configure_attributes = [
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false },
{ name: 'redirect_uri', display: 'Redirect URI', tag: 'textarea', limit: 250, null: false, note: 'Use one line per URI' },
{ name: 'scopes', display: 'Scopes', tag: 'input', note: 'Scopes define the access for' },
{ name: 'clients', display: 'Clients', tag: 'input', readonly: 1 },
{ name: 'created_at', display: 'Created', tag: 'datetime', readonly: 1 },
{ name: 'updated_at', display: 'Updated', tag: 'datetime', readonly: 1 },
]
@configure_overview = [
'name', 'scopes', 'clients'
]
@configure_delete = true

View file

@ -0,0 +1,79 @@
<div class="page-header-title">
<h1><%- @T('API') %> <small><%- @T('Management') %></small></h1>
</div>
<div class="page-content">
<div class="page-header-title">
<div class="zammad-switch zammad-switch--small js-TokenAccess">
<input name="api_token_access" type="checkbox" id="api_token_access" <% if App.Setting.get('api_token_access'): %>checked<% end %>>
<label for="api_token_access"></label>
</div>
<h2><%- @T('Token Access') %> (HTTP Token Authentication)</h2>
</div>
<p><%- @T('Enable REST API using tokens (not username/email addeess and password). Each user need to create own access tokens in user profile.') %></p>
<p><%- @T('Example') %>:</p>
<code>
curl -H "Authorization: Token token=YOUR_TOKEN" <%= @C('http_type') %>://<%= @C('fqdn') %>/api/v1/groups
</code>
<hr>
<div class="page-header-title">
<div class="zammad-switch zammad-switch--small js-PasswordAccess">
<input name="api_password_access" type="checkbox" id="api_password_access" <% if App.Setting.get('api_password_access'): %>checked<% end %>>
<label for="api_password_access"></label>
</div>
<h2><%- @T('Password Access') %> (HTTP Basic Authentication)</h2>
</div>
<p><%- @T('Enable REST API access using the username/email address and password for the authentication user.') %></p>
<p><%- @T('Example') %>:</p>
<code>
curl -u <%= @S('email') %>:some_password <%= @C('http_type') %>://<%= @C('fqdn') %>/api/v1/groups
</code>
<hr>
<div class="page-header-title">
<h2><%- @T('Applications') %> (OAuth Authentication)</h2>
&nbsp;
</div>
<p><%- @T('Manage applications that can use Zammad as an OAuth provider and applications that you\'ve authorized to use your account.') %></p>
<div class="js-appList"></div>
<button class="btn js-appNew"><%- @T('New Application') %></button>
<br>
<div>
OAuth URLs are:
<table class="settings-list" style="width: 100%;">
<thead>
<tr>
<th width="40%"><%- @T('Title') %>
<th width="60%"><%- @T('URL') %>
</thead>
<tbody>
<tr>
<td><%- @T('Requesting the Grant') %>
<td><%= @C('http_type') %>://<%= @C('fqdn') %>/oauth/authorize
<tr>
<td><%- @T('Getting an Access Token') %>
<td><%= @C('http_type') %>://<%= @C('fqdn') %>/oauth/token
<tr>
<td><%- @T('Revoking Access') %>
<td><%= @C('http_type') %>://<%= @C('fqdn') %>/oauth/applications
</tbody>
</table>
</div>
</div>