Skip to content

Commit

Permalink
fix: dont allow crowdsourced users to start a study if its closed
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoalee committed Apr 9, 2024
1 parent 056ceaa commit c750fe7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, isDevMode } from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';
import { Role, SupportedLangs } from 'src/app/models/enums';
import { User } from 'src/app/models/User';
Expand Down Expand Up @@ -38,7 +38,7 @@ export class CreateUserDialogComponent implements OnInit {
createdAt: null,
email: this.newUserEmail,
role: this.newUserRole === Role.ORGANIZATION_MEMBER ? Role.ORGANIZATION_MEMBER : Role.GUEST,
changePasswordRequired: false,
changePasswordRequired: !isDevMode(), // we should require the user to change their password on first login
password: 'password',
lang: SupportedLangs.EN,
organization: this.userStateService.userOrganization,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ManageUsersComponent implements OnInit, OnDestroy {
(_data) => {
this.loaderService.hideLoader();
// this.userService.updateGuests();
this.snackbarService.openSuccessSnackbar('Successfully created new guest');
this.snackbarService.openSuccessSnackbar('Successfully created added new user');
},
(err: HttpStatus) => {
this.loaderService.hideLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h3>Favorites</h3>
<span class="title badge">OWNER </span>
</div>
<div>
<span class="internal-name">{{ study.owner.name }}</span>
<span class="internal-name">{{ study.owner.name || study.owner.id }}</span>
</div>

<div>
Expand Down Expand Up @@ -167,14 +167,23 @@ <h3>Favorites</h3>
</div>

<div class="d-flex my-3" style="justify-content: space-between">
<button
(click)="handlePreviewStudy(study.id)"
class="w-25 mx-2"
color="accent"
mat-raised-button
>
Preview study
</button>

<button (click)="handleViewData(study)" class="w-25" mat-raised-button [disabled]="isGuest">
See data
</button>

<button
[disabled]="!canEditStudy(study.owner)"
(click)="handleEdit(study)"
class="w-25"
class="w-25 mx-2"
color="primary"
mat-raised-button
>
Expand All @@ -183,7 +192,7 @@ <h3>Favorites</h3>

<button
(click)="handleDelete(study)"
class="w-25"
class="w-25 mx-2"
color="warn"
mat-raised-button
[disabled]="!canEditStudy(study.owner)"
Expand Down Expand Up @@ -503,7 +512,7 @@ <h3 class="mt-3">Your Studies</h3>
<span class="title badge">OWNER</span>
</div>
<div>
<span class="internal-name">{{ study.owner.name }}</span>
<span class="internal-name">{{ study.owner.name || study.owner.id }}</span>
</div>

<div>
Expand Down Expand Up @@ -550,14 +559,28 @@ <h3 class="mt-3">Your Studies</h3>
</div>

<div class="d-flex my-3" style="justify-content: space-between">
<button (click)="handleViewData(study)" class="w-25" mat-raised-button [disabled]="isGuest">
<button
(click)="handlePreviewStudy(study.id)"
class="w-25 mx-2"
color="accent"
mat-raised-button
>
Preview study
</button>

<button
(click)="handleViewData(study)"
class="w-25 mx-2"
mat-raised-button
[disabled]="isGuest"
>
See data
</button>

<button
[disabled]="true"
(click)="handleEdit(study)"
class="w-25"
class="w-25 mx-2"
color="primary"
mat-raised-button
>
Expand All @@ -566,7 +589,7 @@ <h3 class="mt-3">Your Studies</h3>

<button
(click)="handleDelete(study)"
class="w-25"
class="w-25 mx-2"
color="warn"
mat-raised-button
[disabled]="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { SnackbarService } from '../../../services/snackbar/snackbar.service';
import { TaskManagerService } from '../../../services/task-manager.service';
import { Observable, Subscription, throwError } from 'rxjs';
import { Observable, Subscription, of, throwError } from 'rxjs';
import { mergeMap, take, tap } from 'rxjs/operators';
import { wait } from 'src/app/common/commonMethods';
import { LoaderService } from 'src/app/services/loader/loader.service';
Expand All @@ -15,6 +15,7 @@ import { SessionStorageService } from 'src/app/services/sessionStorage.service';
import { UserStateService } from 'src/app/services/user-state-service';
import { CrowdSourcedUserService } from 'src/app/services/crowdsourced-user.service';
import { HttpStatus } from 'src/app/models/Auth';
import { StudyService } from 'src/app/services/study.service';
declare function setFullScreen(): any;

@Component({
Expand All @@ -39,7 +40,8 @@ export class CrowdSourceLoginComponent implements OnInit, OnDestroy {
private clearanceService: ClearanceService,
private dialog: MatDialog,
private translateService: TranslateService,
private sessionStorageService: SessionStorageService
private sessionStorageService: SessionStorageService,
private studyService: StudyService
) {}

ngOnInit(): void {
Expand All @@ -61,19 +63,28 @@ export class CrowdSourceLoginComponent implements OnInit, OnDestroy {
}

onRegister() {
if (!this.wasClicked) {
this.wasClicked = true;
if (this.wasClicked || !this.studyId) return;
if (this.workerId.length === 0) return;

if (this.workerId.length === 0) return;
this.wasClicked = true;
this.clearanceService.clearServices();

this.clearanceService.clearServices();
this.studyService.getStudyById(this.studyId).subscribe((study) => {
if (!study.body.started) {
this._snackbarService.openErrorSnackbar('Study not started');
this.wasClicked = false;
return;
}

this.openLanguageDialog()
.pipe(
mergeMap((lang) => {
if (!lang) return throwError('user exited dialog');
this.translateService.use(lang);
this.loaderService.showLoader();
return of(lang);
}),
mergeMap((lang) => {
return this.crowdSourcedUserService.createCrowdSourcedUserAndLogin(
this.workerId,
this.studyId,
Expand Down Expand Up @@ -132,7 +143,7 @@ export class CrowdSourceLoginComponent implements OnInit, OnDestroy {
.add(() => {
this.loaderService.hideLoader();
});
}
});
}

async startGameInFullScreen() {
Expand Down

0 comments on commit c750fe7

Please sign in to comment.