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

Release 2024-07-29 #8503

Merged
merged 22 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6396024
Add new volunteering permissions action
luucvanderzee Jul 8, 2024
5bd8a6f
Merge branch 'TAN-2183-event-action_luuc' into TAN-2209-volunteering-…
luucvanderzee Jul 9, 2024
63b4c14
Create failing test for volunteers spec
luucvanderzee Jul 9, 2024
e2cb86c
Make sure volunteering phases in acceptance tests are active
luucvanderzee Jul 9, 2024
31e92e4
_
luucvanderzee Jul 9, 2024
7bb15c9
_
luucvanderzee Jul 9, 2024
d6bc913
Hopefully fix all tests now
luucvanderzee Jul 9, 2024
3c46202
Remove comment
luucvanderzee Jul 9, 2024
3f3b4e1
_
luucvanderzee Jul 9, 2024
60a1988
Add disabled reason
luucvanderzee Jul 10, 2024
64c5d72
Trigger auth flow with correct context on click volunteer button
luucvanderzee Jul 10, 2024
d49abd6
Use action descriptor to control behavior volunteering button instead…
luucvanderzee Jul 10, 2024
cf88a07
Revert changes to DB structure
luucvanderzee Jul 10, 2024
c31298e
Remove redundant user creation in spec
luucvanderzee Jul 17, 2024
98612d0
Fix example descriptions
luucvanderzee Jul 17, 2024
4606f9b
Add volunteering disabled reason messages
luucvanderzee Jul 17, 2024
5873774
Add custom message in volunteering tooltip
luucvanderzee Jul 17, 2024
24a23ac
Merge branch 'master' into TAN-2209-volunteering-permissions
luucvanderzee Jul 26, 2024
7555810
Merge pull request #8405 from CitizenLabDotCo/TAN-2209-volunteering-p…
luucvanderzee Jul 29, 2024
6752d37
Fix linter
luucvanderzee Jul 29, 2024
692d98c
Translations updated by CI (extract-intl)
Jul 29, 2024
2529db3
Merge pull request #8504 from CitizenLabDotCo/fix-tests
luucvanderzee Jul 29, 2024
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
2 changes: 1 addition & 1 deletion back/app/models/permission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Permission < ApplicationRecord
'survey' => %w[taking_survey attending_event],
'poll' => %w[taking_poll attending_event],
'voting' => %w[voting commenting_idea attending_event],
'volunteering' => %w[attending_event],
'volunteering' => %w[volunteering attending_event],
'document_annotation' => %w[annotating_document attending_event]
}
SCOPE_TYPES = [nil, 'Phase'].freeze
Expand Down
1 change: 1 addition & 0 deletions back/app/services/permissions/base_permissions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BasePermissionsService
taking_survey
taking_poll
attending_event
volunteering
].freeze

USER_DENIED_REASONS = {
Expand Down
12 changes: 12 additions & 0 deletions back/app/services/permissions/phase_permissions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class PhasePermissionsService < BasePermissionsService
already_responded: 'already_responded'
}.freeze

VOLUNTEERING_DENIED_REASONS = {
not_volunteering: 'not_volunteering'
}.freeze

def initialize(phase, user, user_requirements_service: nil)
super(user, user_requirements_service: user_requirements_service)
@phase ||= phase
Expand All @@ -63,6 +67,8 @@ def denied_reason_for_action(action, reaction_mode: nil)
taking_survey_denied_reason_for_action
when 'taking_poll'
taking_poll_denied_reason_for_action
when 'volunteering'
volunteering_denied_reason_for_phase
else
raise "Unsupported action: #{action}" unless SUPPORTED_ACTIONS.include?(action)
end
Expand Down Expand Up @@ -136,6 +142,12 @@ def voting_denied_reason_for_action
end
end

def volunteering_denied_reason_for_phase
unless phase.volunteering?
VOLUNTEERING_DENIED_REASONS[:not_volunteering]
end
end

# Helper methods

def posting_limit_reached?
Expand Down
6 changes: 6 additions & 0 deletions back/app/services/permissions/project_permissions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def action_descriptors
taking_poll_disabled_reason = denied_reason_for_action 'taking_poll'
voting_disabled_reason = denied_reason_for_action 'voting'
attending_event_disabled_reason = denied_reason_for_action 'attending_event'
volunteering_disabled_reason = denied_reason_for_action 'volunteering'

