Skip to content

Commit f824c69

Browse files
committed
wip: fix profile proposals controller
1 parent 1c32433 commit f824c69

8 files changed

Lines changed: 176 additions & 24 deletions

File tree

app/cells/decidim/badges/show.erb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="profile__badge-banner">
2+
<%= icon "information-line" %>
3+
<h2>local modification</h2>
4+
<div>
5+
<h2 class="h4"><%= t "decidim.gamification.title" %></h2>
6+
<p>
7+
<%= t "decidim.gamification.description" %>
8+
<%= link_to t("decidim.gamification.all_badges_link"), gamification_badges_path, class: "text-secondary underline" %>
9+
</p>
10+
</div>
11+
</div>
12+
13+
<div class="profile__badge-grid">
14+
<% available_badges.each do |badge| %>
15+
<%= cell "decidim/badge", model, badge: %>
16+
<% end %>
17+
</div>

app/cells/decidim/profile_cell.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def user_tabs
104104

105105
def group_tabs
106106
items = [:members].tap do |keys|
107-
keys.append(:badges, :proposals)
107+
keys.append(:badges, :followers, :proposals)
108108
keys << :conversations if manageable_group?
109109
end
110110
items.map { |key| tab_item(key) }

app/cells/decidim/proposal/show.erb

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h2>app/cells/decidim/proposals/show.erb</h2>
2+
<% proposals.each do |proposal| %>
3+
<h3>title</h3>
4+
<p><%= proposal.title %></p>
5+
<h3>body</h3>
6+
<p><%= proposal.body %></p>
7+
<hr>
8+
<% end %>

app/cells/decidim/proposals_cell.rb

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,26 @@ class ProposalsCell < Decidim::ViewModel
55
include Decidim::CellsPaginateHelper
66
include Decidim::Core::Engine.routes.url_helpers
77
include Decidim::CardHelper
8-
include Decidim::Coauthorable
8+
# include Decidim::Coauthorable
99

1010
def show
1111
render :show
1212
end
1313

