discourse_api 0.47.0 → 0.48.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fffa65d4ed129c229766cecd20c2b5684570d22dcd08deaa44474f37cbe0b7c
4
- data.tar.gz: 35db4a119a91642c632b43b78cbde678c2a753f28adb88b376bf1b5ab9bb6a2b
3
+ metadata.gz: '047378d84854b5dae025d57550c071bf9944257a4048bd1be5b51b389e995dc3'
4
+ data.tar.gz: af75df86361c631aba91dc685c26e2f0d392597fbd561ef93b628f319f907457
5
5
  SHA512:
6
- metadata.gz: 7353e073896a9e70d38336cba97d0c0f53f951c925e21e4333cc67fd8bfbd40ce5745f50ee6c6a87ce3e5c69c77d67e3287458a96418f033c9ee88901da7e3fa
7
- data.tar.gz: 8a3cbddb1585c72dcf3eeaa3723e4742007b076c239e47a23cbf98c87024a95e4712e54eed85be4b48f9100acef41b282b91007c05237cc10048d5753ed82db4
6
+ metadata.gz: 7a435c702c930231c817d8192a20ddd859c3102cb3a9928ad4402dc1c019330d4dca79bd407f00ffa9e9038cebe7a0c138c081a019f4373711bfea67104c1a00
7
+ data.tar.gz: 8664b7d0efa3982e223a61af2a7d28ea2744100fdf1f3dcef99c9c1c3f7c59481c264ac04092c9b0c4c6a5f7559bd1fa99c4010d69fb1451f1a7875678a06d19
data/CHANGELOG.md CHANGED
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.48.0] - 2022-01-28
10
+ ### Added
11
+ - `group_add_owners` method (#239)
12
+ - `group_remove_owners` method (#239)
13
+ - `anonymize` method (#241)
14
+
15
+ ### Changed
16
+ - `DiscourseApi::Timeout` error now inherits from `DiscourseApi::Error` (#240)
17
+ - `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)
18
+
9
19
  ## [0.47.0] - 2021-07-19
10
20
  ### Added
11
21
  - Update invite method
@@ -17,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
17
27
  - Pass params to get notifications API
18
28
 
19
29
  ### Deprecated
20
- - `invite_user_to_topic` has been deprecated, use `invite_user` instead.
30
+ - `invite_user_to_topic` has been deprecated, use `invite_to_topic` instead.
21
31
  - `create_private_message` has been deprecated, use `create_pm` instead.
22
32
 
23
33
  ## [0.46.0] - 2021-04-12
@@ -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.invite_user_to_topic(email: "foo@bar.com", topic_id: 1)
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.invite_user_to_topic(email: "foo@bar.com", group_ids: "1,2,3", topic_id: 1)
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")
@@ -14,10 +14,10 @@ module DiscourseApi
14
14
  topics = global_reports[3]
15
15
  posts = global_reports[4]
16
16
 
17
- totals = {
17
+ {
18
18
  'users' => users['total'],
19
19
  'topics' => topics['total'],
20
- 'posts' => posts['total']
20
+ 'posts' => posts['total'],
21
21
  }
22
22
  end
23
23
  end
@@ -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
- :members_visibility_level,
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
- response = put("/admin/site_settings/#{params[:name]}", new_site_setting)
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
@@ -34,6 +34,6 @@ module DiscourseApi
34
34
  class TooManyRequests < DiscourseError
35
35
  end
36
36
 
37
- class Timeout < DiscourseError
37
+ class Timeout < Error
38
38
  end
39
39
  end
@@ -15,8 +15,7 @@ module DiscourseApi
15
15
  #NONCE_EXPIRY_TIME = 10.minutes # minutes is a rails method and is causing an error. Is this needed in the api?
16
16
 
17
17
  attr_accessor(*ACCESSORS)
18
- attr_accessor :custom_fields
19
- attr_writer :sso_secret, :sso_url
18
+ attr_writer :custom_fields, :sso_secret, :sso_url
20
19
 
21
20
  def self.sso_secret
22
21
  raise RuntimeError, "sso_secret not implemented on class, be sure to set it on instance"
@@ -27,7 +26,6 @@ module DiscourseApi
27
26
  end
28
27
 
29
28
  def self.parse_hash(payload)
30
- payload
31
29
  sso = new
32
30
 
33
31
  sso.sso_secret = payload.delete(:sso_secret)
@@ -40,11 +38,13 @@ module DiscourseApi
40
38
  if BOOLS.include? k
41
39
  val = ["true", "false"].include?(val) ? val == "true" : nil
42
40
  end
43
- val = Array(val) if ARRAYS.include?(k) && !val.nil?
41
+ val = val.split(",") if ARRAYS.include?(k) && !val.nil?
44
42
  sso.send("#{k}=", val)
45
43
  end
44
+
46
45
  # Set custom_fields
47
46
  sso.custom_fields = payload[:custom_fields]
47
+
48
48
  # Add custom_fields (old format)
49
49
  payload.each do |k, v|
50
50
  if field = k[/^custom\.(.+)$/, 1]
@@ -79,7 +79,7 @@ module DiscourseApi
79
79
  if BOOLS.include? k
80
80
  val = ["true", "false"].include?(val) ? val == "true" : nil
81
81
  end
82
- val = Array(val) if ARRAYS.include?(k) && !val.nil?
82
+ val = val.split(",") if ARRAYS.include?(k) && !val.nil?
83
83
  sso.send("#{k}=", val)
84
84
  end
85
85
 
@@ -127,7 +127,7 @@ module DiscourseApi
127
127
 
128
128
  ACCESSORS.each do |k|
129
129
  next if (val = send k) == nil
130
- payload[k] = val
130
+ payload[k] = val
131
131
  end
132
132
 
133
133
  if @custom_fields
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DiscourseApi
3
- VERSION = "0.47.0"
3
+ VERSION = "0.48.0"
4
4
  end
@@ -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" })
@@ -15,23 +15,18 @@ describe DiscourseApi::API::Topics do
15
15
  end
16
16
  end
17
17
 
18
- describe "#invite_user_to_topic" do
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.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
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.47.0
4
+ version: 0.48.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: 2021-07-19 00:00:00.000000000 Z
14
+ date: 2022-01-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: faraday