{
posting_idea: {
enabled: !posting_disabled_reason,
Expand Down Expand Up @@ -81,6 +83,10 @@ def action_descriptors
attending_event: {
enabled: !attending_event_disabled_reason,
disabled_reason: attending_event_disabled_reason
},
volunteering: {
enabled: !volunteering_disabled_reason,
disabled_reason: volunteering_disabled_reason
}
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
before_all do
# 2020
past_project = create(:project)
create(:phase, project: past_project, start_at: Date.new(2020, 2, 1), end_at: Date.new(2020, 3, 1))
create(
:phase,
project: past_project,
start_at: Date.new(2020, 2, 1),
end_at: Date.new(2020, 3, 1),
with_permissions: true
)

# 2021
@project1 = create(:project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ def index_xlsx?
end

def create?
user&.active? &&
(record.user_id == user.id) &&
ProjectPolicy.new(user, record.cause.phase.project).show?
return false unless user&.active?
return false unless record.user_id == user.id

project = record.cause.phase.project
service = Permissions::ProjectPermissionsService.new(project, user)
reason = service.denied_reason_for_action('volunteering')
return false if reason

ProjectPolicy.new(user, record.cause.phase.project).show?
end

def destroy?
Expand Down
56 changes: 54 additions & 2 deletions back/engines/free/volunteering/spec/acceptance/volunteers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
post 'web_api/v1/causes/:cause_id/volunteers' do
ValidationErrorHelper.new.error_fields(self, Volunteering::Volunteer)

let(:cause) { create(:cause) }
let(:cause) do
create(
:cause,
phase: create(
:volunteering_phase,
start_at: 6.months.ago,
end_at: nil
)
)
end

let(:cause_id) { cause.id }

example_request 'Create a volunteer with the current user' do
Expand All @@ -31,10 +41,52 @@
do_request
assert_status 422
end

context 'when the phase has granular permissions' do
let(:group) { create(:group) }

let(:project) do
create(
:single_phase_volunteering_project,
phase_attrs: { with_permissions: true }
)
end

let(:cause) do
cause = create(:cause, phase: project.phases.first)
permission = cause.phase.permissions.find_by(action: 'volunteering')
permission.update!(permitted_by: 'groups', groups: [group])

cause
end

let(:cause_id) { cause.id }

example 'Try to volunteer for a cause, not as a group member', document: false do
do_request
assert_status 401
end

example 'Try to volunteer for a cause, as a group member', document: false do
group.add_member(@user).save!
do_request
assert_status 201
end
end
end

delete 'web_api/v1/causes/:cause_id/volunteers' do
let(:cause) { create(:cause) }
let(:cause) do
create(
:cause,
phase: create(
:volunteering_phase,
start_at: 6.months.ago,
end_at: nil
)
)
end

let(:cause_id) { cause.id }
let!(:volunteer) { create(:volunteer, user: @user, cause: cause) }

Expand Down
3 changes: 2 additions & 1 deletion back/spec/acceptance/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@
taking_survey: { enabled: false, disabled_reason: 'project_inactive' },
taking_poll: { enabled: false, disabled_reason: 'project_inactive' },
voting: { enabled: false, disabled_reason: 'project_inactive' },
attending_event: { enabled: false, disabled_reason: 'project_inactive' }
attending_event: { enabled: false, disabled_reason: 'project_inactive' },
volunteering: { enabled: false, disabled_reason: 'project_inactive' }
}
)
expect(json_response.dig(:data, :relationships)).to include(
Expand Down
3 changes: 2 additions & 1 deletion front/app/api/permissions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export type IPhasePermissionAction =
| 'taking_poll'
| 'voting'
| 'annotating_document'
| 'attending_event';
| 'attending_event'
| 'volunteering';

export interface IPhasePermissionData {
id: string;
Expand Down
12 changes: 12 additions & 0 deletions front/app/api/projects/__mocks__/_mockServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export const project1: IProjectData = {
enabled: true,
disabled_reason: null,
},
volunteering: {
enabled: false,
disabled_reason: 'not_volunteering',
},
},
avatars_count: 8,
participants_count: 8,
Expand Down Expand Up @@ -211,6 +215,10 @@ export const project2: IProjectData = {
enabled: true,
disabled_reason: null,
},
volunteering: {
enabled: false,
disabled_reason: 'not_volunteering',
},
},
avatars_count: 6,
participants_count: 6,
Expand Down Expand Up @@ -345,6 +353,10 @@ const votingProject: IProject = {
enabled: false,
disabled_reason: 'not_poll',
},
volunteering: {
enabled: false,
disabled_reason: 'not_volunteering',
},
},
avatars_count: 2,
participants_count: 2,
Expand Down
2 changes: 2 additions & 0 deletions front/app/api/projects/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ProjectReactingDisabledReason,
ProjectSurveyDisabledReason,
ProjectVotingDisabledReason,
ProjectVolunteeringDisabledReason,
} from 'utils/actionDescriptors/types';
import { Keys } from 'utils/cl-react-query/types';

