Add a privileged scope that allows email addresses to be returned

This commit is contained in:
Tom Hughes 2021-07-30 22:39:39 +01:00
parent 6c6e8883f7
commit f4d1d97848
5 changed files with 11 additions and 1 deletions

View file

@ -395,4 +395,10 @@ class ApplicationController < ActionController::Base
referer.to_s
end
def scope_enabled?(scope)
doorkeeper_token&.includes_scope?(scope) || current_token&.includes_scope?(scope)
end
helper_method :scope_enabled?
end

View file

@ -65,5 +65,7 @@ json.user do
json.count user.sent_messages.size
end
end
json.email user.email if scope_enabled?(:read_email)
end
end

View file

@ -40,5 +40,6 @@ xml.tag! "user", :id => user.id,
:unread => user.new_messages.size
xml.tag! "sent", :count => user.sent_messages.size
end
xml.tag! "email", user.email if scope_enabled?(:read_email)
end
end

View file

@ -2342,6 +2342,7 @@ en:
read_gpx: Read private GPS traces
write_gpx: Upload GPS traces
write_notes: Modify notes
read_email: Read user email address
oauth_clients:
new:
title: "Register a new application"

View file

@ -1,6 +1,6 @@
module Oauth
SCOPES = %w[read_prefs write_prefs write_diary write_api read_gpx write_gpx write_notes].freeze
PRIVILEGED_SCOPES = %w[].freeze
PRIVILEGED_SCOPES = %w[read_email].freeze
class Scope
attr_reader :name