-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.rb
78 lines (61 loc) · 2.22 KB
/
plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# name: discourse-apim
# about: RCPCH API key management
# version: 0.0.1
# authors: Michael Barton, RCPCH
# url: https://github.com/rcpch/discourse-apim
register_asset "stylesheets/user-apim.scss"
register_svg_icon "server"
after_initialize do
require_relative "app/controllers/apim_controller.rb"
require_relative "app/controllers/apim_usage_controller.rb"
require_relative "app/jobs/fetch_monthly_usage_data.rb"
add_admin_route "admin.apim", "apim"
Discourse::Application.routes.append do
# Pages
%w[users u].each do |root_path|
get "#{root_path}/:username/apim" => "users#show",
:constraints => {
username: RouteFormat.username,
}
end
%w[groups g].each do |root_path|
resources :groups,
only: %i[index show new edit update],
id: RouteFormat.username,
path: root_path do
member do
%w[
apim
].each { |path| get path => "groups#show" }
end
end
end
get "/admin/plugins/apim" => "admin/plugins#index",
:constraints => StaffConstraint.new
# User API
# TODO: isolate this as a Rails engine
get "/apim/users/:username" => "apim#list_for_user",
:constraints => {
username: RouteFormat.username,
}
get "/apim/groups/:id" => "apim#list_for_group"
post "/apim/users/:username/products/:product" => 'apim#create_for_user',
:constraints => {
username: RouteFormat.username,
}
post "/apim/groups/:id/products/:product" => 'apim#create_for_group'
# This is a POST, following the upstream Azure API
# presumably a protection against XSRF
post "/apim/users/:username/products/:product/showCredentials" => 'apim#show_for_user',
:constraints => {
username: RouteFormat.username,
}
post "/apim/groups/:id/products/:product/showCredentials" => 'apim#show_for_group'
put "/apim/groups/:id/reportingSubscriptions" => 'apim#set_reporting_subscriptions'
# Admin API
get "/apim/usage/report" => 'apim_usage#report'
post "/apim/usage/refresh" => 'apim_usage#refresh'
end
register_user_custom_field_type('apim', :json)
register_group_custom_field_type('apim', :json)
end