1414
def proposals
15-
# @proposals ||= Decidim::Proposals::Proposal.where(component:).joins(:coauthorships)
16-
# .where(decidim_coauthorships: { decidim_author_type: "Decidim::UserBaseEntity" })
17-
# .not_hidden
18-
# .published
19-
# .not_withdrawn
2015
@proposals ||= Decidim::Proposals::Proposal.joins(:coauthorships)
21-
.where("decidim_coauthorships.decidim_user_group_id": user_group.id)
22-
end
23-
24-
def memberships
25-
@memberships ||= case role
26-
when "member"
27-
Decidim::UserGroups::MemberMemberships.for(model).page(params[:page]).per(20)
28-
when "admin"
29-
Decidim::UserGroups::AdminMemberships.for(model).page(params[:page]).per(20)
30-
else
31-
Decidim::UserGroups::AcceptedMemberships.for(model).page(params[:page]).per(20)
32-
end
33-
end
34-
35-
def role
36-
options[:role].to_s
16+
.where(
17+
decidim_coauthorships: {
18+
# decidim_author_type: "Decidim::UserBaseEntity",
19+
decidim_user_group_id: profile_holder.id
20+
}
21+
)
22+
# .with_type(type_key: "proposal")
23+
.not_hidden
24+
.published
25+
.not_withdrawn
26+
# @proposals ||= Decidim::Proposals::Proposal.joins(:coauthorships)
27+
# .where("decidim_coauthorships.decidim_user_group_id": user_group.id)
3728
end
3829
end
3930
end
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# frozen_string_literal: true
2+
3+
module Decidim
4+
# The controller to handle the user's public profile page.
5+
#
6+
# i18n-tasks-use t('decidim.profiles.show.badges')
7+
# i18n-tasks-use t('decidim.profiles.show.groups')
8+
# i18n-tasks-use t('decidim.profiles.show.group_admins')
9+
# i18n-tasks-use t('decidim.profiles.show.group_members')
10+
class ProfilesController < Decidim::ApplicationController
11+
include UserGroups
12+
include Flaggable
13+
include HasProfileBreadcrumb
14+
15+
helper Decidim::Messaging::ConversationHelper
16+
17+
helper_method :profile_holder, :active_content, :context_menu
18+
19+
before_action :ensure_profile_holder
20+
before_action :ensure_profile_holder_is_a_group, only: [:members]
21+
before_action :ensure_profile_holder_is_a_user, only: [:groups, :following]
22+
before_action :ensure_user_not_blocked
23+
24+
def show
25+
return redirect_to profile_members_path if profile_holder.is_a?(Decidim::UserGroup)
26+
27+
redirect_to profile_activity_path(nickname: params[:nickname].downcase)
28+
end
29+
30+
def tooltip
31+
render json: { data: cell("decidim/author", profile_holder.presenter).profile_minicard }
32+
end
33+
34+
def following
35+
@content_cell = "decidim/following"
36+
@title_key = "following"
37+
render :show
38+
end
39+
40+
def followers
41+
@content_cell = "decidim/followers"
42+
@title_key = "followers"
43+
render :show
44+
end
45+
46+
def badges
47+
@content_cell = "decidim/badges"
48+
@title_key = "badges"
49+
render :show
50+
end
51+
52+
def groups
53+
enforce_user_groups_enabled
54+
55+
@content_cell = "decidim/groups"
56+
@title_key = "groups"
57+
render :show
58+
end
59+
60+
def members
61+
enforce_user_groups_enabled
62+
63+
@content_cell = "decidim/members"
64+
@title_key = "members"
65+
render :show
66+
end
67+
68+
def group_admins
69+
enforce_permission_to :manage, :user_group, user_group: profile_holder
70+
71+
@content_cell = "decidim/group_admins"
72+
@title_key = "group_admins"
73+
render :show
74+
end
75+
76+
def group_members
77+
enforce_permission_to :manage, :user_group, user_group: profile_holder
78+
79+
@content_cell = "decidim/group_members"
80+
@title_key = "group_members"
81+
render :show
82+
end
83+
84+
def group_invites
85+
enforce_permission_to :manage, :user_group, user_group: profile_holder
86+
87+
@content_cell = "decidim/group_invites"
88+
@title_key = "group_invites"
89+
render :show
90+
end
91+
92+
def activity
93+
@content_cell = "decidim/user_activity"
94+
@title_key = "activity"
95+
render :show
96+
end
97+
98+
def proposals
99+
enforce_user_groups_enabled
100+
101+
@content_cell = "decidim/proposals"
102+
@title_key = "proposals"
103+
render :show
104+
end
105+
106+
private
107+
108+
def ensure_user_not_blocked
109+
raise ActionController::RoutingError, "Blocked User" if profile_holder&.blocked? && !current_user&.admin?
110+
end
111+
112+
def ensure_profile_holder_is_a_group
113+
raise ActionController::RoutingError, "No user group with the given nickname" unless profile_holder.is_a?(Decidim::UserGroup)
114+
end
115+
116+
def ensure_profile_holder_is_a_user
117+
raise ActionController::RoutingError, "No user with the given nickname" unless profile_holder.is_a?(Decidim::User)
118+
end
119+
120+
def ensure_profile_holder
121+
raise ActionController::RoutingError, "No user or user group with the given nickname" if !profile_holder || profile_holder.nickname.blank?
122+
end
123+
124+
def profile_holder
125+
return if params[:nickname].blank?
126+
127+
@profile_holder ||= Decidim::UserBaseEntity.find_by("nickname = ? AND decidim_organization_id = ?", params[:nickname].downcase, current_organization.id)
128+
end
129+
end
130+
end

config/locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ en:
55
assembly:
66
fields:
77
promoted: "Promoted"
8+
profiles:
9+
show:
10+
proposals: "Proposals"
811
layouts:
912
decidim:
1013
data_consent:

config/routes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
get "/admin_sign_in", to: "decidim/devise/sessions#new"
1717
end
1818

19+
scope "/profiles/:nickname", format: false, constraints: { nickname: %r{[^/]+} } do
20+
get "proposals", to: "decidim/profiles#proposals", as: "profile_proposals"
21+
end
22+
1923
get "/sign_in_redirect/:provider", to: "decidim/omniauth/switch#redirect"
2024

2125
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? || ENV.fetch("ENABLE_LETTER_OPENER", "0") == "1"

0 commit comments

Comments
 (0)