Commit 39f389ae authored by Douwe Maan's avatar Douwe Maan

Add invites controller.

parent 90dafe31
...@@ -4,11 +4,11 @@ class ConfirmationsController < Devise::ConfirmationsController ...@@ -4,11 +4,11 @@ class ConfirmationsController < Devise::ConfirmationsController
def after_confirmation_path_for(resource_name, resource) def after_confirmation_path_for(resource_name, resource)
if signed_in?(resource_name) if signed_in?(resource_name)
signed_in_root_path(resource) after_sign_in_path_for(resource)
else else
sign_in(resource) sign_in(resource)
if signed_in?(resource_name) if signed_in?(resource_name)
signed_in_root_path(resource) after_sign_in_path_for(resource)
else else
new_session_path(resource_name) new_session_path(resource_name)
end end
......
class InvitesController < ApplicationController
before_filter :member
respond_to :html
layout 'navless'
def show
end
def accept
if member.accept_invite!(current_user)
case member.source
when Project
project = member.source
source = "project #{project.name_with_namespace}"
path = namespace_project_path(project.namespace, project)
when Group
group = member.source
source = "group #{group.name}"
path = group_path(group)
else
source = "who knows what"
path = dashboard_path
end
redirect_to path, notice: "You have been granted #{member.human_access} access to #{source}."
else
redirect_to :back, alert: "The invite could not be accepted."
end
end
private
def member
return @member if defined?(@member)
@token = params[:id]
if member = Member.find_by_invite_token(@token)
@member = member
else
render_404
end
end
def authenticate_user!
return if current_user
notice = "To accept this invitation, sign in"
notice << " or create an account" if current_application_settings.signup_enabled?
notice << "."
store_location_for :user, request.fullpath
redirect_to new_user_session_path, notice: notice
end
end
...@@ -52,11 +52,18 @@ class Member < ActiveRecord::Base ...@@ -52,11 +52,18 @@ class Member < ActiveRecord::Base
delegate :name, :username, :email, to: :user, prefix: true delegate :name, :username, :email, to: :user, prefix: true
def self.find_by_invite_token(invite_token)
invite_token = Devise.token_generator.digest(self, :invite_token, invite_token)
find_by(invite_token: invite_token)
end
def invite? def invite?
self.invite_token.present? self.invite_token.present?
end end
def accept_invite!(new_user) def accept_invite!(new_user)
return false unless invite?
self.invite_token = nil self.invite_token = nil
self.invite_accepted_at = Time.now.utc self.invite_accepted_at = Time.now.utc
......
%h3.page-title Invitation
%p
You have been invited
- if inviter = @member.created_by
by
= link_to inviter.name, user_url(inviter)
to join
- case @member.source
- when Project
- project = @member.source
project
%strong
= link_to project.name_with_namespace, namespace_project_url(project.namespace, project)
- when Group
- group = @member.source
group
%strong
= link_to group.name, group_url(group)
as #{@member.human_access}.
- if @member.source.users.include?(current_user)
%p
However, you are already a member of this #{@member.source.is_a?(Group) ? "group" : "project"}.
Sign in using a different account to accept the invitation.
- else
.actions
= link_to "Accept invitation", accept_invite_url(@token), method: :post, class: "btn btn-success"
%p
#{@group_member.invite_email}, now known as
#{link_to @group_member.user.name, user_url(@group_member.user)},
has accepted your invitation to join group
= link_to @group.name, group_url(@group)
as #{@group_member.human_access}.
<%= @group_member.invite_email %>, now known as <%= @group_member.user.name %>, has accepted your invitation to join group <%= @group.name %> as <%= @group_member.human_access %>.
<%= group_url(@group) %>
%p
You have been invited
- if inviter = @group_member.created_by
by
= link_to inviter.name, user_url(inviter)
to join group
= link_to @group.name, group_url(@group)
as #{@group_member.human_access}.
%p
= link_to 'Accept invitation', invite_url(@token)
You have been invited <%= "by #{@group_member.created_by.name} " if @group_member.created_by %>to join group <%= @group.name %> as <%= @group_member.human_access %>.
Accept invitation: <%= invite_url(@token) %>
%p
#{@project_member.invite_email}, now known as
#{link_to @project_member.user.name, user_url(@project_member.user)},
has accepted your invitation to join project
= link_to @project.name_with_namespace, namespace_project_url(@project.namespace, @project)
as #{@project_member.human_access}.
<%= @project_member.invite_email %>, now known as <%= @project_member.user.name %>, has accepted your invitation to join project <%= @group.name_with_namespace %> as <%= @project_member.human_access %>.
<%= namespace_project_url(@project.namespace, @project) %>
%p
You have been invited
- if inviter = @project_member.created_by
by
= link_to inviter.name, user_url(inviter)
to join project
= link_to @project.name_with_namespace, namespace_project_url(@project.namespace, @project)
as #{@project_member.human_access}.
%p
= link_to 'Accept invitation', invite_url(@token)
You have been invited <%= "by #{@project_member.created_by.name} " if @project_member.created_by %>to join project <%= @project.name_with_namespace %> as <%= @project_member.human_access %>.
Accept invitation: <%= invite_url(@token) %>
...@@ -53,6 +53,15 @@ Gitlab::Application.routes.draw do ...@@ -53,6 +53,15 @@ Gitlab::Application.routes.draw do
end end
get '/s/:username' => 'snippets#user_index', as: :user_snippets, constraints: { username: /.*/ } get '/s/:username' => 'snippets#user_index', as: :user_snippets, constraints: { username: /.*/ }
#
# Invites
#
resources :invites, only: [:show], constraints: { id: /[A-Za-z0-9_-]+/ } do
member do
post :accept
end
end
# #
# Import # Import
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment