Skip to content
Permalink
Browse files

add ability to view revoked api keys

  • Loading branch information...
leafo committed Mar 9, 2019
1 parent 28a63af commit 3bacea2ada51af4781cc02678622d6daed3e920b
Showing with 44 additions and 18 deletions.
  1. +5 −1 applications/user.moon
  2. +1 −0 models/users.moon
  3. +1 −0 views/delete_api_key.moon
  4. +37 −17 views/user_settings/api_keys.moon
@@ -252,7 +252,11 @@ class MoonRocksUser extends lapis.Application
before: =>
@user = @current_user
@title = "Api Keys - User Settings"
@api_keys = @user\get_api_keys!
@api_keys = if @params.revoked
@show_revoked = true
@user\get_revoked_api_keys!
else
@user\get_api_keys!

GET: =>
render: true
@@ -45,6 +45,7 @@ class Users extends Model

@relations: {
{"api_keys", has_many: "ApiKeys", where: { revoked: false }}
{"revoked_api_keys", has_many: "ApiKeys", where: { revoked: true }}
{"modules", has_many: "Modules", order: "created_at desc"}
{"github_accounts", has_many: "GithubAccounts", order: "updated_at desc"}
}
@@ -7,6 +7,7 @@ class DeleteApiKey extends require "widgets.page"
pre @key.key

@field_table @key, {
{"comment", label: "Comment"}
{"created_at", label: "Created At"}
{"last_used_at", label: "Last Used"}
}
@@ -7,27 +7,40 @@ class UserSettingsApiKeys extends require "widgets.user_settings_page"
}

settings_content: =>
p ->
text "An API key is used to authenticate the "
code "luarocks upload"
text " command line tool to create and modify modules. Treat it like
a password and don't share it with anyone."
if @show_revoked
p ->
text "Revoked API keys are no longer able to be used. "
a href: @url_for("user_settings.api_keys"), "Return to active API keys"
else
p ->
text "An API key is used to authenticate the "
code "luarocks upload"
text " command line tool to create and modify modules. Treat it like
a password and don't share it with anyone. ("
a href: "?revoked", "View revoked API keys"
text ")"

if #@api_keys == 0
p "You currently don't have any keys."
if @show_revoked
p "You don't have any revoked API keys."
else
p "You currently don't have any keys."
else

@column_table @api_keys, {
{"Comment (enter to save)", (key) ->
form method: "post", class: "form", ->
@csrf_input!
input type: "hidden", name: "api_key", value: key.key
input {
type: "text"
name: "comment"
placeholder: "Optional"
value: key.comment
}
{"Comment#{@show_revoked and "" or " (enter to save)"}", (key) ->
if key.revoked
text key.comment or -> em "n/a"
else
form method: "post", class: "form", ->
@csrf_input!
input type: "hidden", name: "api_key", value: key.key
input {
type: "text"
name: "comment"
placeholder: "no comment"
value: key.comment
}
}
{"Key", (key) ->
details ->
@@ -43,8 +56,15 @@ class UserSettingsApiKeys extends require "widgets.user_settings_page"
}
}
{"created_at", label: "Created at"}
{"last_used_at", label: "Last used"}
{"", (key) ->
a href: @url_for("delete_api_key", :key), "Revoke..."
if key.revoked
strong "Revoked"
if key.revoked_at
text " "
@render_date key.revoked_at
else
a href: @url_for("delete_api_key", :key), "Revoke..."
}
}

0 comments on commit 3bacea2

Please sign in to comment.
You can’t perform that action at this time.