# HG changeset patch # User bsw # Date 1334485979 -7200 # Node ID 976d493106a121ce16569e1c81c46c50f021b44a # Parent dbfde3c567903eb06d3b9d94deea3e42848c0338 Updated member api key settings to core 2.0 diff -r dbfde3c56790 -r 976d493106a1 app/main/member/_action/update_api_key.lua --- a/app/main/member/_action/update_api_key.lua Thu Apr 12 00:10:54 2012 +0200 +++ b/app/main/member/_action/update_api_key.lua Sun Apr 15 12:32:59 2012 +0200 @@ -1,54 +1,27 @@ - -local setting_key = "liquidfeedback_frontend_api_key" -local setting = Setting:by_pk(app.session.member.id, setting_key) local api_key -if param.get("delete", atom.boolean) then +if param.get_id() and param.get("delete", atom.boolean) then - if setting then - setting:destroy() + local member_application = MemberApplication:by_id(param.get_id()) + + if member_application then + member_application:destroy() end + slot.put_into("notice", _"API key has been deleted") else - if not setting then - setting = Setting:new() - setting.member_id = app.session.member.id - setting.key = setting_key - end - - api_key = multirand.string( + local member_application = MemberApplication:new() + member_application.member_id = app.session.member_id + member_application.key = multirand.string( 20, '23456789BCDFGHJKLMNPQRSTVWXYZbcdfghjkmnpqrstvwxyz' ) - - setting.value = api_key - - setting:save() -end - - -local setting_key = "liquidfeedback_frontend_api_key_history" + member_application.name = 'member' + member_application.comment = '' + member_application.access_level = 'full' -setting = SettingMap:new() -setting.member_id = app.session.member.id -setting.key = setting_key -setting.subkey = db:query("SELECT now()")[1].now -setting.value = api_key or "" -local dberr = setting:try_save() - -if dberr then - if dberr:is_kind_of("IntegrityConstraintViolation.UniqueViolation") then - slot.put_into("error", _"The API key has been changed too fast.") - return - else - dberr:escalate() - end + member_application:save() + slot.put_into("notice", _"API key has been created") end - -if not api_key then - slot.put_into("notice", _"API key has been deleted") -else - slot.put_into("notice", _"API key has been updated") -end diff -r dbfde3c56790 -r 976d493106a1 app/main/member/developer_settings.lua --- a/app/main/member/developer_settings.lua Thu Apr 12 00:10:54 2012 +0200 +++ b/app/main/member/developer_settings.lua Sun Apr 15 12:32:59 2012 +0200 @@ -40,48 +40,57 @@ } end - local setting_key = "liquidfeedback_frontend_api_key" - local setting = Setting:by_pk(app.session.member.id, setting_key) - local api_key - if setting then - api_key = setting.value - end - - ui.heading{ content = _"Generate / change API key" } + ui.heading{ content = _"API keys" } + util.help("member.developer_settings.api_key", _"API key") - if api_key then - slot.put(_"Your API key:") - slot.put(" ") - slot.put("", api_key, "") - slot.put(" ") - ui.link{ - text = _"Change API key", - module = "member", - action = "update_api_key", - routing = { - default = { - mode = "redirect", - module = "member", - view = "developer_settings" - } + local member_applications = MemberApplication:new_selector() + :add_where{ "member_id = ?", app.session.member.id } + :add_order_by("name, id") + :exec() + + if #member_applications > 0 then + + ui.list{ + records = member_applications, + columns = { + { + name = "name", + label = _"Name" + }, + { + name = "access_level", + label = _"Access level" + }, + { + name = "key", + label = _"API Key" + }, + { + name = "last_usage", + label = "Last usage" + }, + { + content = function(member_application) + ui.link{ + text = _"Delete", + module = "member", action = "update_api_key", id = member_application.id, + params = { delete = true }, + routing = { + default = { + mode = "redirect", + module = "member", + view = "developer_settings" + } + } + } + end + }, } } - slot.put(" ") - ui.link{ - text = _"Delete API key", - module = "member", - action = "update_api_key", - params = { delete = true }, - routing = { - default = { - mode = "redirect", - module = "member", - view = "developer_settings", - } - } - } + else + slot.put(_"Currently no API key is set.") slot.put(" ") ui.link{