Skip to content

Commit

Permalink
Self host invite links
Browse files Browse the repository at this point in the history
  • Loading branch information
Shpigford committed Nov 1, 2024
1 parent 3b83785 commit 801a272
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/controllers/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def create
@invitation.inviter = Current.user

if @invitation.save
InvitationMailer.invite_email(@invitation).deliver_later
InvitationMailer.invite_email(@invitation).deliver_later unless self_hosted?
flash[:notice] = t(".success")
else
flash[:alert] = t(".failure")
Expand Down
5 changes: 4 additions & 1 deletion app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def set_expiration
end

def inviter_is_admin
inviter.admin?
unless inviter.admin?
errors.add(:role, "can only be set to member for non-admin inviters")
self.role = "member"
end
end
end
36 changes: 29 additions & 7 deletions app/views/settings/profiles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,36 @@
<% end %>
<% if @pending_invitations.any? %>
<% @pending_invitations.each do |invitation| %>
<div class="flex gap-2 items-center bg-white p-4 border border-alpha-black-25 rounded-lg">
<div class="w-9 h-9 shrink-0">
<div class="text-white w-full h-full bg-gray-400 rounded-full flex items-center justify-center text-lg uppercase"><%= invitation.email[0] %></div>
</div>
<p class="text-gray-900 font-medium text-sm"><%= invitation.email %></p>
<div class="rounded-md bg-gray-100 px-1.5 py-0.5">
<p class="uppercase text-gray-500 font-medium text-xs"><%= t(".pending") %></p>
<div class="flex gap-2 items-center justify-between bg-white p-4 border border-alpha-black-25 rounded-lg">
<div class="flex gap-2 items-center">
<div class="w-9 h-9 shrink-0">
<div class="text-white w-full h-full bg-gray-400 rounded-full flex items-center justify-center text-lg uppercase"><%= invitation.email[0] %></div>
</div>
<div class="flex">
<p class="text-gray-900 font-medium text-sm"><%= invitation.email %></p>
<div class="rounded-md bg-gray-100 px-1.5 py-0.5">
<p class="uppercase text-gray-500 font-medium text-xs"><%= t(".pending") %></p>
</div>
</div>
</div>
<% if self_hosted? %>
<div class="flex items-center gap-2" data-controller="clipboard">
<p class="text-gray-500 text-sm"><%= t(".invitation_link") %></p>
<span data-clipboard-target="source" class="hidden"><%= accept_invitation_url(invitation.token) %></span>
<input type="text"
readonly
value="<%= accept_invitation_url(invitation.token) %>"
class="text-sm bg-gray-50 px-2 py-1 rounded border border-gray-200 w-72">
<button data-action="clipboard#copy" class="text-gray-500 hover:text-gray-700">
<span data-clipboard-target="iconDefault">
<%= lucide_icon "copy", class: "w-5 h-5" %>
</span>
<span class="hidden" data-clipboard-target="iconSuccess">
<%= lucide_icon "check", class: "w-5 h-5" %>
</span>
</button>
</div>
<% end %>
</div>
<% end %>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/views/settings/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ en:
profile_title: Profile
save: Save
pending: Pending
invitation_link: Invitation link
user_avatar_field:
accepted_formats: JPG or PNG. 5MB max.
choose: Choose

0 comments on commit 801a272

Please sign in to comment.