Skip to content

Commit 927d88b

Browse files
committed
Add funcitonality to delete a domain
1 parent 6b23986 commit 927d88b

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

app/controllers/org_domain_controller.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,21 @@ def update
120120
end
121121
end
122122

123-
123+
def destroy
124+
@org_domain = OrgDomain.find(params[:id])
125+
126+
if @org_domain.org_id != current_user.org_id
127+
redirect_to org_domain_show_path, alert: "Unauthorized"
128+
return
129+
end
130+
131+
if @org_domain.destroy
132+
redirect_to org_domain_show_path, notice: "Domain deleted successfully."
133+
else
134+
redirect_to org_domain_show_path, alert: "Failed to delete domain."
135+
end
136+
end
137+
124138

125139
private
126140

app/views/org_domain/show.html.erb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,20 @@
1717
<td><%= domain.created_at.strftime("%Y-%m-%d %H:%M:%S") %></td>
1818
<td><%= domain.updated_at.strftime("%Y-%m-%d %H:%M:%S") %></td>
1919
<td>
20-
<%= link_to 'Edit', edit_org_domain_path(domain), class: "btn btn-primary" %>
20+
<div class="dropdown">
21+
<button class="btn btn-link dropdown-toggle" type="button" id="actionsDropdown<%= domain.id %>" data-bs-toggle="dropdown" aria-expanded="false">
22+
Select an action
23+
</button>
24+
<ul class="dropdown-menu" aria-labelledby="actionsDropdown<%= domain.id %>">
25+
<li><%= link_to 'Edit', edit_org_domain_path(domain), class: "dropdown-item" %></li>
26+
<li>
27+
<%= link_to 'Delete', org_domain_path(domain),
28+
method: :delete,
29+
data: { confirm: 'Are you sure you want to delete this domain?' },
30+
class: "dropdown-item text-danger" %>
31+
</li>
32+
</ul>
33+
</div>
2134
</td>
2235
</tr>
2336
<% end %>

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208

209209
post 'orgs-by-domain', to: 'org_domain#index'
210210
get 'org_domain/show', to: 'org_domain#show', as: 'org_domain_show'
211-
resources :org_domain, only: [:edit, :update, :new, :create]
211+
resources :org_domain, only: [:edit, :update, :new, :create, :destroy]
212212

213213

214214
namespace :paginable do

0 commit comments

Comments
 (0)