Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
fixes & authorize button
Browse files Browse the repository at this point in the history
  • Loading branch information
reesericci committed Jan 25, 2024
1 parent 2841dfa commit 81f38c0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
28 changes: 21 additions & 7 deletions app/controllers/developers/applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,53 @@ def show

def add_scope
@application = current_application
@application.update!(scopes: Doorkeeper::OAuth::Scopes.from_array([@application.scopes, params[:scope]]))
redirect_back(fallback_location: developers_applications_path(id: params[:id]))
begin
@application.update!(scopes: Doorkeeper::OAuth::Scopes.from_array([@application.scopes, params[:scope]]))
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique => e
flash.notice = e.message
else
flash.notice = "Added Scope #{params[:scope]}"
ensure
redirect_back(fallback_location: developers_applications_path(id: params[:id]))
end
end

def destroy_scope
@application = current_application
scopes = @application.scopes.to_a
scopes.delete(params[:scope])
@application.update!(scopes: Doorkeeper::OAuth::Scopes.from_array(scopes))
redirect_back(fallback_location: developers_applications_path(id: params[:id]))
redirect_back(fallback_location: developers_applications_path(id: params[:id]), notice: "Destroyed scope #{params[:scope]}")
end

def add_redirect_uri
@application = current_application
uris = @application.redirect_uri.split("\r\n")
uris.push(params[:redirect_uri])
@application.update!(redirect_uri: uris.join("\r\n"))
redirect_back(fallback_location: developers_applications_path(id: params[:id]))
begin
@application.update!(redirect_uri: uris.join("\r\n"))
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique => e
flash.notice = e.message
else
flash.notice = "Added Redirect URI"
ensure
redirect_back(fallback_location: developers_applications_path(id: params[:id]))
end
end

def destroy_redirect_uri
@application = current_application
uris = @application.redirect_uri.split("\r\n")
uris.delete(params[:redirect_uri])
@application.update!(redirect_uri: uris.join("\r\n"))
redirect_back(fallback_location: developers_applications_path(id: params[:id]))
redirect_back(fallback_location: developers_applications_path(id: params[:id]), notice: "Destroyed Redirect URI")
end

def update
@application = current_application
@application.update!(name: params[:name]) if params[:name]
@application.update!(confidential: params[:confidential].to_i.zero?) if params[:confidential]
redirect_back(fallback_location: developers_applications_path(id: params[:id]))
redirect_back(fallback_location: developers_applications_path(id: params[:id]), notice: "Updated application")
end

def destroy
Expand Down
2 changes: 0 additions & 2 deletions app/helpers/developer/applications_helper.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/mailers/developers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Developers::ApplicationMailer < ApplicationMailer
def app_created_email
@app = params[:domain]
@app = params[:app]
mail(to: params[:email], subject: "Your app has been created!", message_stream: "outbound")
end
end
5 changes: 5 additions & 0 deletions app/views/developers/applications/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
<% @application.redirect_uri.split("\r\n") do |r| %>
<tr>
<td><%= r %></td>
<td>
<%= link_to oauth_authorization_path(client_id: @application.uid, redirect_uri: r, response_type: 'code', scope: @application.scopes), target: "_blank" do %>
<button class="clipbutton">Authorize</button>
<% end %>
</td>
<td>
<%= form_with method: :delete, url: redirect_uris_developers_application_path(id: @application.id), id: "destroy_redirect_url" do |form| %>
<%= form.hidden_field :redirect_uri, value: r %>
Expand Down

0 comments on commit 81f38c0

Please sign in to comment.