Skip to content

Commit 196cc21

Browse files
committed
Allow users who can add/edit questions to see answers before they've answered
1 parent c5708ff commit 196cc21

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
@@ -207,7 +207,7 @@ export class CheckingAnswersComponent implements OnInit {
207207
// If the user hasn't added an answer yet and is able to, then
208208
// don't hold back any incoming answers from appearing right away
209209
// as soon as the user adds their answer.
210-
if (this.currentUserTotalAnswers === 0 && this.canAddAnswer && !this.isProjectAdmin) {
210+
if (this.currentUserTotalAnswers === 0 && this.canAddAnswer && !this.canManageQuestions) {
211211
this.showRemoteAnswers();
212212
return;
213213
}
@@ -296,15 +296,39 @@ export class CheckingAnswersComponent implements OnInit {
296296
);
297297
}
298298

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

303327
get shouldShowAnswers(): boolean {
304328
return (
305329
!this.answerFormVisible &&
306330
this.totalAnswers > 0 &&
307-
(this.currentUserTotalAnswers > 0 || !this.canAddAnswer || this.isProjectAdmin)
331+
(this.currentUserTotalAnswers > 0 || !this.canAddAnswer || this.canManageQuestions)
308332
);
309333
}
310334

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)