2015-05-30 18:53:14 +03:00
|
|
|
# TODO Needs to work with profiles, not with users
|
2014-09-17 14:23:36 +03:00
|
|
|
module Management
|
|
|
|
class UsersController < ManagementController
|
|
|
|
def index
|
2015-07-26 14:58:56 +03:00
|
|
|
@conference = find_conference
|
|
|
|
@profiles = @conference.participant_profiles
|
2014-09-17 14:23:36 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def toggle_admin
|
2015-07-26 14:58:56 +03:00
|
|
|
@conference = find_conference
|
|
|
|
@user = find_user
|
|
|
|
|
2014-09-17 17:48:46 +03:00
|
|
|
@user.toggle_admin!
|
2015-05-30 16:34:49 +03:00
|
|
|
redirect_to :back
|
2014-09-17 17:48:46 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2015-07-26 14:58:56 +03:00
|
|
|
@conference = find_conference
|
|
|
|
@user = find_user
|
|
|
|
@profile = @user.personal_profile(@conference)
|
2015-07-26 15:58:08 +03:00
|
|
|
|
|
|
|
if not @profile
|
|
|
|
flash[:error] = "No profile, needs to be created"
|
|
|
|
redirect_to action: :edit
|
|
|
|
end
|
2014-09-17 14:23:36 +03:00
|
|
|
end
|
|
|
|
|
2015-05-24 12:28:05 +03:00
|
|
|
def edit
|
2015-07-26 14:58:56 +03:00
|
|
|
@conference = find_conference
|
|
|
|
@user = find_user
|
|
|
|
@profile = @user.personal_profile(@conference)
|
2015-07-26 15:58:08 +03:00
|
|
|
|
|
|
|
# TODO (2015-07-26) Totally not working, can't create new profile properly
|
|
|
|
if not @profile
|
|
|
|
@profile = @user.clone_recent_profile(@conference)
|
|
|
|
end
|
2015-05-24 12:28:05 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-07-26 15:58:08 +03:00
|
|
|
@conference = find_conference
|
|
|
|
@user = find_user
|
2015-05-24 12:28:05 +03:00
|
|
|
|
|
|
|
if @user.update_attributes(user_params)
|
2015-07-26 15:58:08 +03:00
|
|
|
redirect_to [:management, @conference, @user]
|
2015-05-24 12:28:05 +03:00
|
|
|
else
|
|
|
|
render action: 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-25 11:29:22 +03:00
|
|
|
def destroy
|
|
|
|
@user = find_user
|
|
|
|
@user.destroy
|
|
|
|
|
|
|
|
redirect_to action: :index
|
|
|
|
end
|
|
|
|
|
2014-09-17 14:23:36 +03:00
|
|
|
private
|
|
|
|
|
2015-05-10 13:36:29 +03:00
|
|
|
def find_user
|
|
|
|
User.find(params[:id])
|
2014-09-17 14:23:36 +03:00
|
|
|
end
|
2015-05-24 12:28:05 +03:00
|
|
|
|
2015-07-26 14:58:56 +03:00
|
|
|
def find_conference
|
|
|
|
Conference.find(params[:conference_id])
|
|
|
|
end
|
|
|
|
|
2015-05-24 12:28:05 +03:00
|
|
|
def user_params
|
|
|
|
params.require(:user).permit(
|
|
|
|
:email,
|
2015-07-26 15:58:08 +03:00
|
|
|
personal_profiles_attributes: [
|
2015-05-24 12:28:05 +03:00
|
|
|
:picture,
|
|
|
|
:first_name,
|
|
|
|
:last_name,
|
|
|
|
:mobile_phone,
|
|
|
|
:biography,
|
|
|
|
:organisation,
|
|
|
|
:public_email,
|
|
|
|
:github,
|
|
|
|
:twitter,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
end
|
2014-09-17 14:23:36 +03:00
|
|
|
end
|
|
|
|
end
|