discourse_api 0.47.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +8 -9
- data/CHANGELOG.md +23 -5
- data/discourse_api.gemspec +2 -2
- data/examples/invite_users.rb +2 -2
- data/lib/discourse_api/api/dashboard.rb +2 -2
- data/lib/discourse_api/api/groups.rb +15 -4
- data/lib/discourse_api/api/site_settings.rb +3 -3
- data/lib/discourse_api/api/users.rb +4 -0
- data/lib/discourse_api/error.rb +1 -1
- data/lib/discourse_api/single_sign_on.rb +45 -11
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/groups_spec.rb +29 -0
- data/spec/discourse_api/api/sso_spec.rb +4 -4
- data/spec/discourse_api/api/topics_spec.rb +2 -7
- data/spec/discourse_api/api/users_spec.rb +14 -0
- data/spec/discourse_api/client_spec.rb +6 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 730d29945a35c74f70e468ae35c3079b68019bd3eed8ae578e30658c1dbc638a
|
4
|
+
data.tar.gz: '0728d384637cfd505efe9c86a895b9915e6638f6576f3907d06f34eac816fa53'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a32c491fd381e24e5c11c3e73fc1ecfabe014c31e4d14cdc5975869d73663eb35cd0711fa77cf74c65ecd91b3d657e28a413edcceb3d0f7230b0ece0ba7598a4
|
7
|
+
data.tar.gz: 78099bb35c97d711fbf9c574148230d5e79d0dd45b3f384aeb335a7354faaa89267c4f40673a08e7a07e1cadbbc051990f392742176fa436748ebcb676b0c1db
|
data/.github/workflows/ci.yml
CHANGED
@@ -4,7 +4,6 @@ on:
|
|
4
4
|
pull_request:
|
5
5
|
push:
|
6
6
|
branches:
|
7
|
-
- master
|
8
7
|
- main
|
9
8
|
|
10
9
|
jobs:
|
@@ -14,13 +13,13 @@ jobs:
|
|
14
13
|
strategy:
|
15
14
|
matrix:
|
16
15
|
ruby:
|
17
|
-
- 2.
|
18
|
-
- 2.
|
19
|
-
-
|
20
|
-
- 3.
|
16
|
+
- '2.6'
|
17
|
+
- '2.7'
|
18
|
+
- '3.0'
|
19
|
+
- '3.1'
|
21
20
|
|
22
21
|
steps:
|
23
|
-
- uses: actions/checkout@
|
22
|
+
- uses: actions/checkout@v3
|
24
23
|
|
25
24
|
- name: Setup ruby
|
26
25
|
uses: ruby/setup-ruby@v1
|
@@ -35,15 +34,15 @@ jobs:
|
|
35
34
|
run: bundle exec rake test
|
36
35
|
|
37
36
|
publish:
|
38
|
-
if: github.event_name == 'push' &&
|
37
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
39
38
|
needs: build
|
40
39
|
runs-on: ubuntu-latest
|
41
40
|
|
42
41
|
steps:
|
43
|
-
- uses: actions/checkout@
|
42
|
+
- uses: actions/checkout@v3
|
44
43
|
|
45
44
|
- name: Release Gem
|
46
|
-
uses: discourse/publish-rubygems-action@v2
|
45
|
+
uses: discourse/publish-rubygems-action@v2
|
47
46
|
env:
|
48
47
|
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
49
48
|
GIT_EMAIL: team@discourse.org
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.0.0] - 2022-05-01
|
10
|
+
### Changed
|
11
|
+
- The package now requires ruby 2.6+
|
12
|
+
|
13
|
+
## [0.48.1] - 2022-04-13
|
14
|
+
### Added
|
15
|
+
- New attributes for Discourse Connect (aka SSO)
|
16
|
+
|
17
|
+
## [0.48.0] - 2022-01-28
|
18
|
+
### Added
|
19
|
+
- `group_add_owners` method (#239)
|
20
|
+
- `group_remove_owners` method (#239)
|
21
|
+
- `anonymize` method (#241)
|
22
|
+
|
23
|
+
### Changed
|
24
|
+
- `DiscourseApi::Timeout` error now inherits from `DiscourseApi::Error` (#240)
|
25
|
+
- `DiscourseApi::SingleSignOn#groups` now returns an array of strings where each string is a group name, rather than an array with a single string that contains all the groups comma-concatenated (#243)
|
26
|
+
|
9
27
|
## [0.47.0] - 2021-07-19
|
10
28
|
### Added
|
11
29
|
- Update invite method
|
@@ -17,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
17
35
|
- Pass params to get notifications API
|
18
36
|
|
19
37
|
### Deprecated
|
20
|
-
- `invite_user_to_topic` has been deprecated, use `
|
38
|
+
- `invite_user_to_topic` has been deprecated, use `invite_to_topic` instead.
|
21
39
|
- `create_private_message` has been deprecated, use `create_pm` instead.
|
22
40
|
|
23
41
|
## [0.46.0] - 2021-04-12
|
@@ -51,7 +69,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
51
69
|
|
52
70
|
## [0.43.1] - 2020-11-04
|
53
71
|
### Fixed
|
54
|
-
- Tagged version 0.43.0 got pushed without
|
72
|
+
- Tagged version 0.43.0 got pushed without commit due to new master branch
|
55
73
|
protections in github. No, code changes here just making sure tags align with
|
56
74
|
commits.
|
57
75
|
|
@@ -104,7 +122,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
104
122
|
## [0.38.0] - 2019-10-18
|
105
123
|
### Added
|
106
124
|
- Allow setting locale in SingleSignOn
|
107
|
-
- Optional param to group
|
125
|
+
- Optional param to group members to include owners as well as members
|
108
126
|
|
109
127
|
## [0.37.0] - 2019-09-23
|
110
128
|
### Added
|
@@ -117,7 +135,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
117
135
|
- Added poll methods
|
118
136
|
### Fixed
|
119
137
|
- Updated create topic example
|
120
|
-
- Fixed
|
138
|
+
- Fixed capitalization for header auth keys
|
121
139
|
|
122
140
|
## [0.35.0] - 2019-05-15
|
123
141
|
### Added
|
@@ -279,7 +297,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
279
297
|
- group_members: Allows you to retrieve more than 100 users with pagination (offset &
|
280
298
|
limit)
|
281
299
|
### Fixed
|
282
|
-
-
|
300
|
+
- Deprecation warning with SimpleCov
|
283
301
|
- updated rack dependency and added ruby 2.3 to travis config
|
284
302
|
|
285
303
|
## [0.9.1] - 2016-03-23
|
data/discourse_api.gemspec
CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
31
31
|
spec.add_development_dependency 'simplecov', '~> 0.11'
|
32
32
|
spec.add_development_dependency 'webmock', '~> 3.0'
|
33
|
-
spec.add_development_dependency 'rubocop-discourse', '~> 2.
|
33
|
+
spec.add_development_dependency 'rubocop-discourse', '~> 2.5.0'
|
34
34
|
|
35
|
-
spec.required_ruby_version = '>= 2.
|
35
|
+
spec.required_ruby_version = '>= 2.6.0'
|
36
36
|
end
|
data/examples/invite_users.rb
CHANGED
@@ -18,10 +18,10 @@ client.update_invite(invite["id"], email: "namee@example.com")
|
|
18
18
|
client.resend_invite("namee@example.com")
|
19
19
|
|
20
20
|
# invite to a topic
|
21
|
-
client.
|
21
|
+
client.invite_to_topic(1, email: "foo@bar.com")
|
22
22
|
|
23
23
|
# if the user is an admin you may invite to a group as well
|
24
|
-
client.
|
24
|
+
client.invite_to_topic(1, email: "foo@bar.com", group_ids: "1,2,3")
|
25
25
|
|
26
26
|
# retrieve invite
|
27
27
|
puts client.retrieve_invite(email: "foo@bar.com")
|
@@ -38,7 +38,6 @@ module DiscourseApi
|
|
38
38
|
:messageable_level,
|
39
39
|
:name,
|
40
40
|
:automatic_membership_email_domains,
|
41
|
-
:automatic_membership_retroactive,
|
42
41
|
:title,
|
43
42
|
:primary_group,
|
44
43
|
:grant_trust_level,
|
@@ -47,19 +46,31 @@ module DiscourseApi
|
|
47
46
|
:flair_bg_color,
|
48
47
|
:flair_color,
|
49
48
|
:bio_raw,
|
50
|
-
:
|
49
|
+
:visibility_level,
|
51
50
|
:public_admission,
|
52
51
|
:public_exit,
|
53
52
|
:allow_membership_requests,
|
54
53
|
:full_name,
|
55
54
|
:default_notification_level,
|
56
|
-
:usernames,
|
57
|
-
:owner_usernames,
|
58
55
|
:membership_request_template)
|
59
56
|
.to_h
|
60
57
|
put("/groups/#{group_id}", group: args)
|
61
58
|
end
|
62
59
|
|
60
|
+
def group_add_owners(group_id, args)
|
61
|
+
args = API.params(args)
|
62
|
+
.required(:usernames)
|
63
|
+
.to_h
|
64
|
+
put("/admin/groups/#{group_id}/owners.json", group: args)
|
65
|
+
end
|
66
|
+
|
67
|
+
def group_remove_owners(group_id, args)
|
68
|
+
args = API.params(args)
|
69
|
+
.required(:usernames)
|
70
|
+
.to_h
|
71
|
+
delete("/admin/groups/#{group_id}/owners.json", group: args)
|
72
|
+
end
|
73
|
+
|
63
74
|
def groups(args = {})
|
64
75
|
params = API.params(args)
|
65
76
|
.optional(:page)
|
@@ -3,10 +3,10 @@ module DiscourseApi
|
|
3
3
|
module API
|
4
4
|
module SiteSettings
|
5
5
|
def site_setting_update(args = {})
|
6
|
-
params = API.params(args)
|
7
|
-
.required(:name, :value).to_h
|
6
|
+
params = API.params(args).required(:name, :value).to_h
|
8
7
|
new_site_setting = { params[:name] => params[:value] }
|
9
|
-
|
8
|
+
|
9
|
+
put("/admin/site_settings/#{params[:name]}", new_site_setting)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -102,6 +102,10 @@ module DiscourseApi
|
|
102
102
|
put("/admin/users/#{user_id}/unsuspend")
|
103
103
|
end
|
104
104
|
|
105
|
+
def anonymize(user_id)
|
106
|
+
put("/admin/users/#{user_id}/anonymize")
|
107
|
+
end
|
108
|
+
|
105
109
|
def delete_user(user_id, delete_posts = false)
|
106
110
|
delete("/admin/users/#{user_id}.json?delete_posts=#{delete_posts}")
|
107
111
|
end
|
data/lib/discourse_api/error.rb
CHANGED
@@ -5,18 +5,51 @@ require 'openssl'
|
|
5
5
|
|
6
6
|
module DiscourseApi
|
7
7
|
class SingleSignOn
|
8
|
-
ACCESSORS = [
|
9
|
-
|
10
|
-
|
8
|
+
ACCESSORS = [
|
9
|
+
:add_groups,
|
10
|
+
:admin,
|
11
|
+
:avatar_force_update,
|
12
|
+
:avatar_url,
|
13
|
+
:bio,
|
14
|
+
:card_background_url,
|
15
|
+
:confirmed_2fa,
|
16
|
+
:email,
|
17
|
+
:external_id,
|
18
|
+
:groups,
|
19
|
+
:locale,
|
20
|
+
:locale_force_update,
|
21
|
+
:moderator,
|
22
|
+
:name,
|
23
|
+
:no_2fa_methods,
|
24
|
+
:nonce,
|
25
|
+
:profile_background_url,
|
26
|
+
:remove_groups,
|
27
|
+
:require_2fa,
|
28
|
+
:require_activation,
|
29
|
+
:return_sso_url,
|
30
|
+
:suppress_welcome_message,
|
31
|
+
:title,
|
32
|
+
:username,
|
33
|
+
]
|
34
|
+
|
11
35
|
FIXNUMS = []
|
12
|
-
|
13
|
-
|
36
|
+
|
37
|
+
BOOLS = [
|
38
|
+
:admin,
|
39
|
+
:avatar_force_update,
|
40
|
+
:confirmed_2fa,
|
41
|
+
:locale_force_update,
|
42
|
+
:moderator,
|
43
|
+
:no_2fa_methods,
|
44
|
+
:require_2fa,
|
45
|
+
:require_activation,
|
46
|
+
:suppress_welcome_message,
|
47
|
+
]
|
14
48
|
ARRAYS = [:groups]
|
15
49
|
#NONCE_EXPIRY_TIME = 10.minutes # minutes is a rails method and is causing an error. Is this needed in the api?
|
16
50
|
|
17
51
|
attr_accessor(*ACCESSORS)
|
18
|
-
|
19
|
-
attr_writer :sso_secret, :sso_url
|
52
|
+
attr_writer :custom_fields, :sso_secret, :sso_url
|
20
53
|
|
21
54
|
def self.sso_secret
|
22
55
|
raise RuntimeError, "sso_secret not implemented on class, be sure to set it on instance"
|
@@ -27,7 +60,6 @@ module DiscourseApi
|
|
27
60
|
end
|
28
61
|
|
29
62
|
def self.parse_hash(payload)
|
30
|
-
payload
|
31
63
|
sso = new
|
32
64
|
|
33
65
|
sso.sso_secret = payload.delete(:sso_secret)
|
@@ -40,11 +72,13 @@ module DiscourseApi
|
|
40
72
|
if BOOLS.include? k
|
41
73
|
val = ["true", "false"].include?(val) ? val == "true" : nil
|
42
74
|
end
|
43
|
-
val =
|
75
|
+
val = val.split(",") if ARRAYS.include?(k) && !val.nil?
|
44
76
|
sso.send("#{k}=", val)
|
45
77
|
end
|
78
|
+
|
46
79
|
# Set custom_fields
|
47
80
|
sso.custom_fields = payload[:custom_fields]
|
81
|
+
|
48
82
|
# Add custom_fields (old format)
|
49
83
|
payload.each do |k, v|
|
50
84
|
if field = k[/^custom\.(.+)$/, 1]
|
@@ -79,7 +113,7 @@ module DiscourseApi
|
|
79
113
|
if BOOLS.include? k
|
80
114
|
val = ["true", "false"].include?(val) ? val == "true" : nil
|
81
115
|
end
|
82
|
-
val =
|
116
|
+
val = val.split(",") if ARRAYS.include?(k) && !val.nil?
|
83
117
|
sso.send("#{k}=", val)
|
84
118
|
end
|
85
119
|
|
@@ -127,7 +161,7 @@ module DiscourseApi
|
|
127
161
|
|
128
162
|
ACCESSORS.each do |k|
|
129
163
|
next if (val = send k) == nil
|
130
|
-
|
164
|
+
payload[k] = val
|
131
165
|
end
|
132
166
|
|
133
167
|
if @custom_fields
|
@@ -91,6 +91,35 @@ describe DiscourseApi::API::Groups do
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
+
describe "add owners" do
|
95
|
+
let(:url) { "#{host}/admin/groups/123/owners.json" }
|
96
|
+
|
97
|
+
before do
|
98
|
+
stub_put(url)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "makes the member an owner" do
|
102
|
+
subject.group_add_owners(123, usernames: "sam")
|
103
|
+
params = escape_params("group[usernames]" => "sam")
|
104
|
+
expect(a_request(:put, "#{host}/admin/groups/123/owners.json").
|
105
|
+
with(body: params)
|
106
|
+
).to have_been_made
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "remove owners" do
|
111
|
+
let(:url) { "#{host}/admin/groups/123/owners.json?group%5Busernames%5D=sam" }
|
112
|
+
|
113
|
+
before do
|
114
|
+
stub_delete(url)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "removes the owner role from the group member" do
|
118
|
+
subject.group_remove_owners(123, usernames: "sam")
|
119
|
+
expect(a_delete(url)).to have_been_made
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
94
123
|
describe "group members" do
|
95
124
|
it "list members" do
|
96
125
|
stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=0").to_return(body: fixture("members_0.json"), headers: { content_type: "application/json" })
|
@@ -27,10 +27,10 @@ describe DiscourseApi::API::SSO do
|
|
27
27
|
}
|
28
28
|
end
|
29
29
|
let(:expected_unsigned_payload) do
|
30
|
-
'
|
31
|
-
'
|
32
|
-
'&
|
33
|
-
'custom.custom.field_1=tomato'
|
30
|
+
'add_groups=a&add_groups=b&avatar_url=https%3A%2F%2Fwww.website.com'\
|
31
|
+
'&email=some%40email.com&external_id=abc&name=Some+User&remove_groups=c'\
|
32
|
+
'&remove_groups=d&title=ruby&username=some_user&custom.field_2=potato'\
|
33
|
+
'&custom.custom.field_1=tomato'
|
34
34
|
end
|
35
35
|
let(:sso_double) { DiscourseApi::SingleSignOn.parse_hash(params) }
|
36
36
|
|
@@ -15,23 +15,18 @@ describe DiscourseApi::API::Topics do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe "#
|
18
|
+
describe "#invite_to_topic" do
|
19
19
|
before do
|
20
20
|
stub_post("#{host}/t/12/invite").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
|
21
21
|
end
|
22
22
|
|
23
23
|
it "requests the correct resource" do
|
24
|
-
subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
|
25
|
-
expect(a_post("#{host}/t/12/invite")).to have_been_made
|
26
|
-
end
|
27
|
-
|
28
|
-
it "requests the correct resource with new method 'invite_to_topic'" do
|
29
24
|
subject.invite_to_topic(12, email: "fake_user@example.com")
|
30
25
|
expect(a_post("#{host}/t/12/invite")).to have_been_made
|
31
26
|
end
|
32
27
|
|
33
28
|
it "returns success" do
|
34
|
-
response = subject.
|
29
|
+
response = subject.invite_to_topic(12, email: "fake_user@example.com")
|
35
30
|
expect(response).to be_a Hash
|
36
31
|
expect(response['success']).to be_truthy
|
37
32
|
end
|
@@ -306,6 +306,20 @@ describe DiscourseApi::API::Users do
|
|
306
306
|
end
|
307
307
|
end
|
308
308
|
|
309
|
+
describe "#anonymize" do
|
310
|
+
before do
|
311
|
+
url = "#{host}/admin/users/11/anonymize"
|
312
|
+
stub_put(url).to_return(body: '', status: 200)
|
313
|
+
end
|
314
|
+
|
315
|
+
it "makes the correct put request" do
|
316
|
+
result = subject.anonymize(11)
|
317
|
+
url = "#{host}/admin/users/11/anonymize"
|
318
|
+
expect(a_put(url)).to have_been_made
|
319
|
+
expect(result.status).to eq(200)
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
309
323
|
describe "#delete_user" do
|
310
324
|
before do
|
311
325
|
url = "#{host}/admin/users/11.json?delete_posts=true"
|
@@ -41,6 +41,12 @@ describe DiscourseApi::Client do
|
|
41
41
|
expect(subject.send(:connection).options.timeout).to eq(25)
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
it "raises DiscourseApi::Timeout" do
|
46
|
+
stub_get("#{host}/t/1.json").to_timeout
|
47
|
+
|
48
|
+
expect { subject.topic(1) }.to raise_error(DiscourseApi::Timeout)
|
49
|
+
end
|
44
50
|
end
|
45
51
|
|
46
52
|
describe "#api_key" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2022-05-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: faraday
|
@@ -173,14 +173,14 @@ dependencies:
|
|
173
173
|
requirements:
|
174
174
|
- - "~>"
|
175
175
|
- !ruby/object:Gem::Version
|
176
|
-
version: 2.
|
176
|
+
version: 2.5.0
|
177
177
|
type: :development
|
178
178
|
prerelease: false
|
179
179
|
version_requirements: !ruby/object:Gem::Requirement
|
180
180
|
requirements:
|
181
181
|
- - "~>"
|
182
182
|
- !ruby/object:Gem::Version
|
183
|
-
version: 2.
|
183
|
+
version: 2.5.0
|
184
184
|
description: Discourse API
|
185
185
|
email:
|
186
186
|
- sam.saffron@gmail.com
|
@@ -340,7 +340,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
340
340
|
requirements:
|
341
341
|
- - ">="
|
342
342
|
- !ruby/object:Gem::Version
|
343
|
-
version: 2.
|
343
|
+
version: 2.6.0
|
344
344
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
345
345
|
requirements:
|
346
346
|
- - ">="
|