From 94638703017ea3de852fec3e0f3e438e1bb4788c Mon Sep 17 00:00:00 2001 From: w1stler Date: Wed, 18 Jul 2018 20:55:02 +0200 Subject: [PATCH 01/14] [981] Initial commit --- backend/apps/volontulo/views/api.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/backend/apps/volontulo/views/api.py b/backend/apps/volontulo/views/api.py index cacc21b8..13e86876 100644 --- a/backend/apps/volontulo/views/api.py +++ b/backend/apps/volontulo/views/api.py @@ -34,6 +34,7 @@ from apps.volontulo import serializers from apps.volontulo.authentication import CsrfExemptSessionAuthentication from apps.volontulo.lib.email import send_mail +from apps.volontulo.models import Offer from apps.volontulo.models import Organization from apps.volontulo.models import UserProfile from apps.volontulo.serializers import ( @@ -220,6 +221,23 @@ def get_queryset(self): ) return qs.filter(offer_status='published') + @detail_route(methods=['POST'], permission_classes=(IsAuthenticated,)) + # pylint: disable=invalid-name + def join(self, request, pk): + """Endpoint to join offer by current user""" + offer = get_object_or_404(self.get_queryset(), id=pk) + offer.volunteers.add(request.user) + import sys + import ipdb + sys.stdout = sys.__stdout__ + ipdb.set_trace() + message = request.data.get('message') + + return Response(self.serializer_class( + offer, message, + context={'request': request} + ).data, status=201) + class OrganizationViewSet(viewsets.ModelViewSet): From 7ea2f41bc7735909aaa6ff4ea4e675e98ce84b60 Mon Sep 17 00:00:00 2001 From: w1stler Date: Wed, 25 Jul 2018 17:18:17 +0200 Subject: [PATCH 02/14] [981] Removing pdb --- backend/apps/volontulo/views/api.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/backend/apps/volontulo/views/api.py b/backend/apps/volontulo/views/api.py index 13e86876..5a1f5d67 100644 --- a/backend/apps/volontulo/views/api.py +++ b/backend/apps/volontulo/views/api.py @@ -227,14 +227,9 @@ def join(self, request, pk): """Endpoint to join offer by current user""" offer = get_object_or_404(self.get_queryset(), id=pk) offer.volunteers.add(request.user) - import sys - import ipdb - sys.stdout = sys.__stdout__ - ipdb.set_trace() - message = request.data.get('message') return Response(self.serializer_class( - offer, message, + offer, context={'request': request} ).data, status=201) From a20fb14e7359f4cd8ea70608ca9d70033cb66a31 Mon Sep 17 00:00:00 2001 From: OtisRed Date: Wed, 25 Jul 2018 17:46:30 +0200 Subject: [PATCH 03/14] new component --- frontend/package-lock.json | 2 +- frontend/src/app/app.module.ts | 10 ++++- .../offer-detail/offer-detail.component.html | 2 +- .../offer-join-form.component.html | 12 +++++ .../offer-join-form.component.ts | 44 +++++++++++++++++++ 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 frontend/src/app/offers/offer-join-form/offer-join-form.component.html create mode 100644 frontend/src/app/offers/offer-join-form/offer-join-form.component.ts diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 7b2ab750..e43e5d8b 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -5005,7 +5005,7 @@ "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=", "dev": true, "requires": { "brace-expansion": "1.1.8" diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 6e0a8c3d..712e09e5 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -55,6 +55,7 @@ import { ContactResolver } from './resolvers'; import { FormErrorComponent } from './form-error/form-error.component'; import { ContactService } from './contact.service'; import { UserProfileComponent } from './user-profile/user-profile.component'; +import { OfferJoinFormComponent } from "./offers/offer-join-form/offer-join-form.component"; Raven.config(environment.sentryDSN).install(); @@ -166,6 +167,12 @@ const appRoutes: Routes = [ component: UserProfileComponent, canActivate: [LoggedInGuard], }, + { + // adjust the path when component is ready + path: 'offers/:offerSlug/:offerId/join', + component: OfferJoinFormComponent, + // canActivate: [LoggedInGuard], + }, { path: '**', component: RedirectComponent @@ -214,7 +221,8 @@ registerLocaleData(localePl); ContactComponent, FormErrorComponent, OrganizationsListComponent, - UserProfileComponent + UserProfileComponent, + OfferJoinFormComponent, ], imports: [ BrowserModule.withServerTransition({ appId: 'volontulo' }), diff --git a/frontend/src/app/offers/offer-detail/offer-detail.component.html b/frontend/src/app/offers/offer-detail/offer-detail.component.html index edf12d41..78bd80c5 100644 --- a/frontend/src/app/offers/offer-detail/offer-detail.component.html +++ b/frontend/src/app/offers/offer-detail/offer-detail.component.html @@ -63,7 +63,7 @@

