Allow admins to add and remove invitations per account
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		
							parent
							
								
									ca238be6f4
								
							
						
					
					
						commit
						f3159d30f1
					
				| @ -5,7 +5,9 @@ | |||||||
|       } : nil do %> |       } : nil do %> | ||||||
|   <div class="flex flex-col"> |   <div class="flex flex-col"> | ||||||
|     <label class="font-bold mb-1"><%= @title %></label> |     <label class="font-bold mb-1"><%= @title %></label> | ||||||
|  |     <% if @description.present? %> | ||||||
|     <p class="text-gray-500"><%= @descripton %></p> |     <p class="text-gray-500"><%= @descripton %></p> | ||||||
|  |     <% end %> | ||||||
|   </div> |   </div> | ||||||
|   <div class="relative ml-4 inline-flex flex-shrink-0"> |   <div class="relative ml-4 inline-flex flex-shrink-0"> | ||||||
|     <%= render FormElements::ToggleComponent.new( |     <%= render FormElements::ToggleComponent.new( | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ | |||||||
| module FormElements | module FormElements | ||||||
|   class FieldsetToggleComponent < ViewComponent::Base |   class FieldsetToggleComponent < ViewComponent::Base | ||||||
|     def initialize(tag: "li", form: nil, attribute: nil, field_name: nil, |     def initialize(tag: "li", form: nil, attribute: nil, field_name: nil, | ||||||
|                    enabled: false, input_enabled: true, title:, description:) |                    enabled: false, input_enabled: true, title:, description: nil) | ||||||
|       @tag = tag |       @tag = tag | ||||||
|       @form = form |       @form = form | ||||||
|       @attribute = attribute |       @attribute = attribute | ||||||
|  | |||||||
| @ -1,7 +1,8 @@ | |||||||
| class Admin::UsersController < Admin::BaseController | class Admin::UsersController < Admin::BaseController | ||||||
|   before_action :set_user, only: [:show] |   before_action :set_user, except: [:index] | ||||||
|   before_action :set_current_section |   before_action :set_current_section | ||||||
| 
 | 
 | ||||||
|  |   # GET /admin/users | ||||||
|   def index |   def index | ||||||
|     ldap   = LdapService.new |     ldap   = LdapService.new | ||||||
|     @ou    = Setting.primary_domain |     @ou    = Setting.primary_domain | ||||||
| @ -13,6 +14,7 @@ class Admin::UsersController < Admin::BaseController | |||||||
|     } |     } | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   # GET /admin/users/:username | ||||||
|   def show |   def show | ||||||
|     if Setting.lndhub_admin_enabled? |     if Setting.lndhub_admin_enabled? | ||||||
|       @lndhub_user = @user.lndhub_user |       @lndhub_user = @user.lndhub_user | ||||||
| @ -23,6 +25,30 @@ class Admin::UsersController < Admin::BaseController | |||||||
|     @avatar = LdapManager::FetchAvatar.call(cn: @user.cn) |     @avatar = LdapManager::FetchAvatar.call(cn: @user.cn) | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   # POST /admin/users/:username/invitations | ||||||
|  |   def create_invitations | ||||||
|  |     amount = params[:amount].to_i | ||||||
|  |     notify_user = ActiveRecord::Type::Boolean.new.cast(params[:notify_user]) | ||||||
|  | 
 | ||||||
|  |     CreateInvitations.call(user: @user, amount: amount, notify: notify_user) | ||||||
|  | 
 | ||||||
|  |     redirect_to admin_user_path(@user.cn), flash: { | ||||||
|  |       success: "Added #{amount} invitations to #{@user.cn}'s account" | ||||||
|  |     } | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|  |   # DELETE /admin/users/:username/invitations | ||||||
|  |   def delete_invitations | ||||||
|  |     invitations = @user.invitations.unused | ||||||
|  |     amount = invitations.count | ||||||
|  | 
 | ||||||
|  |     invitations.destroy_all | ||||||
|  | 
 | ||||||
|  |     redirect_to admin_user_path(@user.cn), flash: { | ||||||
|  |       success: "Removed #{amount} invitations from #{@user.cn}'s account" | ||||||
|  |     } | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|   private |   private | ||||||
| 
 | 
 | ||||||
|   def set_user |   def set_user | ||||||
|  | |||||||
							
								
								
									
										21
									
								
								app/views/admin/users/_create_invitations.html.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								app/views/admin/users/_create_invitations.html.erb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,21 @@ | |||||||
