Class: Postnhost::UsersController
Constant Summary
Postnhost::Users::SchemaManageable::USER_SCHEMA_PROFILE_FIELDS, Postnhost::Users::SchemaManageable::USER_SCHEMA_TEXT_FIELDS
SchemaHelper::ARTICLE_TYPES, SchemaHelper::AUTHOR_ALUMNI_TYPES, SchemaHelper::CONTACT_TYPES, SchemaHelper::ORGANIZATION_TYPES, SchemaHelper::POLICY_FIELDS, SchemaHelper::SETTINGS_TEXT_OVERRIDE_FIELDS
Instance Method Summary
collapse
#schema_array_to_multiline, #schema_article_type_options, #schema_author_alumni_type_options, #schema_contact_type_options, #schema_multiline_to_array, #schema_organization_type_options, #schema_policy_fields
Instance Method Details
#create ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'app/controllers/postnhost/users_controller.rb', line 23
def create
@user = Postnhost::User.new(user_params)
if @user.save
redirect_to users_path
else
render :new, status: :unprocessable_content
end
end
|
#destroy ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'app/controllers/postnhost/users_controller.rb', line 61
def destroy
if @user == current_user
redirect_to users_path, alert: "You cannot remove your own account while signed in."
return
end
if @user.pages.exists?
redirect_to users_path, alert: "Author cannot be removed while they own pages. Reassign or remove their pages first."
return
end
Postnhost::User.transaction do
Postnhost::Article.where(user_id: @user.id).update_all(user_id: nil, updated_at: Time.current)
@user.article_authors.delete_all
@user.destroy!
end
redirect_to users_path, notice: "Author was successfully removed. Their articles were kept."
end
|
#edit ⇒ Object
17
|
# File 'app/controllers/postnhost/users_controller.rb', line 17
def edit; end
|
#index ⇒ Object
9
10
11
|
# File 'app/controllers/postnhost/users_controller.rb', line 9
def index
@users = Postnhost::User.order(:name, :email)
end
|
#new ⇒ Object
13
14
15
|
# File 'app/controllers/postnhost/users_controller.rb', line 13
def new
@user = Postnhost::User.new
end
|
#schema_edit ⇒ Object
19
20
21
|
# File 'app/controllers/postnhost/users_controller.rb', line 19
def schema_edit
set_user_schema_editor_state
end
|
#schema_update ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/controllers/postnhost/users_controller.rb', line 41
def schema_update
@schema_locale_keys = user_schema_locale_keys
locale_key = selected_user_schema_locale_key
merged_profile = @user.schema_profile_hash.merge(user_schema_profile_params)
merged_overrides = merge_user_schema_locale_overrides(
@user.schema_locale_overrides_hash,
locale_key,
user_schema_translation_params
)
if @user.update(schema_profile: merged_profile, schema_locale_overrides: merged_overrides)
redirect_to schema_edit_user_path(@user, locale: locale_key), notice: "Author schema was successfully updated."
else
set_user_schema_editor_state
@schema_profile_values = merged_profile
@schema_translation_entries = @schema_translation_entries.merge(user_schema_translation_params.stringify_keys)
render :schema_edit, status: :unprocessable_content
end
end
|
#update ⇒ Object
33
34
35
36
37
38
39
|
# File 'app/controllers/postnhost/users_controller.rb', line 33
def update
if @user.update(user_params)
redirect_to edit_user_path(@user), notice: "Author was successfully updated."
else
render :edit, status: :unprocessable_content
end
end
|