Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit ffa792b

Browse files
authored
Merge pull request #139 from nodes-vapor/feature/fix-unique-email-validation
Prevent overwriting uniqueness validation
2 parents db7274a + 4738d14 commit ffa792b

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

Sources/AdminPanel/Models/AdminPanelUser/Extensions/AdminPanelUser+Submittable.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ import Validation
55
import Vapor
66

77
extension AdminPanelUser: Submittable {
8-
public static func makeFields(
8+
public static func makeAdditionalFields(
99
for submission: Submission?,
1010
given user: AdminPanelUser?
1111
) throws -> [Field] {
12-
guard let submission = submission else { return [] }
1312
return try [
1413
Field(
1514
keyPath: \.email,
1615
instance: submission,
17-
label: "Email address",
16+
label: "Email",
17+
validators: [.email],
1818
asyncValidators: [{ req, _ in
19-
validateThat(
19+
guard let submission = submission else { return req.future([]) }
20+
return validateThat(
2021
only: user,
2122
has: submission.email,
2223
for: \.email,
@@ -77,12 +78,6 @@ extension AdminPanelUser: Submittable {
7778
label: "Title",
7879
validators: [.count(...191)]
7980
),
80-
Field(
81-
keyPath: \.email,
82-
instance: instance,
83-
label: "Email",
84-
validators: [.email]
85-
),
8681
Field(
8782
keyPath: \.role,
8883
instance: instance,

0 commit comments

Comments
 (0)