Skip to content

[FIX] Manage users bugs #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ def resource_not_found
render 'errors/not_found', status: 404
end

def member_should_be_active
if !current_member.active
def member_should_exist_and_be_active
if !current_member
redirect_to organizations_path
elsif !current_member.active
flash[:error] = I18n.t('users.index.account_deactivated')
redirect_to select_organization_path
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class TagsController < ApplicationController
before_action :authenticate_user!, :member_should_be_active
before_action :authenticate_user!, :member_should_exist_and_be_active

def index
model = params[:model].classify.constantize
Expand Down
11 changes: 7 additions & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class UsersController < ApplicationController
before_action :authenticate_user!, :member_should_be_active, except: [:signup, :create]
before_action :authenticate_user!, except: %i[signup create]
before_action :member_should_exist_and_be_active, except: %i[signup create edit show update]

has_scope :tagged_with, as: :tag

Expand All @@ -16,6 +17,8 @@ def manage

def show
@user = find_user
redirect_to edit_user_path(@user) and return if !current_organization

@member = @user.as_member_of(current_organization)
@movements = @member.movements.order("created_at DESC").page(params[:page]).
per(10)
Expand Down Expand Up @@ -57,11 +60,11 @@ def create
end

def update
@user = scoped_users.find(params[:id])
authorize @user
@user = User.find(params[:id])
authorize @user unless @user == current_user

if @user.update(user_params)
@user.add_tags(current_organization, params[:tag_list] || [])
@user.add_tags(current_organization, params[:tag_list] || []) if current_organization

redirect_to @user
else
Expand Down
21 changes: 12 additions & 9 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@
include_blank: :true %>
<%= f.input :description, as: "text" %>
<%= f.input :postcode %>
<%= label_tag :tag_list, t('activerecord.attributes.post.tag_list') %>
<div class='form-group'>
<%= select_tag :tag_list,
options_for_select(member.tags, member.tags),
multiple: true,
data: { placeholder: t("application.tips.entertag"), model: "member" },
id: "tags-js",
class: "form-control" %>
</div>

<% if current_organization %>
<%= label_tag :tag_list, t('activerecord.attributes.post.tag_list') %>
<div class='form-group'>
<%= select_tag :tag_list,
options_for_select(member.tags, member.tags),
multiple: true,
data: { placeholder: t("application.tips.entertag"), model: "member" },
id: "tags-js",
class: "form-control" %>
</div>
<% end %>

<div class='form-group'>
<label><%= t('.notifications') %></label>
Expand Down