|  | <h3>Add new invitations to <%= @user.cn %>'s account</h3> | ||||||
|  | <%= form_with(url: invitations_admin_user_path, method: :post) do |form| %> | ||||||
|  |   <ul role="list"> | ||||||
|  |     <%= render FormElements::FieldsetComponent.new( | ||||||
|  |       positioning: :horizontal, | ||||||
|  |       title: "Amount" | ||||||
|  |     ) do %> | ||||||
|  |       <%= form.select :amount, options_for_select([ | ||||||
|  |         ["3", "3"], ["5", "5"], ["10", "10"], ["20", "20"] | ||||||
|  |       ]) %> | ||||||
|  |     <% end %> | ||||||
|  |     <%= render FormElements::FieldsetToggleComponent.new( | ||||||
|  |       field_name: "notify_user", | ||||||
|  |       enabled: true, | ||||||
|  |       title: "Notify user via email" | ||||||
|  |     ) %> | ||||||
|  |   </ul> | ||||||
|  |   <p class="pt-6 border-t border-gray-200 text-right"> | ||||||
|  |     <%= form.submit 'Add', class: "btn-md btn-blue w-full" %> | ||||||
|  |   </p> | ||||||
|  | <% end %> | ||||||
| @ -42,27 +42,33 @@ | |||||||
|           </tr> |           </tr> | ||||||
|           <tr> |           <tr> | ||||||
|             <th>Invitations available</th> |             <th>Invitations available</th> | ||||||
|             <td> |             <td data-controller="modal" data-action="keydown.esc->modal#close"> | ||||||
|               <div class="flex justify-between"> |               <div class="flex justify-between"> | ||||||
|                 <span> |                 <span> | ||||||
|                   <%= @user.invitations.count %> |                   <%= @user.invitations.count %> | ||||||
|                 </span> |                 </span> | ||||||
|                 <span> |                 <span> | ||||||
|                   <%= render DropdownComponent.new(size: :small, icon_name: "edit") do %> |                   <button data-action="click->modal#open"> | ||||||
|                     <%= render DropdownLinkComponent.new( |                     <%= render partial: "icons/plus-circle", locals: { | ||||||
|                           href: "" |                       custom_class: "text-green-600 hover:text-green-500 -mt-2 -mb-1 h-6 w-6 inline-block" | ||||||
|                         ) do %> |                     } %> | ||||||
|                       Add more |                   </button> | ||||||
|                     <% end %> |                     <% if @user.invitations.unused.count > 0 %> | ||||||
|                     <%= render DropdownLinkComponent.new( |                       <%= link_to invitations_admin_user_path(@user.cn), data: { | ||||||
|                           href: "", |                             turbo_method: :delete, | ||||||
|                           separator: true, add_class: "text-red-700" |                             turbo_confirm: "Delete all of #{@user.cn}'s available invitations?" | ||||||
|                         ) do %> |                           } do %> | ||||||
|                       Remove all |                         <%= render partial: "icons/x-circle", locals: { | ||||||
|  |                           custom_class: "text-red-600 hover:text-red-500 -mt-2 -mb-1 h-6 w-6 inline-block" | ||||||
|  |                         } %> | ||||||
|                     <% end %> |                     <% end %> | ||||||
|                   <% end %> |                   <% end %> | ||||||
|                 </span> |                 </span> | ||||||
|               </div> |               </div> | ||||||
|  |               <%= render ModalComponent.new(show_close_button: false) do %> | ||||||
|  |                 <%= render partial: "admin/users/create_invitations", | ||||||
|  |                            locals: { user: @user } %> | ||||||
|  |               <% end %> | ||||||
|             </td> |             </td> | ||||||
|           </tr> |           </tr> | ||||||
|           <tr> |           <tr> | ||||||
|  | |||||||
| @ -1 +1 @@ | |||||||
| <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-plus-circle"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="16"></line><line x1="8" y1="12" x2="16" y2="12"></line></svg> | <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-plus-circle <%= custom_class %>"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="16"></line><line x1="8" y1="12" x2="16" y2="12"></line></svg> | ||||||
|  | |||||||
| Before Width: | Height: | Size: 351 B After Width: | Height: | Size: 372 B | 
| @ -1 +1 @@ | |||||||
| <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x-circle"><circle cx="12" cy="12" r="10"></circle><line x1="15" y1="9" x2="9" y2="15"></line><line x1="9" y1="9" x2="15" y2="15"></line></svg> | <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x-circle <%= custom_class %>"><circle cx="12" cy="12" r="10"></circle><line x1="15" y1="9" x2="9" y2="15"></line><line x1="9" y1="9" x2="15" y2="15"></line></svg> | ||||||
|  | |||||||
| Before Width: | Height: | Size: 346 B After Width: | Height: | Size: 367 B | 
| @ -74,8 +74,13 @@ Rails.application.routes.draw do | |||||||
|     root to: 'dashboard#index' |     root to: 'dashboard#index' | ||||||
| 
 | 
 | ||||||
|     resources 'users', param: 'username', only: ['index', 'show'] do |     resources 'users', param: 'username', only: ['index', 'show'] do | ||||||
| 
 |       member do | ||||||
|  |         post 'invitations', to: 'users#create_invitations' | ||||||
|  |         delete 'invitations', to: 'users#delete_invitations' | ||||||
|       end |       end | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|  |     # post 'users/:username/invitations', to: 'users#create_invitations' | ||||||
| 
 | 
 | ||||||
|     get 'invitations', to: 'invitations#index' |     get 'invitations', to: 'invitations#index' | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user