paully21
(Paul Apostolos)
2019 年 7 月 3 日午後 12:48
1
API を通じてユーザーの現在のメールアドレスを取得する方法はありますか?
私たちのユースケースは以下の通りです。
当社のウェブサイトを通じて、ユーザーが Discourse の情報を管理できるようにしています。一般的に、Discourse はメーリングリストとしてのみ使用され、ほとんどのユーザーは実際の Discourse サイトを訪れることはありません。ユーザーに Discourse が現在使用しているメールアドレスを表示し、変更が必要かどうかを確認できるようにしたいと考えています。
メールアドレス以外のすべての項目については、この処理を実行できています。
以前は users/{username}/emails という API エンドポイントが存在していましたが、現在は利用できないようです。
j.jaffeux
(Joffrey Jaffeux)
2019 年 7 月 3 日午後 1:01
2
Hi,
GET /users/:username.json
will display the email in two cases:
the user id of the API KEY holder is the same than the user id related to the requested username
the API KEY holder is staff and the requested user is staged
Read more about this in code:
end
def can_change_website
!(SiteSetting.enable_discourse_connect && SiteSetting.discourse_connect_overrides_website)
end
def can_change_tracking_preferences
scope.can_change_tracking_preferences?(object)
end
def user_api_keys
keys =
object
.user_api_keys
.where(revoked_at: nil)
.map do |k|
{
id: k.id,
application_name: k.client.application_name,
scopes: k.scopes.map { |s| I18n.t("user_api_key.scopes.#{s.name}") },
created_at: k.created_at,
AFAIK this codepath has not changed recently.
「いいね!」 3
paully21
(Paul Apostolos)
2019 年 7 月 3 日午後 1:07
3
Yeah, but that doesn’t help me. All of the users are already active and the user API key is not going to match.
j.jaffeux
(Joffrey Jaffeux)
2019 年 7 月 3 日午後 1:09
4
This request does work for me:
curl "http://example.com/users/joffreyjaffeux/emails.json" \
-H 'Api-Username: joffreyjaffeux' \
-H 'Api-Key: xxx' \
-H 'Content-Type: application/json; charset=utf-8' \
「いいね!」 3
paully21
(Paul Apostolos)
2019 年 7 月 3 日午後 1:14
5
But, does it work if the URL is http://example.com/users/paulapostolos/emails.json ?
j.jaffeux
(Joffrey Jaffeux)
2019 年 7 月 3 日午後 1:17
6
Yes it should work for yourself and other users as long as this is true:
def can_check_emails?(user)
is_admin? || (is_staff? && SiteSetting.moderators_view_emails)
end
Note that doing so will trigger a staff action log.
「いいね!」 4
paully21
(Paul Apostolos)
2019 年 7 月 3 日午後 1:25
7
That worked…I had some old code that used to work (version 1.4 ish) that had the request as a PUT and without the .json at the end. I modified it to a GET and changed the URL and now it works.
Thanks for the help!
「いいね!」 3