]> git.openstreetmap.org Git - rails.git/commitdiff
Highlight moderator-only scopes when showing authorizations
authorAnton Khorev <tony29@yandex.ru>
Sat, 21 Oct 2023 17:39:55 +0000 (20:39 +0300)
committerAnton Khorev <tony29@yandex.ru>
Thu, 21 Dec 2023 14:37:17 +0000 (17:37 +0300)
app/helpers/authorization_helper.rb [new file with mode: 0644]
app/views/oauth2_applications/_application.html.erb
app/views/oauth2_authorizations/new.html.erb
app/views/oauth2_authorized_applications/_application.html.erb
lib/oauth.rb

diff --git a/app/helpers/authorization_helper.rb b/app/helpers/authorization_helper.rb
new file mode 100644 (file)
index 0000000..11c8c29
--- /dev/null
@@ -0,0 +1,13 @@
+module AuthorizationHelper
+  include ActionView::Helpers::TranslationHelper
+
+  def authorization_scope(scope)
+    html = []
+    html << t("oauth.scopes.#{scope}")
+    if Oauth::MODERATOR_SCOPES.include? scope
+      html << " "
+      html << image_tag("roles/moderator.png", :srcset => image_path("roles/moderator.svg", :class => "align-text-bottom"), :size => "20x20")
+    end
+    safe_join(html)
+  end
+end
index 564fa81ebf33ad83ce07f55b2d8af173de932466..57e852182941301acd09cb75543270dc149a406b 100644 (file)
@@ -10,7 +10,7 @@
   <td class="align-middle">
     <ul class="list-unstyled mb-0">
       <% application.scopes.each do |scope| -%>
-        <li><%= t "oauth.scopes.#{scope}" %> <code class="text-muted">(<%= scope %>)</code></li>
+        <li><%= authorization_scope(scope) %> <code class="text-muted">(<%= scope %>)</code></li>
       <% end -%>
     </ul>
   </td>
index ac9c7c6c598404131f12fc790444d43b6b21fa36..8720bf05a6461bee51d96a9ec83ccc154e5dde24 100644 (file)
@@ -6,7 +6,7 @@
 
 <ul>
   <% @pre_auth.scopes.each do |scope| -%>
-    <li><%= t "oauth.scopes.#{scope}" %></li>
+    <li><%= authorization_scope(scope) %></li>
   <% end -%>
 </ul>
 
index 8abbb26ed8bb46e83e7830d7d2c97f3f979a96b8..28d048c4a098a727d7f289aec84c61ebce69cd6e 100644 (file)
@@ -5,7 +5,7 @@
   <td class="align-middle">
     <ul class="list-unstyled mb-0">
       <% application.authorized_scopes_for(current_user).each do |scope| -%>
-        <li><%= t "oauth.scopes.#{scope}" %></li>
+        <li><%= authorization_scope(scope) %></li>
       <% end -%>
     </ul>
   </td>
index 0456c08732a927eb1c944f74b5ccc969f9971ce4..e5642163d5cde62388bdd06124b65ee86bd64a5f 100644 (file)
@@ -1,6 +1,7 @@
 module Oauth
   SCOPES = %w[read_prefs write_prefs write_diary write_api read_gpx write_gpx write_notes].freeze
   PRIVILEGED_SCOPES = %w[read_email skip_authorization].freeze
+  MODERATOR_SCOPES = %w[].freeze
   OAUTH2_SCOPES = %w[openid].freeze
 
   class Scope