Skip to content
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

Add user membership management to group management #219

Merged
merged 29 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c62f2ee
feat: add ui for adding users to groups
kbroschke Jan 8, 2023
990082c
Merge branch 'dev' into ba/group-add-user
RogerAK Jan 10, 2023
8d1a02e
feat: adding user to group
KiruChaff Jan 10, 2023
71081b7
fix: reverted one line in schema
KiruChaff Jan 10, 2023
56e7636
fix: change route from PUT to PATCH and use field input
TobiPeterG Jan 11, 2023
0054387
fix: fix comments
TobiPeterG Jan 11, 2023
6429ed8
fix: fix rubocop offenses
TobiPeterG Jan 11, 2023
e8ce15e
feat: hide remove user and chat button when user is admin
TobiPeterG Jan 11, 2023
53fb5e9
fix: add_user somewhat works *comments*
KiruChaff Jan 13, 2023
132b087
fix: revert schema
KiruChaff Jan 13, 2023
41372bc
feat: add working remove button
DieKautz Jan 16, 2023
a3f587e
fix: add user through modal
DieKautz Jan 16, 2023
c1d559b
refactor: apply lint suggestion
DieKautz Jan 16, 2023
2bb989d
feat: worked on edit group page
KiruChaff Jan 20, 2023
3c1d706
fix: small refactoring
KiruChaff Jan 20, 2023
5347c50
Merge branch 'dev' into ba/group-add-user
kbroschke Jan 22, 2023
aaf2b72
refactor: remove redundant group admin check
kbroschke Jan 22, 2023
eaad988
fix: add missing div closer
kbroschke Jan 22, 2023
ff4899e
feat: internationalize placeholder email
kbroschke Jan 22, 2023
42860a3
refactor: remove empty line
kbroschke Jan 22, 2023
f4f01f2
refactor: remove another redundant admin check
kbroschke Jan 22, 2023
f700677
refactor: move user managedment to own controller
kbroschke Jan 22, 2023
d2b2e45
fix: refactor German localization
TobiPeterG Jan 25, 2023
5332798
Merge branch 'dev' into ba/group-add-user
TobiPeterG Jan 25, 2023
c822634
fix: show alert when user is not found
TobiPeterG Jan 25, 2023
43c5675
fix: remove unused function
TobiPeterG Jan 25, 2023
dd2fe09
Merge branch 'dev' into ba/group-add-user
DieKautz Jan 27, 2023
bc5eaaa
Update button text in add user modal
kbroschke Jan 29, 2023
9b640c1
Merge branch 'dev' into ba/group-add-user
DieKautz Jan 29, 2023
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
16 changes: 16 additions & 0 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ def leave
end
end


# PATCH /groups/1/add_user or /groups/1/add_user.json
def add_user
respond_to do |format|
group = @group
user = User.where(email: params[:user]).first
DieKautz marked this conversation as resolved.
Show resolved Hide resolved
if Membership.create(user: user, group: group, role: :member)
format.html { redirect_to groups_url, notice: t(:group_update) }
format.json { head :no_content }
else
unprocessable_response(format, redirect: :edit, entity: @group)
end
end
end


private

def assure_signed_in
Expand Down
21 changes: 21 additions & 0 deletions app/views/groups/_modal-add-member.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="modal fade" id="addMemberGroupModal" tabindex="-1" aria-labelledby="addMemberGroupModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header border-0">
<h5 class="modal-title" id="addMemberGroupModalLabel"><%= t(:group_add_member) %></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="<%= t(:cancel) %>"></button>
</div>
<div class="modal-body">
<%= form_with(model: @group, url: group_add_user_path(@group), local: true) do |form| %>
<div>
<%= form.label :user, t(:group_add_member_prompt), class: "form-label" %>
<%= form.text_field :user, placeholder: "[email protected]", class: "form-control" %>

<div class="modal-footer border-0 justify-content-evenly">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><%= t(:cancel) %></button>
<%= form.submit t(:save), :class => "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
</div>
5 changes: 4 additions & 1 deletion app/views/groups/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
</table>

<div class="d-flex justify-content-center">
<%= link_to t(:group_add_member), "", class: "btn btn-secondary mx-1" %>
<button type="button" class="btn btn-secondary mx-1" data-bs-toggle="modal" data-bs-target="#addMemberGroupModal">
<%= t(:group_add_member) %>
</button>
<%= render "modal-add-member", group: @group %>

<button type="button" class="btn btn-primary mx-1" data-bs-toggle="modal" data-bs-target="#deleteGroupModal">
<%= t(:delete_group) %>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/views/groups/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ de:
delete_group: "Gruppe löschen"
leave_group: "Gruppe verlassen"
edit_group: "Gruppe bearbeiten"

group_add_member: "Nutzer hinzufügen"
group_add_member_prompt: "Bitte gib die E-Mail-Adresse des Nutzers ein, den du zur Gruppe hinzufügen möchtest."

group_name : "Gruppenname"
group_name_prompt: "Bitte gib deiner Gruppe einen Namen"
Expand All @@ -28,3 +30,4 @@ de:
group_new: "Die Gruppe wurde erfolgreich erstellt"
group_update: "Die Gruppe wurde erfolgreich aktualisiert"
group_destroy: "Die Gruppe wurde wurde erfolgreich gelöscht"

2 changes: 2 additions & 0 deletions config/locales/views/groups/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ en:
delete_group: "Delete group"
leave_group: "Leave group"
edit_group: "Edit group"

group_add_member: "Add user"
group_add_member_prompt: "Please provide the email address of the user you'd like to add to this group."

group_name : "Groupname"
group_name_prompt: "Please provide a name for your group"
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
resources :groups, except: [:show, :new] do
post :leave
patch :add_user
end
resources :items do
patch :reserve
Expand Down
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@
t.datetime "remember_created_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "provider", limit: 50, default: "", null: false
t.string "uid", limit: 50, default: "", null: false
t.string "full_name", default: "", null: false
t.string "description", default: "", null: false
t.string "provider", limit: 50, default: "", null: false
t.string "uid", limit: 50, default: "", null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
Expand Down