Pomagasz już w tej inicjatywie

Możesz pomóc?

Twoja pomoc jest ważna. Potrzebujemy Ciebie!

- Zgłoś się na ten wolontariat
diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.html b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html new file mode 100644 index 00000000..cbca3dda --- /dev/null +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html @@ -0,0 +1,12 @@ +
+
+
+ +
+ +
+
+ + +
+
diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts new file mode 100644 index 00000000..6badac9e --- /dev/null +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts @@ -0,0 +1,44 @@ +import {Component, OnInit} from '@angular/core'; +import {FormBuilder, FormGroup, Validators} from "@angular/forms"; +import {filter, take} from "rxjs/operators"; +import {User} from "../../user"; +import {ActivatedRoute} from "@angular/router"; +import {UserService} from "../../user.service"; +import {AuthService} from "../../auth.service"; + +@Component({ + selector: 'volontulo-offer-join-form', + templateUrl: './offer-join-form.component.html' +}) + +export class OfferJoinFormComponent implements OnInit { + public joinForm: FormGroup = this.fb.group( { + applicant_email: ['', [Validators.required, Validators.email]], + applicant_name: ['', [Validators.required, Validators.minLength(3), Validators.maxLength(150)]], + message: ['', [Validators.required, Validators.minLength(10), Validators.maxLength(2000)]], + phone_no: ['', [Validators.maxLength(20)]], + }); + + constructor( + private route: ActivatedRoute, + private fb: FormBuilder, + private authService: AuthService, + private userService: UserService, + ) {} + + ngOnInit() { + this.authService.user$ + .pipe( + filter(user => user !== null), + take(1), + ) + .subscribe( + (user: User) => { + this.joinForm.controls.applicant_email.setValue(user.email); + this.joinForm.controls.applicant_name.setValue(this.userService.getFullName(user)); + this.joinForm.controls.phone_no.setValue(user.phoneNo); + } + ) + } + +} From 2cf9d227f22d6cadd65b15a8ca90aaed54047b4f Mon Sep 17 00:00:00 2001 From: OtisRed Date: Wed, 25 Jul 2018 21:40:43 +0200 Subject: [PATCH 04/14] prepopulated form --- .../offer-join-form.component.html | 29 ++++++++++++++++--- .../offer-join-form.component.ts | 2 ++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.html b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html index cbca3dda..609bab0a 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.html +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html @@ -1,12 +1,33 @@
- + +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+
- +
+
+
+
+
- - +
diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts index 6badac9e..f20f6a90 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts @@ -19,6 +19,8 @@ export class OfferJoinFormComponent implements OnInit { phone_no: ['', [Validators.maxLength(20)]], }); + public submitEnabled = false; + constructor( private route: ActivatedRoute, private fb: FormBuilder, From 335f1107fff7beff1aa6b8fa5f63eec4a9e3458c Mon Sep 17 00:00:00 2001 From: OtisRed Date: Wed, 25 Jul 2018 22:54:48 +0200 Subject: [PATCH 05/14] linter issues --- frontend/src/app/app.module.ts | 2 +- .../offer-join-form/offer-join-form.component.html | 2 +- .../offer-join-form/offer-join-form.component.ts | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 712e09e5..069ddab5 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -55,7 +55,7 @@ import { ContactResolver } from './resolvers'; import { FormErrorComponent } from './form-error/form-error.component'; import { ContactService } from './contact.service'; import { UserProfileComponent } from './user-profile/user-profile.component'; -import { OfferJoinFormComponent } from "./offers/offer-join-form/offer-join-form.component"; +import { OfferJoinFormComponent } from './offers/offer-join-form/offer-join-form.component'; Raven.config(environment.sentryDSN).install(); diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.html b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html index 609bab0a..6994e88c 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.html +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html @@ -17,7 +17,7 @@
- +
diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts index f20f6a90..d49b3f2c 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts @@ -1,10 +1,10 @@ import {Component, OnInit} from '@angular/core'; -import {FormBuilder, FormGroup, Validators} from "@angular/forms"; -import {filter, take} from "rxjs/operators"; -import {User} from "../../user"; -import {ActivatedRoute} from "@angular/router"; -import {UserService} from "../../user.service"; -import {AuthService} from "../../auth.service"; +import {FormBuilder, FormGroup, Validators} from '@angular/forms'; +import {filter, take} from 'rxjs/operators'; +import {User} from '../../user'; +import {ActivatedRoute} from '@angular/router'; +import {UserService} from '../../user.service'; +import {AuthService} from '../../auth.service'; @Component({ selector: 'volontulo-offer-join-form', From 3fadfbc1cfd9632ed8f03e744c750162f97989ef Mon Sep 17 00:00:00 2001 From: w1stler Date: Wed, 1 Aug 2018 20:37:16 +0200 Subject: [PATCH 06/14] [981] Removing unused import --- backend/apps/volontulo/views/api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/apps/volontulo/views/api.py b/backend/apps/volontulo/views/api.py index 5a1f5d67..1b222de1 100644 --- a/backend/apps/volontulo/views/api.py +++ b/backend/apps/volontulo/views/api.py @@ -34,7 +34,6 @@ from apps.volontulo import serializers from apps.volontulo.authentication import CsrfExemptSessionAuthentication from apps.volontulo.lib.email import send_mail -from apps.volontulo.models import Offer from apps.volontulo.models import Organization from apps.volontulo.models import UserProfile from apps.volontulo.serializers import ( From ae38fa4ca8a5708a313a8856b20d4c68a8582008 Mon Sep 17 00:00:00 2001 From: w1stler Date: Wed, 1 Aug 2018 21:24:37 +0200 Subject: [PATCH 07/14] [981] Initial tests --- .../tests/views/api/offers/test_join.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 backend/apps/volontulo/tests/views/api/offers/test_join.py diff --git a/backend/apps/volontulo/tests/views/api/offers/test_join.py b/backend/apps/volontulo/tests/views/api/offers/test_join.py new file mode 100644 index 00000000..3ec5a9a0 --- /dev/null +++ b/backend/apps/volontulo/tests/views/api/offers/test_join.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +""" +.. module:: test_join +""" + +from rest_framework import status +from rest_framework.test import APITestCase + +from apps.volontulo.tests.views.offers.commons import TestOffersCommons + + +class TestAuthenticatedUserJoinOffer(TestOffersCommons, APITestCase): + + """Tests for REST API's join offer view for authenticated user.""" + + def setUp(self): + """Set up each test.""" + super(TestAuthenticatedUserJoinOffer, self).setUp() + self.client.login(username='admin@example.com', password='123admin') + + def test_user_join_offer_authenticated(self): + """Test offer's delete status for admin user.""" + response = self.client.post('/api/offers/1/join/') + + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + + +class TestNotAuthenticatedUserJoinOffer(TestOffersCommons, APITestCase): + + def test_user_join_offer_not_authenticated(self): + """Test offer's delete status for not logged in user.""" + response = self.client.post('/api/offers/1/join/') + + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) From abed5dfa3d407d3ba1108c69ad80ce2ae27288c3 Mon Sep 17 00:00:00 2001 From: OtisRed Date: Wed, 1 Aug 2018 22:02:09 +0200 Subject: [PATCH 08/14] Working with Radek --- .../offer-join-form.component.html | 10 +++---- .../offer-join-form.component.ts | 27 ++++++++++++++----- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.html b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html index 6994e88c..5c4c0801 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.html +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html @@ -1,5 +1,5 @@
-
+
@@ -18,13 +18,13 @@
-
- -
+
+ +
-
diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts index d49b3f2c..3c89f7a6 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts @@ -1,10 +1,14 @@ import {Component, OnInit} from '@angular/core'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; -import {filter, take} from 'rxjs/operators'; +import {catchError} from 'rxjs/operators'; import {User} from '../../user'; import {ActivatedRoute} from '@angular/router'; import {UserService} from '../../user.service'; import {AuthService} from '../../auth.service'; +import {HttpClient} from "@angular/common/http"; +import {environment} from "../../../environments/environment"; +import { map, mergeMap } from 'rxjs/operators'; +import {of} from "rxjs/observable/of"; @Component({ selector: 'volontulo-offer-join-form', @@ -15,25 +19,24 @@ export class OfferJoinFormComponent implements OnInit { public joinForm: FormGroup = this.fb.group( { applicant_email: ['', [Validators.required, Validators.email]], applicant_name: ['', [Validators.required, Validators.minLength(3), Validators.maxLength(150)]], - message: ['', [Validators.required, Validators.minLength(10), Validators.maxLength(2000)]], + message: ['', [Validators.minLength(10), Validators.maxLength(2000)]], phone_no: ['', [Validators.maxLength(20)]], }); public submitEnabled = false; + public success: null | boolean = null; constructor( private route: ActivatedRoute, private fb: FormBuilder, private authService: AuthService, private userService: UserService, + private httpClient: HttpClient, ) {} ngOnInit() { this.authService.user$ - .pipe( - filter(user => user !== null), - take(1), - ) + .subscribe( (user: User) => { this.joinForm.controls.applicant_email.setValue(user.email); @@ -43,4 +46,16 @@ export class OfferJoinFormComponent implements OnInit { ) } + onSubmit() { + if (this.joinForm.valid) { + console.log(this.joinForm.value) + + this.route.params.pipe( + map(params => params.offerId), + mergeMap(offerId => this.httpClient.post(`${environment.apiRoot}/offers/${offerId}/join`, this.joinForm.value)), + catchError(err => {alert(err); return of(err)})) + .subscribe( + () => {this.success = true}) + } + } } From ff16e0fc646a2e59710435d71271f8fed95ea57e Mon Sep 17 00:00:00 2001 From: OtisRed Date: Wed, 22 Aug 2018 19:20:32 +0200 Subject: [PATCH 09/14] 982 joinOffer added in offersService --- fabfile.py | 3 ++- .../src/app/homepage-offer/offers.service.ts | 4 +++ .../offer-join-form.component.ts | 25 +++++++++++-------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/fabfile.py b/fabfile.py index b1459d05..83a5b629 100644 --- a/fabfile.py +++ b/fabfile.py @@ -298,7 +298,8 @@ def install(): }} location = /o {{ - include uwsgi_params; + include uwsgi_ + params; uwsgi_pass unix:/run/uwsgi/volontulo.sock; }} diff --git a/frontend/src/app/homepage-offer/offers.service.ts b/frontend/src/app/homepage-offer/offers.service.ts index 5a506a6d..c6055ff1 100644 --- a/frontend/src/app/homepage-offer/offers.service.ts +++ b/frontend/src/app/homepage-offer/offers.service.ts @@ -35,4 +35,8 @@ export class OffersService { return this.http.put(`${environment.apiRoot}/offers/${id}/`, offer); } + joinOffer(offer: Offer, id: number) { + return this.http.post(`${environment.apiRoot}/offers/${id}/join`, offer); + } + } diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts index 3c89f7a6..be6eeef0 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts @@ -9,6 +9,9 @@ import {HttpClient} from "@angular/common/http"; import {environment} from "../../../environments/environment"; import { map, mergeMap } from 'rxjs/operators'; import {of} from "rxjs/observable/of"; +import { OffersService } from 'app/homepage-offer/offers.service'; +import {Offer} from "../../homepage-offer/offers.model"; + @Component({ selector: 'volontulo-offer-join-form', @@ -25,18 +28,19 @@ export class OfferJoinFormComponent implements OnInit { public submitEnabled = false; public success: null | boolean = null; + public offerId: number; constructor( - private route: ActivatedRoute, + private activatedRoute: ActivatedRoute, private fb: FormBuilder, private authService: AuthService, private userService: UserService, private httpClient: HttpClient, + private offersService: OffersService, ) {} ngOnInit() { this.authService.user$ - .subscribe( (user: User) => { this.joinForm.controls.applicant_email.setValue(user.email); @@ -44,18 +48,19 @@ export class OfferJoinFormComponent implements OnInit { this.joinForm.controls.phone_no.setValue(user.phoneNo); } ) + + this.activatedRoute.params +// .map(params => params.offerId) + .switchMap(params => this.offerId = params.offerId) + .subscribe() } onSubmit() { if (this.joinForm.valid) { - console.log(this.joinForm.value) - - this.route.params.pipe( - map(params => params.offerId), - mergeMap(offerId => this.httpClient.post(`${environment.apiRoot}/offers/${offerId}/join`, this.joinForm.value)), - catchError(err => {alert(err); return of(err)})) - .subscribe( - () => {this.success = true}) + console.log(this.joinForm.value); + + + this.offersService.joinOffer(this.joinForm.value, this.offerId).subscribe() } } } From 2175008858067c751b5273ffbd5a310e35013a82 Mon Sep 17 00:00:00 2001 From: OtisRed Date: Wed, 22 Aug 2018 19:22:49 +0200 Subject: [PATCH 10/14] 982 minor changes --- .../offer-join-form/offer-join-form.component.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts index be6eeef0..328ff753 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts @@ -1,16 +1,13 @@ import {Component, OnInit} from '@angular/core'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; -import {catchError} from 'rxjs/operators'; -import {User} from '../../user'; +import {HttpClient} from '@angular/common/http'; + import {ActivatedRoute} from '@angular/router'; -import {UserService} from '../../user.service'; import {AuthService} from '../../auth.service'; -import {HttpClient} from "@angular/common/http"; -import {environment} from "../../../environments/environment"; -import { map, mergeMap } from 'rxjs/operators'; -import {of} from "rxjs/observable/of"; -import { OffersService } from 'app/homepage-offer/offers.service'; -import {Offer} from "../../homepage-offer/offers.model"; +import {OffersService} from 'app/homepage-offer/offers.service'; +import {User} from '../../user'; +import {UserService} from '../../user.service'; + @Component({ @@ -50,7 +47,6 @@ export class OfferJoinFormComponent implements OnInit { ) this.activatedRoute.params -// .map(params => params.offerId) .switchMap(params => this.offerId = params.offerId) .subscribe() } From 07bcc6225c870990a01348b903657f7ae7a80baa Mon Sep 17 00:00:00 2001 From: w1stler Date: Wed, 22 Aug 2018 20:15:03 +0200 Subject: [PATCH 11/14] [981] Test fixes --- .../volontulo/tests/views/api/offers/test_join.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/apps/volontulo/tests/views/api/offers/test_join.py b/backend/apps/volontulo/tests/views/api/offers/test_join.py index 3ec5a9a0..e0b4443f 100644 --- a/backend/apps/volontulo/tests/views/api/offers/test_join.py +++ b/backend/apps/volontulo/tests/views/api/offers/test_join.py @@ -20,16 +20,24 @@ def setUp(self): self.client.login(username='admin@example.com', password='123admin') def test_user_join_offer_authenticated(self): - """Test offer's delete status for admin user.""" + """Test offer's created status for admin user.""" response = self.client.post('/api/offers/1/join/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) + def test_user_join_not_existing_offer(self): + """Test offer's 404 status for non existing offer.""" + response = self.client.post('/api/offers/1999999999999/join/') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + class TestNotAuthenticatedUserJoinOffer(TestOffersCommons, APITestCase): + """Tests for REST API's join offer view for not authenitcated user""" + def test_user_join_offer_not_authenticated(self): - """Test offer's delete status for not logged in user.""" + """Test offer's forbidden status for not logged in user.""" response = self.client.post('/api/offers/1/join/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) From 059a33871df8668e36ce20e31a3f76762d16b52d Mon Sep 17 00:00:00 2001 From: OtisRed Date: Wed, 22 Aug 2018 20:36:37 +0200 Subject: [PATCH 12/14] 982 fixing in the fabfile --- fabfile.py | 3 +-- .../offer-join-form/offer-join-form.component.html | 10 +++++++--- .../offer-join-form/offer-join-form.component.ts | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/fabfile.py b/fabfile.py index 4a94c264..710cd438 100644 --- a/fabfile.py +++ b/fabfile.py @@ -298,8 +298,7 @@ def install(): }} location = /o {{ - include uwsgi_ - params; + include uwsgi_params; uwsgi_pass unix:/run/uwsgi/volontulo.sock; }} diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.html b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html index 5c4c0801..08cf3685 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.html +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html @@ -4,22 +4,26 @@
+
-
- -
+
+ +
+
+
+
diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts index 328ff753..c3509266 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts @@ -53,7 +53,8 @@ export class OfferJoinFormComponent implements OnInit { onSubmit() { if (this.joinForm.valid) { - console.log(this.joinForm.value); + this.submitEnabled = true +// console.log(this.joinForm.value); this.offersService.joinOffer(this.joinForm.value, this.offerId).subscribe() From 1a3f1cfdd08f732e1f8db160462b8e02b0f9bb1a Mon Sep 17 00:00:00 2001 From: OtisRed Date: Wed, 29 Aug 2018 22:04:34 +0200 Subject: [PATCH 13/14] 982 working join offer component --- .../src/app/homepage-offer/offers.service.ts | 4 +-- .../offer-join-form.component.html | 22 ++++++------ .../offer-join-form.component.ts | 34 +++++++++++-------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/frontend/src/app/homepage-offer/offers.service.ts b/frontend/src/app/homepage-offer/offers.service.ts index c6055ff1..37b9bc04 100644 --- a/frontend/src/app/homepage-offer/offers.service.ts +++ b/frontend/src/app/homepage-offer/offers.service.ts @@ -35,8 +35,8 @@ export class OffersService { return this.http.put(`${environment.apiRoot}/offers/${id}/`, offer); } - joinOffer(offer: Offer, id: number) { - return this.http.post(`${environment.apiRoot}/offers/${id}/join`, offer); + joinOffer(id: number, message: string) { + return this.http.post(`${environment.apiRoot}/offers/${id}/join/`, {message}, {observe: 'response'}); } } diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.html b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html index 08cf3685..2a55af53 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.html +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.html @@ -1,22 +1,19 @@
- +
+ +
+ +
- - +
- -
- - -
- +
- - +
@@ -28,10 +25,11 @@
-
+ diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts index c3509266..9b7c718c 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts @@ -2,30 +2,29 @@ import {Component, OnInit} from '@angular/core'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {HttpClient} from '@angular/common/http'; -import {ActivatedRoute} from '@angular/router'; +import {ActivatedRoute, NavigationEnd, Router} from '@angular/router'; import {AuthService} from '../../auth.service'; import {OffersService} from 'app/homepage-offer/offers.service'; import {User} from '../../user'; import {UserService} from '../../user.service'; - - @Component({ selector: 'volontulo-offer-join-form', templateUrl: './offer-join-form.component.html' }) export class OfferJoinFormComponent implements OnInit { - public joinForm: FormGroup = this.fb.group( { - applicant_email: ['', [Validators.required, Validators.email]], - applicant_name: ['', [Validators.required, Validators.minLength(3), Validators.maxLength(150)]], + public joinForm: FormGroup = this.fb.group({ + applicant_email: [''], + applicant_name: [''], message: ['', [Validators.minLength(10), Validators.maxLength(2000)]], - phone_no: ['', [Validators.maxLength(20)]], - }); + phone_no: [''], + }); public submitEnabled = false; public success: null | boolean = null; public offerId: number; + public error; constructor( private activatedRoute: ActivatedRoute, @@ -34,7 +33,9 @@ export class OfferJoinFormComponent implements OnInit { private userService: UserService, private httpClient: HttpClient, private offersService: OffersService, - ) {} + private router: Router, + ) { + } ngOnInit() { this.authService.user$ @@ -44,7 +45,7 @@ export class OfferJoinFormComponent implements OnInit { this.joinForm.controls.applicant_name.setValue(this.userService.getFullName(user)); this.joinForm.controls.phone_no.setValue(user.phoneNo); } - ) + ); this.activatedRoute.params .switchMap(params => this.offerId = params.offerId) @@ -53,11 +54,14 @@ export class OfferJoinFormComponent implements OnInit { onSubmit() { if (this.joinForm.valid) { - this.submitEnabled = true -// console.log(this.joinForm.value); + this.submitEnabled = true; - - this.offersService.joinOffer(this.joinForm.value, this.offerId).subscribe() - } + this.offersService.joinOffer(this.offerId, this.joinForm.value.message).subscribe( + response => { + if (response.status === 201) { + this.success = true}}, + () => this.success = false, + ) + } } } From dcf8f2f0c57319566529222603519510ee4af999 Mon Sep 17 00:00:00 2001 From: OtisRed Date: Wed, 5 Sep 2018 21:31:11 +0200 Subject: [PATCH 14/14] routing back to offer details --- frontend/src/app/app.module.ts | 3 +-- .../offers/offer-join-form/offer-join-form.component.ts | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index a793ef68..5cd4d50c 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -168,10 +168,9 @@ const appRoutes: Routes = [ canActivate: [LoggedInGuard], }, { - // adjust the path when component is ready path: 'offers/:offerSlug/:offerId/join', component: OfferJoinFormComponent, - // canActivate: [LoggedInGuard], + canActivate: [LoggedInGuard], }, { path: '**', diff --git a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts index 9b7c718c..d10e3849 100644 --- a/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts +++ b/frontend/src/app/offers/offer-join-form/offer-join-form.component.ts @@ -1,8 +1,9 @@ import {Component, OnInit} from '@angular/core'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {HttpClient} from '@angular/common/http'; +import {Location} from '@angular/common' -import {ActivatedRoute, NavigationEnd, Router} from '@angular/router'; +import {ActivatedRoute} from '@angular/router'; import {AuthService} from '../../auth.service'; import {OffersService} from 'app/homepage-offer/offers.service'; import {User} from '../../user'; @@ -33,7 +34,7 @@ export class OfferJoinFormComponent implements OnInit { private userService: UserService, private httpClient: HttpClient, private offersService: OffersService, - private router: Router, + private location: Location , ) { } @@ -59,8 +60,7 @@ export class OfferJoinFormComponent implements OnInit { this.offersService.joinOffer(this.offerId, this.joinForm.value.message).subscribe( response => { if (response.status === 201) { - this.success = true}}, - () => this.success = false, + this.location.back()}} ) } }