Expand Down Expand Up @@ -99,6 +100,7 @@ export interface IProjectAttributes {
annotating_document: ActionDescriptor<ProjectDocumentAnnotationDisabledReason>;
voting: ActionDescriptor<ProjectVotingDisabledReason>;
attending_event: ActionDescriptor<ProjectDisabledReason>;
volunteering: ActionDescriptor<ProjectVolunteeringDisabledReason>;
};
uses_content_builder: boolean;
}
Expand Down
2 changes: 0 additions & 2 deletions front/app/components/FormBuilder/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ export const getIsPostingEnabled = (
return false;
};



export function generateTempId() {
return `TEMP-ID-${uuid4()}`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const PagesMenu = () => {
return null;
}

const disabledAddProjectToNavbarButton = navbarItems.data.length >= MAX_NAVBAR_ITEMS;
const disabledAddProjectToNavbarButton =
navbarItems.data.length >= MAX_NAVBAR_ITEMS;

return (
<SectionFormWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const ideationConfig: FormBuilderConfig = {
},
};


export const proposalsConfig: FormBuilderConfig = {
formBuilderTitle: messages.inputForm,
viewFormLinkCopy: messages.viewFormLinkCopy,
Expand All @@ -55,7 +54,7 @@ export const proposalsConfig: FormBuilderConfig = {

toolboxFieldsToExclude: ['page', 'file_upload', 'point'],
displayBuiltInFields: true,
builtInFields:[
builtInFields: [
'title_multiloc',
'body_multiloc',
'topic_ids',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export default defineMessages({
id: 'app.containers.AdminPage.groups.permissions.permissionAction_attending_event_subtitle',
defaultMessage: 'Who can sign up to attend an event?',
},
permissionAction_volunteering_subtitle: {
id: 'app.containers.AdminPage.groups.permissions.permissionAction_volunteering_subtitle',
defaultMessage: 'Who can volunteer?',
},
phase: {
id: 'app.containers.AdminPage.groups.permissions.phase',
defaultMessage: 'Phase ',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const getPermissionActionSectionSubtitle = ({
annotating_document:
messages.permissionAction_annotating_document_subtitle,
attending_event: messages.permissionAction_attending_event_subtitle,
volunteering: messages.permissionAction_volunteering_subtitle,
};
return participationContextPermissionActionMessages[permissionAction];
}
Expand Down
4 changes: 4 additions & 0 deletions front/app/containers/Admin/projects/project/phase/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export default defineMessages({
id: 'app.components.app.containers.AdminPage.ProjectEdit.phaseHeader.attendingEvent',
defaultMessage: '<b>Attending event:</b> {participants}',
},
volunteering: {
id: 'app.components.app.containers.AdminPage.ProjectEdit.phaseHeader.volunteering',
defaultMessage: '<b>Volunteering:</b> {participants}',
},
and: {
id: 'app.components.app.containers.AdminPage.ProjectEdit.phaseHeader.and',
defaultMessage: 'and',
Expand Down
2 changes: 2 additions & 0 deletions front/app/containers/Admin/projects/project/phase/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export const getParticipationActionLabel = (action: IPhasePermissionAction) => {
return messages.annotatingDocument;
case 'attending_event':
return messages.attendingEvent;
case 'volunteering':
return messages.volunteering;
}
};

Expand Down
Loading