GetQuestion get question one
(ctx context.Context, questionID, userID string, per schema.QuestionPermission)
| 1086 | |
| 1087 | // GetQuestion get question one |
| 1088 | func (qs *QuestionService) GetQuestion(ctx context.Context, questionID, userID string, |
| 1089 | per schema.QuestionPermission) (resp *schema.QuestionInfoResp, err error) { |
| 1090 | question, err := qs.questioncommon.Info(ctx, questionID, userID) |
| 1091 | if err != nil { |
| 1092 | return |
| 1093 | } |
| 1094 | // If the question is deleted or pending, only the administrator and the author can view it |
| 1095 | if (question.Status == entity.QuestionStatusDeleted || |
| 1096 | question.Status == entity.QuestionStatusPending) && !per.CanReopen && question.UserID != userID { |
| 1097 | return nil, errors.NotFound(reason.QuestionNotFound) |
| 1098 | } |
| 1099 | if question.Show == entity.QuestionHide && !per.IsAdminModerator && question.UserID != userID { |
| 1100 | return nil, errors.NotFound(reason.QuestionNotFound) |
| 1101 | } |
| 1102 | if question.Status != entity.QuestionStatusClosed { |
| 1103 | per.CanReopen = false |
| 1104 | } |
| 1105 | if question.Status == entity.QuestionStatusClosed { |
| 1106 | per.CanClose = false |
| 1107 | } |
| 1108 | if question.Pin == entity.QuestionPin { |
| 1109 | per.CanPin = false |
| 1110 | per.CanHide = false |
| 1111 | } |
| 1112 | if question.Pin == entity.QuestionUnPin { |
| 1113 | per.CanUnPin = false |
| 1114 | } |
| 1115 | if question.Show == entity.QuestionShow { |
| 1116 | per.CanShow = false |
| 1117 | } |
| 1118 | if question.Show == entity.QuestionHide { |
| 1119 | per.CanHide = false |
| 1120 | per.CanPin = false |
| 1121 | } |
| 1122 | |
| 1123 | if question.Status == entity.QuestionStatusDeleted { |
| 1124 | operation := &schema.Operation{} |
| 1125 | operation.Msg = translator.Tr(handler.GetLangByCtx(ctx), reason.QuestionAlreadyDeleted) |
| 1126 | operation.Level = schema.OperationLevelDanger |
| 1127 | question.Operation = operation |
| 1128 | } |
| 1129 | if question.Status == entity.QuestionStatusPending { |
| 1130 | operation := &schema.Operation{} |
| 1131 | operation.Msg = translator.Tr(handler.GetLangByCtx(ctx), reason.QuestionUnderReview) |
| 1132 | operation.Level = schema.OperationLevelSecondary |
| 1133 | question.Operation = operation |
| 1134 | } |
| 1135 | |
| 1136 | question.Description = htmltext.FetchExcerpt(question.HTML, "...", 240) |
| 1137 | question.MemberActions = permission.GetQuestionPermission(ctx, userID, question.UserID, question.Status, |
| 1138 | per.CanEdit, per.CanDelete, |
| 1139 | per.CanClose, per.CanReopen, per.CanPin, per.CanHide, per.CanUnPin, per.CanShow, |
| 1140 | per.CanRecover) |
| 1141 | question.ExtendsActions = permission.GetQuestionExtendsPermission(ctx, per.CanInviteOtherToAnswer) |
| 1142 | return question, nil |
| 1143 | } |
| 1144 | |
| 1145 | // GetQuestionAndAddPV get question one |
no test coverage detected