Class: UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/users_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #api_authenticate!, #authenticated_via_token?, #current_project, #expire_revision!, #followed_projects, #no_cache, #oauth_authorize!, #read_revision, #require_login, #return_or_cache_revision!, #revision, #token_authenticate!, #unfurling?, #with_current_project

Methods included from UrlHelper

#feature_path, #link_to_project_feature

Instance Method Details

#createObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/users_controller.rb', line 35

def create
  @user = User.new(user_params)

  if params[:send_invitation]
    User.invite!(params[:user])
  else
    @user.role = @role
    @user.save!
  end

  redirect_to @user, notice: 'User was successfully invited.'

rescue ActiveRecord::RecordInvalid
  flash.now[:error] = @user.errors[:base].join("\n")
  render action: "new"
end

#destroyObject



70
71
72
73
74
75
# File 'app/controllers/users_controller.rb', line 70

def destroy
  @user = User.find(params[:id])
  @user.retire!

  redirect_to users_url
end

#editObject



23
24
25
# File 'app/controllers/users_controller.rb', line 23

def edit
  @user = User.find(params[:id])
end

#indexObject



6
7
8
9
# File 'app/controllers/users_controller.rb', line 6

def index
  @title = "Users"
  @users = User.unretired
end

#inviteObject



28
29
30
31
32
# File 'app/controllers/users_controller.rb', line 28

def invite
  @user = User.find(params[:id])
  @user.invite!
  redirect_to request.referrer, :notice => "#{@user.name} has been invited to use this program"
end

#newObject



18
19
20
# File 'app/controllers/users_controller.rb', line 18

def new
  @user = User.new
end

#showObject



12
13
14
15
# File 'app/controllers/users_controller.rb', line 12

def show
  @user = User.find(params[:id])
  @title = @user.name
end

#updateObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/users_controller.rb', line 53

def update
  @user = User.find(params[:id])
  @user.role = @role

  attributes = params[:user]
  attributes[:alias_emails] = attributes.fetch(:alias_emails, "").split.map(&:strip)
  @user.props.merge! attributes.delete(:props) if attributes.key?(:props)

  if @user.update_attributes(attributes)
    redirect_to @user, notice: 'User was successfully updated.'
  else
    flash.now[:error] = @user.errors[:base].join("\n")
    render action: "edit"
  end
end