Skip to content

Commit 142f019

Browse files
authored
SF-3619 Allow users who can add/edit questions to see answers before they've answered (#3560)
1 parent b9a5295 commit 142f019

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

src/SIL.XForge.Scripture/ClientApp/src/app/checking/checking/checking-answers/checking-answers.component.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class CheckingAnswersComponent implements OnInit {
203203
// If the user hasn't added an answer yet and is able to, then
204204
// don't hold back any incoming answers from appearing right away
205205
// as soon as the user adds their answer.
206-
if (this.currentUserTotalAnswers === 0 && this.canAddAnswer && !this.isProjectAdmin) {
206+
if (this.currentUserTotalAnswers === 0 && this.canAddAnswer && !this.canManageQuestions) {
207207
this.showRemoteAnswers();
208208
return;
209209
}
@@ -292,15 +292,39 @@ export class CheckingAnswersComponent implements OnInit {
292292
);
293293
}
294294

295+
get canAddAndEditQuestions(): boolean {
296+
if (this.project == null) {
297+
return false;
298+
}
299+
const userId: string = this.userService.currentUserId;
300+
const canCreateQuestions: boolean = SF_PROJECT_RIGHTS.hasRight(
301+
this.project,
302+
userId,
303+
SFProjectDomain.Questions,
304+
Operation.Create
305+
);
306+
const canEditQuestions: boolean = SF_PROJECT_RIGHTS.hasRight(
307+
this.project,
308+
userId,
309+
SFProjectDomain.Questions,
310+
Operation.Edit
311+
);
312+
return canCreateQuestions && canEditQuestions;
313+
}
314+
315+
get canManageQuestions(): boolean {
316+
return this.isProjectAdmin || this.canAddAndEditQuestions;
317+
}
318+
295319
get shouldSeeAnswersList(): boolean {
296-
return this.canSeeOtherUserResponses || !this.canAddAnswer || this.isProjectAdmin;
320+
return this.canSeeOtherUserResponses || !this.canAddAnswer || this.canManageQuestions;
297321
}
298322

299323
get shouldShowAnswers(): boolean {
300324
return (
301325
!this.answerFormVisible &&
302326
this.totalAnswers > 0 &&
303-
(this.currentUserTotalAnswers > 0 || !this.canAddAnswer || this.isProjectAdmin)
327+
(this.currentUserTotalAnswers > 0 || !this.canAddAnswer || this.canManageQuestions)
304328
);
305329
}
306330

src/SIL.XForge.Scripture/ClientApp/src/app/checking/checking/checking-questions/checking-questions.component.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,30 @@ export class CheckingQuestionsComponent implements OnInit, OnChanges {
221221
return this._firstUnansweredQuestion.count > 0;
222222
}
223223

224+
get canManageQuestions(): boolean {
225+
return this.isProjectAdmin || this.canAddAndEditQuestions;
226+
}
227+
228+
get canAddAndEditQuestions(): boolean {
229+
if (this.project == null) {
230+
return false;
231+
}
232+
const userId: string = this.userService.currentUserId;
233+
const canCreateQuestions: boolean = SF_PROJECT_RIGHTS.hasRight(
234+
this.project,
235+
userId,
236+
SFProjectDomain.Questions,
237+
Operation.Create
238+
);
239+
const canEditQuestions: boolean = SF_PROJECT_RIGHTS.hasRight(
240+
this.project,
241+
userId,
242+
SFProjectDomain.Questions,
243+
Operation.Edit
244+
);
245+
return canCreateQuestions && canEditQuestions;
246+
}
247+
224248
protected activateFirstUnansweredQuestion(): void {
225249
if (!this.hasUnansweredQuestion || this._firstUnansweredQuestion == null) return;
226250
this.activateQuestion(this._firstUnansweredQuestion.docs[0], { isQuestionListChange: false }, true);
@@ -239,7 +263,7 @@ export class CheckingQuestionsComponent implements OnInit, OnChanges {
239263
return [];
240264
}
241265

242-
if (this.project.checkingConfig.usersSeeEachOthersResponses || !this.canAddAnswer || this.isProjectAdmin) {
266+
if (this.project.checkingConfig.usersSeeEachOthersResponses || !this.canAddAnswer || this.canManageQuestions) {
243267
return questionDoc.getAnswers();
244268
} else {
245269
return questionDoc.getAnswers(this.userService.currentUserId);
@@ -248,7 +272,7 @@ export class CheckingQuestionsComponent implements OnInit, OnChanges {
248272

249273
getUnreadAnswers(questionDoc: QuestionDoc): number {
250274
if (
251-
(this.canAddAnswer && !this.isProjectAdmin) ||
275+
(this.canAddAnswer && !this.canManageQuestions) ||
252276
this.project == null ||
253277
!this.project.checkingConfig.usersSeeEachOthersResponses
254278
) {
@@ -332,7 +356,7 @@ export class CheckingQuestionsComponent implements OnInit, OnChanges {
332356
if (questionDoc != null && questionDoc.data != null && !this.hasUserReadQuestion(questionDoc)) {
333357
op.add(puc => puc.questionRefsRead, questionDoc.data.dataId);
334358
}
335-
if (this.hasUserAnswered(questionDoc) || !this.canAddAnswer || this.isProjectAdmin) {
359+
if (this.hasUserAnswered(questionDoc) || !this.canAddAnswer || this.canManageQuestions) {
336360
for (const answer of this.getAnswers(questionDoc)) {
337361
if (!this.hasUserReadAnswer(answer)) {
338362
op.add(puc => puc.answerRefsRead, answer.dataId);

0 commit comments

Comments
 (0)