note description: "Summary description for {ES_CLOUD_LICENSES_ADMIN_HANDLER}." author: "" date: "$Date$" revision: "$Revision$" class ES_CLOUD_LICENSES_ADMIN_HANDLER inherit ES_CLOUD_ADMIN_HANDLER rename make as make_admin_handler end WSF_URI_TEMPLATE_HANDLER create make feature {NONE} -- Creation make (a_es_cloud_api: ES_CLOUD_API; a_admin_module: ES_CLOUD_MODULE_ADMINISTRATION) do admin_module := a_admin_module make_admin_handler (a_es_cloud_api) end feature -- Access admin_module: ES_CLOUD_MODULE_ADMINISTRATION feature -- Execution execute (req: WSF_REQUEST; res: WSF_RESPONSE) do if attached {WSF_STRING} req.path_parameter ("license") as p_license then handle_license (p_license.value, req, res) elseif req.is_post_request_method then handle_licenses_group_action (req, res) else handle_licenses_list (req, res) end end handle_license (a_lic_id: READABLE_STRING_GENERAL; req: WSF_REQUEST; res: WSF_RESPONSE) local lic: ES_CLOUD_LICENSE l_email_lic: detachable ES_CLOUD_EMAIL_LICENSE s: STRING r: like new_generic_response f: CMS_FORM fset: WSF_FORM_FIELD_SET l_user: detachable ES_CLOUD_USER do if api.has_permission ("admin es licenses") then lic := es_cloud_api.license_by_key (a_lic_id) if lic = Void and a_lic_id.is_integer_64 then lic := es_cloud_api.license (a_lic_id.to_integer_64) end if lic = Void then send_not_found (req, res) else l_user := es_cloud_api.user_for_license (lic) r := new_generic_response (req, res) create s.make_empty -- Edit form create f.make (r.absolute_url (req.percent_encoded_path_info, Void), "edit-license") f.set_method_post if l_user = Void then l_email_lic := es_cloud_api.email_license (lic) end if l_email_lic /= Void then admin_module.add_assign_email_license_form_part_to (l_email_lic, f, es_cloud_api) end create fset.make fset.set_legend ("Edit license " + html_encoded (lic.key)) f.extend (fset) admin_module.add_license_form_part_to (lic, fset, es_cloud_api) if req.is_post_request_method then f.validation_actions.extend (agent admin_module.license_form_validation_action (?, l_user, lic, es_cloud_api)) f.process (r) if attached es_cloud_api.license_by_key (lic.key) as l_updated_lic then lic := l_updated_lic end es_cloud_api.append_license_to_html (lic, l_user, Void, s) -- Update form with fresh data. create f.make (r.absolute_url (req.percent_encoded_path_info, Void), "edit-license") f.set_method_post if l_email_lic /= Void then admin_module.add_assign_email_license_form_part_to (l_email_lic, f, es_cloud_api) end create fset.make f.extend (fset) admin_module.add_license_form_part_to (lic, fset, es_cloud_api) f.append_to_html (r.wsf_theme, s) else es_cloud_api.append_license_to_html (lic, l_user, Void, s) f.append_to_html (r.wsf_theme, s) end r.set_main_content (s) r.execute end end end handle_licenses_list (req: WSF_REQUEST; res: WSF_RESPONSE) local r: like new_generic_response lic: detachable ES_CLOUD_LICENSE s: STRING l_user: ES_CLOUD_USER l_order_by: detachable READABLE_STRING_32 l_order_by_reversed: BOOLEAN l_plan_filter: detachable READABLE_STRING_GENERAL l_expiring_before_n_days_filter: INTEGER l_inc_expired, l_only_expired: BOOLEAN l_org: ES_CLOUD_ORGANIZATION l_email, l_user_email: READABLE_STRING_8 -- orgs: detachable LIST [ES_CLOUD_ORGANIZATION] lics: LIST [TUPLE [license: ES_CLOUD_LICENSE; user: detachable ES_CLOUD_USER; email: detachable READABLE_STRING_8; org: detachable ES_CLOUD_ORGANIZATION]] lics_last_sessions: STRING_TABLE [ES_CLOUD_SESSION] -- indexed by license key. lics_sorter: QUICK_SORTER [TUPLE [license: ES_CLOUD_LICENSE]] l_last_remote_address: detachable READABLE_STRING_32 f: CMS_FORM f_select: WSF_FORM_SELECT f_opt: WSF_FORM_SELECT_OPTION f_div: WSF_WIDGET_DIV f_cb: WSF_FORM_CHECKBOX_INPUT do if api.has_permissions (<< {ES_CLOUD_MODULE}.perm_manage_es_accounts, {ES_CLOUD_MODULE}.perm_manage_es_licenses >>) then r := new_generic_response (req, res) add_primary_tabs (r) if attached {WSF_STRING} req.query_parameter ("order-by") as p_order_by then l_order_by := p_order_by.value if l_order_by.is_whitespace then l_order_by := Void end end if attached {WSF_STRING} req.query_parameter ("plan") as p_plan then l_plan_filter := p_plan.value if l_plan_filter.is_whitespace then l_plan_filter := Void end end if attached {WSF_STRING} req.query_parameter ("with_expired") as p_include_expired then l_inc_expired := p_include_expired.is_case_insensitive_equal ("yes") end if attached {WSF_STRING} req.query_parameter ("expiring_before_n_days") as p_expiring_before_n_days then l_expiring_before_n_days_filter := p_expiring_before_n_days.value.to_integer_32 if l_expiring_before_n_days_filter <= 0 then l_expiring_before_n_days_filter := 0 end end if attached {WSF_STRING} req.query_parameter ("only_expired") as p_only_expired then l_only_expired := p_only_expired.is_case_insensitive_equal ("yes") if l_only_expired then l_expiring_before_n_days_filter := 0 l_inc_expired := True end end if l_plan_filter /= Void then if l_plan_filter.is_case_insensitive_equal ("$") then create s.make_from_string ("
organizations | Plan | Until | ") -- s.append ("Action | ") s.append ("|||
---|---|---|---|---|---|---|
") -- s.append (html_encoded (ic.item.name)) -- s.append (" | ") -- if sub /= Void then -- s.append ("") -- s.append (html_encoded (sub.plan.title_or_name)) -- s.append (" | ") -- s.append ("") -- if sub.is_active then -- if attached sub.expiration_date as dt then -- s.append (html_encoded (date_time_to_string (dt))) -- s.append (" ( " + sub.days_remaining.out + " days remaining )") -- else -- s.append ("ACTIVE") -- s.append (" (since ") -- s.append (html_encoded (date_time_to_string (sub.creation_date))) -- s.append (")") -- end -- else -- s.append ("EXPIRED") -- if attached sub.expiration_date as dt then -- s.append (" (since ") -- s.append (html_encoded (date_time_to_string (dt))) -- s.append (")") -- end -- end -- s.append (" | ") -- -- s.append ("") -- -- s.append ("Cancel | Upgrade") -- -- s.append (" | ") -- else -- s.append ("") -- s.append (" | ") -- s.append ("") -- s.append (" | ") -- -- s.append ("") -- -- s.append ("Upgrade") -- -- s.append (" | ") -- end -- s.append ("
") fset.extend_raw_text (l_export) fset.extend_html_text ("") end f.append_to_html (r.wsf_theme, s) r.set_main_content (s) r.execute else send_bad_request (req, res) end else send_access_denied (req, res) end end form_submit_label_export_to_csv: STRING = "Export to CSV" form_submit_label_send_message_for_expired_licenses: STRING = "Send messages for expired licenses" form_submit_label_send_message_for_soon_expired_licenses: STRING = "Send messages for licenses about to expire" invariant end