master
lion 3 weeks ago
parent 40b715ae53
commit 464e5d68d2

@ -190,7 +190,7 @@ class CourseController extends CommonController
if ($message = $detail->participationError($this->getUserId())) return $this->success(['id' => $detail->id, 'access_error' => $message]);
$detail->schema_hash = SurveySchema::hash($detail->courseContentEvaluationAsks->toArray());
$reply = $detail->courseContentEvaluationForms()->where('user_id', $this->getUserId())->first();
$detail->requires_profile = !\App\Services\Survey\SurveyIdentity::complete(auth('mobile')->user());
$detail->requires_profile = trim((string) auth('mobile')->user()->mobile) === '';
if ($reply && !empty($reply->snapshot['questions'])) $detail->schema_hash = SurveySchema::hash($reply->snapshot['questions']);
$detail->my_response = $reply ? [
'title' => $reply->snapshot['title'] ?? $detail->title,
@ -488,8 +488,7 @@ class CourseController extends CommonController
if ($message = $survey->participationError($this->getUserId())) return ['access_error' => $message];
if ((int) $survey->status !== 1) throw new \InvalidArgumentException('问卷未发布');
if ($survey->start_time && strtotime($survey->start_time) > time()) throw new \InvalidArgumentException('评价时间未开始');
if (empty(auth('mobile')->user()->mobile)) throw new \InvalidArgumentException('请先绑定或注册');
if (!\App\Services\Survey\SurveyIdentity::complete(auth('mobile')->user())) throw new \InvalidArgumentException('请先完成绑定或注册资料');
if (trim((string) auth('mobile')->user()->mobile) === '') throw new \InvalidArgumentException('请先绑定或注册');
$reply = $survey->courseContentEvaluationForms()->where('user_id', $this->getUserId())->first();
$questions = $survey->courseContentEvaluationAsks()->with('courseContent.teacher')->orderBy('sort')->orderBy('id')->get()->toArray();
if ($reply && !empty($reply->snapshot['questions'])) $questions = $reply->snapshot['questions'];

@ -477,7 +477,7 @@ class UserController extends CommonController
}
\App\Services\SupplyDemand\Handover::verified($hasMobile);
$token = $hasMobile->createToken("mobile-token")->plainTextToken;
return $this->success(['token' => $token, 'requires_profile' => !\App\Services\Survey\SurveyIdentity::complete($hasMobile)]);
return $this->success(compact('token'));
}
return $this->fail([ResponseCode::ERROR_BUSINESS, '校友库中还没有您的信息,请先注册']);
}

@ -65,29 +65,22 @@ class SurveyWorkflowTest extends TestCase
return $response->json('id');
}
public function testIncompleteProfilesCannotSubmitUntilRegistrationIsComplete(): void
public function testSurveyAccessRequiresOnlyMobileEvenWhenOtherProfileFieldsAreMissing(): void
{
$id = $this->createQuestion();
$complete = clone Auth::guard('mobile')->user();
$pending = new User();
$pending->forceFill(['id' => 200, 'mobile' => '13800000000']);
Auth::guard('mobile')->setUser($pending);
$detail = '/api/mobile/course/evaluation-detail?course_content_evaluation_id=10';
$payload = ['course_content_evaluation_id' => 10, 'answer_version' => 2, 'data' => [['id' => $id, 'value' => ['count' => 0, 'follow' => 'yes']]]];
$this->getJson($detail)->assertJsonPath('requires_profile', true);
$this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('errmsg', '请先完成绑定或注册资料');
$this->assertSame(0, \App\Models\CourseContentEvaluationForm::count());
foreach (['name', 'sex', 'birthday', 'email', 'company_name', 'company_position'] as $field) {
$missing = clone $complete;
$missing->$field = null;
$this->assertFalse(\App\Services\Survey\SurveyIdentity::complete($missing));
}
$monthOnly = clone $complete;
$monthOnly->birthday = '1990-01';
$this->assertFalse(\App\Services\Survey\SurveyIdentity::complete($monthOnly));
Auth::guard('mobile')->setUser($complete);
$this->getJson($detail)->assertJsonPath('requires_profile', false);
$this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('user_id', 200);
$replyId = $this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('user_id', 200)->json('id');
$pending->mobile = null;
$this->getJson($detail)->assertJsonPath('requires_profile', true);
$this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('errmsg', '请先绑定或注册');
$pending->mobile = '13800000000';
$this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('id', $replyId);
$this->assertSame(1, \App\Models\CourseContentEvaluationForm::count());
}
public function testRespondentFallbackIsSharedByListsDetailsAndExportWithoutUpdatingUsers(): void

Loading…
Cancel
Save