Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

feature: option for users to delete their account (#395)

Guilherme Oenningca943b59c63d
diff --git a/app/cmd/routes.go b/app/cmd/routes.go
index 34224de18..827e947bf 100644
--- a/app/cmd/routes.go
+++ b/app/cmd/routes.go
@@ -105,6 +105,7 @@ func routes(r *web.Engine) *web.Engine {
private.Post("/api/ideas/:number/unsubscribe", handlers.Unsubscribe())
private.Post("/api/ideas/:number/tags/:slug", handlers.AssignTag())
private.Delete("/api/ideas/:number/tags/:slug", handlers.UnassignTag())
+ private.Delete("/api/user", handlers.DeleteUser())
private.Post("/api/user/settings", handlers.UpdateUserSettings())
private.Post("/api/user/change-email", handlers.ChangeUserEmail())
private.Post("/api/notifications/read-all", handlers.ReadAllNotifications())
diff --git a/app/handlers/images.go b/app/handlers/images.go
index 4621ebc33..822036a7d 100644
--- a/app/handlers/images.go
+++ b/app/handlers/images.go
@@ -43,7 +43,9 @@ func Avatar() web.HandlerFunc {
}
}
- img, err := letteravatar.Draw(size, strings.ToUpper(letteravatar.Extract(name)), &letteravatar.Options{PaletteKey: name})
+ img, err := letteravatar.Draw(size, strings.ToUpper(letteravatar.Extract(name)), &letteravatar.Options{
+ PaletteKey: fmt.Sprintf("%d:%s", id, name),
+ })
if err != nil {
return c.Failure(err)
}
diff --git a/app/handlers/images_test.go b/app/handlers/images_test.go
index d1e1cfb16..e5a89706d 100644
--- a/app/handlers/images_test.go
+++ b/app/handlers/images_test.go
@@ -51,7 +51,7 @@ func TestGravatarNotFound_LetterAvatarHandler(t *testing.T) {
AddParam("name", user.Name).
Execute(handlers.Avatar())
- expectedAvatar := []byte{137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 50, 0, 0, 0, 50, 8, 2, 0, 0, 0, 145, 93, 31, 230, 0, 0, 2, 143, 73, 68, 65, 84, 120, 156, 236, 152, 193, 107, 19, 79, 20, 199, 191, 155, 166, 45, 109, 55, 205, 239, 151, 10, 145, 216, 106, 116, 27, 49, 168, 141, 151, 122, 16, 188, 40, 244, 234, 65, 176, 8, 94, 197, 147, 39, 241, 159, 240, 230, 205, 147, 122, 241, 80, 60, 136, 7, 43, 8, 22, 65, 16, 105, 109, 13, 141, 218, 36, 164, 182, 198, 10, 38, 216, 38, 134, 53, 169, 217, 102, 87, 94, 50, 77, 54, 33, 232, 62, 108, 106, 15, 243, 165, 12, 223, 125, 59, 59, 243, 225, 205, 155, 153, 18, 183, 117, 235, 42, 246, 158, 92, 255, 26, 160, 189, 36, 22, 71, 18, 139, 35, 137, 197, 145, 196, 226, 72, 98, 113, 36, 177, 56, 146, 88, 28, 73, 44, 142, 220, 142, 122, 133, 79, 227, 196, 153, 198, 227, 207, 18, 10, 235, 248, 24, 67, 58, 209, 8, 42, 46, 92, 184, 134, 238, 94, 232, 121, 60, 189, 223, 102, 144, 137, 43, 240, 238, 67, 197, 192, 227, 59, 168, 84, 118, 2, 203, 243, 63, 2, 135, 91, 131, 145, 179, 200, 124, 198, 244, 93, 20, 54, 232, 209, 50, 177, 89, 196, 161, 99, 228, 95, 79, 35, 151, 109, 29, 33, 60, 78, 38, 181, 248, 71, 38, 254, 34, 62, 159, 194, 147, 123, 120, 246, 0, 177, 87, 168, 108, 193, 63, 130, 201, 27, 24, 240, 138, 183, 241, 57, 97, 180, 177, 214, 15, 71, 79, 9, 147, 120, 227, 100, 30, 38, 214, 234, 7, 164, 162, 88, 154, 197, 204, 20, 30, 222, 134, 81, 70, 191, 138, 243, 147, 226, 109, 58, 142, 162, 94, 133, 136, 180, 126, 24, 170, 98, 109, 150, 176, 242, 190, 3, 88, 118, 101, 210, 88, 152, 33, 19, 60, 14, 143, 143, 140, 105, 34, 185, 64, 198, 127, 16, 158, 255, 26, 61, 85, 47, 246, 7, 201, 164, 162, 148, 227, 206, 98, 1, 72, 190, 165, 86, 1, 180, 147, 34, 18, 223, 94, 35, 205, 150, 48, 45, 66, 125, 236, 171, 220, 89, 172, 252, 118, 93, 15, 250, 132, 201, 124, 66, 254, 27, 90, 202, 171, 230, 11, 57, 124, 89, 222, 21, 44, 211, 132, 97, 144, 233, 247, 52, 130, 137, 121, 106, 3, 26, 250, 84, 50, 125, 42, 14, 140, 194, 113, 177, 239, 4, 22, 128, 174, 46, 106, 141, 178, 13, 171, 58, 189, 75, 17, 73, 210, 198, 200, 115, 86, 240, 175, 177, 6, 188, 112, 85, 71, 208, 243, 141, 96, 46, 75, 187, 161, 190, 31, 107, 123, 48, 187, 134, 141, 204, 110, 97, 141, 132, 132, 249, 186, 218, 20, 175, 21, 254, 240, 81, 12, 14, 97, 56, 4, 251, 86, 232, 56, 150, 187, 27, 227, 19, 100, 126, 20, 144, 78, 54, 189, 74, 206, 83, 217, 117, 185, 112, 238, 18, 165, 211, 180, 68, 193, 117, 22, 75, 81, 16, 56, 130, 139, 215, 225, 243, 163, 118, 244, 91, 102, 83, 135, 162, 46, 174, 203, 218, 93, 180, 150, 68, 177, 192, 154, 193, 217, 157, 88, 215, 229, 155, 128, 133, 222, 1, 202, 4, 128, 138, 137, 151, 143, 176, 242, 174, 77, 207, 248, 28, 130, 97, 225, 151, 102, 121, 179, 176, 177, 250, 85, 97, 12, 131, 142, 236, 232, 11, 170, 229, 182, 90, 142, 161, 92, 70, 79, 15, 181, 169, 69, 46, 150, 226, 232, 103, 183, 62, 213, 118, 50, 89, 40, 233, 226, 238, 251, 189, 188, 67, 112, 247, 96, 171, 140, 239, 235, 92, 44, 103, 217, 42, 233, 244, 199, 21, 159, 166, 174, 61, 250, 223, 169, 196, 226, 72, 98, 113, 36, 177, 56, 146, 88, 28, 73, 44, 142, 36, 22, 71, 18, 139, 163, 95, 1, 0, 0, 255, 255, 231, 10, 191, 199, 156, 125, 3, 241, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130}
+ expectedAvatar := []byte{137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 50, 0, 0, 0, 50, 8, 2, 0, 0, 0, 145, 93, 31, 230, 0, 0, 3, 6, 73, 68, 65, 84, 120, 156, 236, 152, 75, 79, 19, 81, 20, 128, 207, 204, 212, 210, 18, 90, 232, 211, 34, 196, 40, 6, 65, 129, 0, 209, 2, 11, 100, 97, 140, 113, 225, 2, 127, 3, 198, 196, 184, 55, 38, 38, 36, 198, 132, 168, 11, 149, 152, 24, 35, 97, 99, 220, 24, 23, 46, 140, 186, 49, 38, 242, 42, 20, 10, 72, 241, 149, 64, 75, 12, 125, 208, 86, 104, 7, 90, 103, 134, 206, 29, 211, 14, 25, 154, 66, 116, 46, 96, 101, 113, 191, 213, 225, 204, 153, 123, 191, 204, 185, 15, 82, 205, 197, 87, 157, 176, 255, 160, 255, 183, 192, 246, 16, 45, 28, 136, 22, 14, 68, 11, 7, 162, 133, 3, 209, 194, 129, 104, 225, 64, 180, 112, 32, 90, 56, 104, 212, 20, 117, 84, 158, 57, 119, 248, 172, 242, 103, 50, 157, 138, 164, 34, 19, 97, 143, 55, 54, 171, 36, 105, 138, 190, 209, 114, 93, 199, 20, 45, 115, 203, 15, 39, 31, 109, 29, 228, 90, 211, 213, 131, 197, 118, 1, 173, 223, 113, 223, 75, 163, 244, 30, 104, 89, 245, 150, 26, 243, 241, 188, 228, 133, 35, 231, 125, 9, 255, 125, 79, 111, 52, 21, 5, 0, 36, 161, 53, 97, 181, 177, 162, 1, 0, 94, 124, 127, 25, 74, 134, 243, 70, 232, 168, 108, 7, 0, 119, 120, 226, 175, 78, 216, 77, 124, 58, 211, 255, 192, 211, 251, 120, 250, 201, 251, 31, 31, 214, 81, 186, 170, 244, 104, 79, 251, 109, 147, 206, 36, 63, 29, 12, 12, 203, 65, 75, 121, 75, 222, 139, 173, 229, 173, 27, 53, 139, 67, 106, 38, 194, 211, 154, 138, 76, 143, 134, 220, 31, 23, 7, 251, 102, 250, 187, 71, 110, 241, 34, 111, 212, 26, 174, 52, 116, 201, 79, 63, 69, 103, 18, 60, 155, 145, 112, 56, 243, 94, 108, 203, 138, 38, 215, 147, 147, 145, 169, 189, 215, 202, 197, 23, 247, 189, 158, 127, 3, 0, 205, 246, 102, 171, 222, 42, 247, 209, 21, 116, 1, 192, 177, 178, 42, 139, 222, 162, 84, 154, 117, 166, 234, 178, 106, 0, 24, 13, 185, 213, 116, 112, 183, 59, 209, 21, 26, 5, 0, 138, 2, 167, 227, 148, 156, 217, 236, 163, 227, 180, 82, 230, 116, 56, 41, 74, 126, 170, 170, 131, 187, 213, 10, 174, 133, 228, 192, 166, 183, 201, 193, 92, 124, 62, 156, 92, 202, 106, 109, 246, 177, 181, 60, 19, 71, 127, 197, 190, 254, 252, 86, 8, 45, 36, 33, 94, 20, 0, 160, 180, 168, 84, 73, 14, 7, 71, 0, 160, 214, 92, 99, 212, 26, 0, 192, 168, 53, 156, 48, 215, 102, 242, 129, 17, 245, 35, 239, 246, 56, 213, 208, 153, 35, 70, 16, 121, 37, 35, 239, 53, 154, 162, 157, 217, 15, 230, 116, 56, 105, 42, 51, 203, 192, 226, 96, 129, 180, 76, 58, 19, 147, 157, 50, 198, 45, 43, 201, 80, 50, 60, 31, 247, 41, 189, 147, 247, 160, 63, 177, 16, 88, 11, 22, 72, 171, 222, 114, 82, 14, 230, 86, 230, 114, 243, 242, 210, 174, 183, 212, 217, 139, 109, 117, 214, 186, 220, 173, 240, 207, 181, 180, 140, 246, 82, 117, 39, 0, 172, 112, 241, 220, 91, 40, 187, 188, 92, 162, 132, 24, 154, 185, 220, 208, 197, 80, 52, 146, 208, 112, 1, 180, 40, 138, 170, 53, 215, 116, 183, 221, 172, 40, 57, 4, 0, 125, 222, 126, 36, 161, 220, 2, 150, 103, 189, 81, 47, 0, 52, 218, 50, 119, 209, 108, 236, 115, 156, 79, 96, 77, 161, 234, 78, 84, 184, 219, 209, 35, 73, 168, 228, 64, 9, 67, 51, 0, 32, 34, 241, 217, 151, 231, 158, 165, 201, 173, 149, 3, 129, 161, 38, 123, 227, 70, 140, 179, 216, 119, 162, 37, 239, 121, 0, 224, 69, 97, 44, 228, 126, 235, 127, 231, 79, 44, 108, 91, 57, 30, 158, 224, 210, 156, 78, 163, 227, 210, 220, 88, 120, 28, 87, 139, 82, 243, 179, 155, 81, 107, 80, 78, 38, 9, 128, 21, 88, 54, 123, 247, 253, 25, 123, 177, 189, 136, 209, 242, 162, 16, 73, 69, 112, 181, 84, 125, 45, 86, 88, 101, 133, 85, 220, 161, 119, 96, 163, 176, 79, 255, 59, 37, 90, 56, 16, 45, 28, 136, 22, 14, 68, 11, 7, 162, 133, 3, 209, 194, 129, 104, 225, 240, 59, 0, 0, 255, 255, 193, 108, 28, 164, 14, 189, 96, 131, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130}
Expect(code).Equals(http.StatusOK)
bytes, _ := ioutil.ReadAll(response.Body)
Expect(bytes).Equals(expectedAvatar)
@@ -68,7 +68,7 @@ func TestUnknownUser_LetterAvatarHandler(t *testing.T) {
AddParam("name", "Jon Snow").
Execute(handlers.Avatar())
- expectedAvatar := []byte{137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 50, 0, 0, 0, 50, 8, 2, 0, 0, 0, 145, 93, 31, 230, 0, 0, 2, 150, 73, 68, 65, 84, 120, 156, 236, 152, 91, 79, 226, 64, 20, 128, 167, 115, 233, 141, 94, 160, 84, 164, 46, 198, 93, 55, 217, 248, 255, 255, 200, 190, 154, 189, 100, 141, 138, 130, 86, 64, 218, 210, 206, 244, 182, 129, 106, 117, 163, 49, 51, 89, 34, 62, 204, 247, 212, 28, 79, 207, 124, 158, 30, 78, 9, 248, 251, 233, 47, 240, 241, 128, 187, 22, 120, 29, 169, 37, 130, 212, 18, 65, 106, 137, 32, 181, 68, 144, 90, 34, 72, 45, 17, 164, 150, 8, 82, 75, 4, 252, 63, 55, 219, 29, 115, 224, 117, 1, 0, 227, 105, 152, 49, 214, 4, 33, 132, 126, 215, 113, 172, 142, 70, 214, 197, 243, 162, 140, 146, 85, 184, 88, 230, 69, 241, 78, 90, 24, 161, 142, 174, 53, 42, 77, 132, 16, 124, 252, 105, 168, 17, 210, 230, 32, 21, 234, 170, 235, 185, 246, 217, 213, 52, 73, 179, 247, 208, 122, 201, 104, 224, 107, 132, 212, 0, 220, 220, 45, 238, 147, 164, 174, 129, 169, 107, 67, 191, 71, 16, 58, 10, 246, 79, 207, 46, 170, 170, 226, 169, 179, 205, 217, 66, 8, 218, 166, 1, 0, 88, 44, 227, 233, 108, 158, 81, 70, 25, 155, 47, 163, 203, 105, 184, 105, 45, 116, 173, 14, 103, 169, 109, 118, 75, 81, 148, 230, 162, 252, 183, 37, 73, 154, 221, 221, 71, 155, 120, 185, 3, 173, 162, 40, 105, 158, 107, 132, 120, 174, 157, 164, 217, 125, 156, 52, 241, 170, 170, 198, 55, 161, 80, 169, 45, 47, 136, 241, 205, 93, 93, 3, 168, 40, 71, 193, 224, 219, 209, 104, 224, 117, 213, 103, 227, 191, 51, 173, 120, 149, 254, 190, 188, 74, 233, 122, 89, 232, 42, 25, 246, 123, 39, 159, 71, 199, 163, 192, 212, 245, 93, 106, 1, 0, 86, 25, 253, 121, 62, 254, 51, 158, 204, 163, 184, 25, 50, 203, 208, 191, 30, 6, 125, 215, 225, 47, 178, 229, 5, 209, 18, 173, 210, 104, 149, 66, 69, 113, 237, 78, 224, 123, 24, 161, 131, 65, 63, 78, 51, 250, 184, 117, 223, 134, 183, 91, 16, 66, 140, 16, 70, 232, 121, 80, 121, 186, 172, 1, 0, 134, 166, 117, 109, 171, 107, 91, 237, 71, 178, 170, 235, 249, 50, 62, 159, 220, 54, 201, 174, 101, 114, 30, 199, 219, 45, 191, 235, 12, 251, 61, 0, 192, 233, 217, 5, 203, 31, 94, 35, 132, 60, 220, 94, 148, 155, 135, 101, 26, 129, 191, 206, 249, 113, 206, 50, 250, 212, 149, 246, 26, 65, 238, 46, 112, 230, 165, 143, 165, 219, 17, 33, 24, 123, 142, 221, 188, 245, 88, 158, 3, 0, 150, 73, 82, 111, 254, 116, 176, 215, 111, 251, 170, 40, 74, 191, 251, 112, 75, 198, 114, 206, 227, 120, 187, 21, 175, 210, 148, 50, 67, 83, 247, 122, 174, 99, 153, 121, 81, 26, 154, 134, 224, 250, 97, 93, 135, 179, 38, 135, 178, 124, 18, 206, 2, 223, 179, 12, 253, 228, 203, 97, 70, 89, 89, 85, 154, 74, 84, 140, 155, 127, 108, 17, 197, 156, 199, 41, 252, 191, 111, 97, 140, 70, 131, 61, 167, 99, 180, 145, 162, 172, 38, 225, 108, 182, 140, 158, 167, 57, 29, 115, 223, 239, 25, 170, 218, 70, 106, 0, 22, 81, 124, 125, 59, 43, 74, 222, 45, 47, 160, 213, 160, 18, 172, 107, 42, 84, 96, 94, 20, 105, 70, 171, 186, 126, 53, 109, 221, 36, 66, 16, 132, 69, 89, 102, 148, 241, 11, 53, 8, 47, 8, 150, 23, 237, 200, 191, 1, 101, 57, 229, 158, 164, 151, 124, 208, 111, 167, 82, 75, 4, 169, 37, 130, 212, 18, 65, 106, 137, 32, 181, 68, 144, 90, 34, 72, 45, 17, 254, 6, 0, 0, 255, 255, 195, 184, 4, 70, 45, 232, 84, 206, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130}
+ expectedAvatar := []byte{137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 50, 0, 0, 0, 50, 8, 2, 0, 0, 0, 145, 93, 31, 230, 0, 0, 2, 137, 73, 68, 65, 84, 120, 156, 236, 152, 75, 79, 19, 81, 20, 199, 255, 3, 51, 244, 65, 95, 80, 74, 43, 160, 149, 135, 36, 5, 177, 169, 137, 40, 42, 209, 152, 200, 74, 19, 87, 110, 248, 84, 126, 7, 227, 70, 23, 110, 140, 137, 154, 248, 32, 33, 152, 72, 20, 13, 6, 8, 62, 210, 74, 209, 218, 161, 239, 55, 237, 152, 67, 167, 37, 141, 36, 222, 139, 19, 202, 226, 254, 114, 51, 28, 78, 239, 220, 249, 245, 204, 205, 153, 73, 101, 237, 225, 61, 28, 63, 58, 218, 45, 112, 48, 66, 139, 7, 161, 197, 131, 208, 226, 65, 104, 241, 32, 180, 120, 16, 90, 60, 8, 45, 30, 132, 22, 15, 242, 127, 157, 237, 61, 133, 241, 243, 20, 124, 120, 141, 76, 162, 177, 164, 130, 145, 41, 156, 24, 134, 205, 65, 255, 22, 114, 248, 21, 198, 151, 143, 40, 230, 143, 74, 203, 100, 129, 219, 71, 129, 210, 165, 103, 44, 54, 92, 190, 5, 187, 107, 127, 142, 98, 130, 163, 23, 167, 39, 176, 244, 20, 234, 246, 145, 104, 253, 77, 232, 26, 57, 105, 26, 214, 222, 97, 251, 59, 180, 42, 122, 188, 152, 184, 8, 179, 21, 211, 115, 120, 254, 0, 187, 21, 150, 101, 12, 221, 91, 138, 9, 253, 39, 41, 136, 108, 96, 125, 25, 105, 21, 153, 36, 194, 235, 120, 255, 10, 245, 210, 14, 140, 48, 174, 100, 104, 181, 58, 26, 95, 178, 82, 106, 201, 199, 163, 248, 246, 153, 130, 114, 169, 29, 90, 165, 2, 149, 199, 238, 162, 157, 164, 254, 68, 244, 171, 158, 175, 238, 98, 229, 13, 215, 74, 70, 55, 136, 149, 5, 212, 106, 232, 148, 105, 39, 221, 184, 139, 241, 16, 172, 246, 67, 44, 99, 180, 86, 124, 11, 11, 143, 145, 138, 83, 236, 232, 165, 205, 62, 55, 143, 43, 183, 209, 235, 109, 171, 22, 128, 68, 12, 47, 31, 97, 241, 9, 194, 27, 168, 148, 41, 227, 25, 196, 236, 29, 186, 179, 204, 24, 221, 32, 154, 196, 34, 52, 58, 58, 49, 56, 138, 201, 25, 152, 45, 8, 206, 66, 141, 210, 230, 99, 128, 185, 90, 157, 50, 186, 204, 52, 90, 144, 244, 191, 154, 70, 71, 103, 31, 134, 198, 104, 72, 141, 124, 173, 74, 205, 98, 249, 197, 222, 92, 137, 90, 63, 27, 204, 213, 26, 11, 34, 112, 129, 130, 103, 247, 145, 207, 234, 73, 171, 77, 15, 202, 69, 58, 246, 15, 97, 242, 18, 5, 233, 29, 26, 77, 82, 170, 30, 40, 102, 198, 171, 49, 87, 43, 249, 91, 15, 134, 167, 244, 192, 210, 13, 127, 128, 130, 66, 22, 185, 52, 5, 212, 214, 247, 202, 118, 238, 42, 53, 207, 58, 146, 132, 209, 198, 41, 153, 29, 198, 171, 49, 87, 43, 22, 33, 51, 151, 7, 103, 130, 240, 249, 233, 185, 235, 242, 64, 81, 232, 163, 213, 183, 250, 156, 108, 18, 171, 75, 56, 59, 131, 190, 1, 220, 156, 167, 130, 85, 138, 176, 247, 232, 61, 34, 165, 226, 199, 38, 227, 213, 36, 142, 223, 183, 76, 22, 132, 174, 147, 83, 147, 82, 129, 156, 194, 107, 45, 211, 124, 126, 4, 166, 225, 116, 239, 103, 106, 53, 108, 109, 226, 211, 162, 126, 175, 13, 214, 170, 99, 181, 195, 225, 134, 44, 211, 27, 75, 34, 70, 155, 250, 64, 186, 157, 176, 57, 233, 205, 162, 84, 160, 54, 198, 252, 216, 169, 195, 223, 32, 242, 25, 26, 255, 36, 151, 162, 113, 88, 142, 233, 219, 169, 208, 226, 65, 104, 241, 32, 180, 120, 16, 90, 60, 8, 45, 30, 132, 22, 15, 66, 139, 135, 63, 1, 0, 0, 255, 255, 117, 91, 183, 108, 67, 255, 85, 68, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130}
Expect(code).Equals(http.StatusOK)
bytes, _ := ioutil.ReadAll(response.Body)
Expect(bytes).Equals(expectedAvatar)
diff --git a/app/handlers/settings.go b/app/handlers/settings.go
index 0665c1bba..da8c695e1 100644
--- a/app/handlers/settings.go
+++ b/app/handlers/settings.go
@@ -109,3 +109,16 @@ func ChangeUserRole() web.HandlerFunc {
return c.Ok(web.Map{})
}
}
+
+// DeleteUser erases current user personal data and sign them out
+func DeleteUser() web.HandlerFunc {
+ return func(c web.Context) error {
+ err := c.Services().Users.Delete()
+ if err != nil {
+ return c.Failure(err)
+ }
+
+ c.RemoveCookie(web.CookieAuthName)
+ return c.Ok(web.Map{})
+ }
+}
diff --git a/app/handlers/settings_test.go b/app/handlers/settings_test.go
index 8fb10d5a9..307a63d02 100644
--- a/app/handlers/settings_test.go
+++ b/app/handlers/settings_test.go
@@ -13,6 +13,7 @@ import (
. "github.com/getfider/fider/app/pkg/assert"
"github.com/getfider/fider/app/pkg/errors"
"github.com/getfider/fider/app/pkg/mock"
+ "github.com/getfider/fider/app/pkg/web"
)
func TestSettingsHandler(t *testing.T) {
@@ -185,3 +186,20 @@ func TestVerifyChangeEmailKeyHandler_DifferentUser(t *testing.T) {
_, err = services.Users.GetByEmail("[email protected]")
Expect(errors.Cause(err)).Equals(app.ErrNotFound)
}
+
+func TestDeleteUserHandler(t *testing.T) {
+ RegisterT(t)
+
+ server, services := mock.NewServer()
+ code, response := server.
+ AsUser(mock.JonSnow).
+ Execute(handlers.DeleteUser())
+
+ Expect(code).Equals(http.StatusOK)
+ Expect(response.Header().Get("Set-Cookie")).ContainsSubstring(web.CookieAuthName + "=; Path=/; Expires=")
+ Expect(response.Header().Get("Set-Cookie")).ContainsSubstring("Max-Age=0; HttpOnly")
+
+ user, err := services.Users.GetByEmail("[email protected]")
+ Expect(errors.Cause(err)).Equals(app.ErrNotFound)
+ Expect(user).IsNil()
+}
diff --git a/app/handlers/signin_test.go b/app/handlers/signin_test.go
index 7f5062537..71be15f49 100644
--- a/app/handlers/signin_test.go
+++ b/app/handlers/signin_test.go
@@ -29,7 +29,8 @@ func TestSignOutHandler(t *testing.T) {
Expect(code).Equals(http.StatusTemporaryRedirect)
Expect(response.Header().Get("Location")).Equals("/")
- Expect(response.Header().Get("Set-Cookie")).ContainsSubstring(web.CookieAuthName + "=;")
+ Expect(response.Header().Get("Set-Cookie")).ContainsSubstring(web.CookieAuthName + "=; Path=/; Expires=")
+ Expect(response.Header().Get("Set-Cookie")).ContainsSubstring("Max-Age=0; HttpOnly")
}
func TestSignInByOAuthHandler(t *testing.T) {
diff --git a/app/models/identity.go b/app/models/identity.go
index cc48bfddb..df014c3b8 100644
--- a/app/models/identity.go
+++ b/app/models/identity.go
@@ -44,8 +44,16 @@ type User struct {
Tenant *Tenant `json:"-"`
Role Role `json:"role"`
Providers []*UserProvider `json:"-"`
+ Status int `json:"status"`
}
+var (
+ //UserActive is the default status for users
+ UserActive = 1
+ //UserDeleted is used for users that chose to delete their accounts
+ UserDeleted = 2
+)
+
//Role is the role of a user inside a tenant
type Role int
diff --git a/app/pkg/dbx/setup.sql b/app/pkg/dbx/setup.sql
index de6e4713b..9ca4068cb 100644
--- a/app/pkg/dbx/setup.sql
+++ b/app/pkg/dbx/setup.sql
@@ -1,19 +1,30 @@
TRUNCATE TABLE tenants RESTART IDENTITY CASCADE;
-INSERT INTO tenants (name, subdomain, created_on, cname, invitation, welcome_message, status, is_private, custom_css) VALUES ('Demonstration', 'demo', now(), '', '', '', 1, false, '');
+INSERT INTO tenants (name, subdomain, created_on, cname, invitation, welcome_message, status, is_private, custom_css)
+VALUES ('Demonstration', 'demo', now(), '', '', '', 1, false, '');
-INSERT INTO users (name, email, tenant_id, created_on, role) VALUES ('Jon Snow', '[email protected]', 1, now(), 3);
-INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_on) VALUES (1, 1, 'facebook', 'FB1234', now());
+INSERT INTO users (name, email, tenant_id, created_on, role, status)
+VALUES ('Jon Snow', '[email protected]', 1, now(), 3, 1);
+INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_on)
+VALUES (1, 1, 'facebook', 'FB1234', now());
-INSERT INTO users (name, email, tenant_id, created_on, role) VALUES ('Arya Stark', '[email protected]', 1, now(), 1);
-INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_on) VALUES (2, 1, 'google', 'GO5678', now());
+INSERT INTO users (name, email, tenant_id, created_on, role, status)
+VALUES ('Arya Stark', '[email protected]', 1, now(), 1, 1);
+INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_on)
+VALUES (2, 1, 'google', 'GO5678', now());
-INSERT INTO users (name, email, tenant_id, created_on, role) VALUES ('Sansa Stark', '[email protected]', 1, now(), 1);
+INSERT INTO users (name, email, tenant_id, created_on, role, status)
+VALUES ('Sansa Stark', '[email protected]', 1, now(), 1, 1);
-INSERT INTO tenants (name, subdomain, created_on, cname, invitation, welcome_message, status, is_private, custom_css) VALUES ('Avengers', 'avengers', now(), 'feedback.avengers.com', '', '', 1, false, '');
+INSERT INTO tenants (name, subdomain, created_on, cname, invitation, welcome_message, status, is_private, custom_css)
+VALUES ('Avengers', 'avengers', now(), 'feedback.avengers.com', '', '', 1, false, '');
-INSERT INTO users (name, email, tenant_id, created_on, role) VALUES ('Tony Stark', '[email protected]', 2, now(), 3);
-INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_on) VALUES (4, 2, 'facebook', 'FB2222', now());
+INSERT INTO users (name, email, tenant_id, created_on, role, status)
+VALUES ('Tony Stark', '[email protected]', 2, now(), 3, 1);
+INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_on)
+VALUES (4, 2, 'facebook', 'FB2222', now());
-INSERT INTO users (name, email, tenant_id, created_on, role) VALUES ('The Hulk', '[email protected]', 2, now(), 1);
-INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_on) VALUES (5, 2, 'google', 'GO1111', now());
+INSERT INTO users (name, email, tenant_id, created_on, role, status)
+VALUES ('The Hulk', '[email protected]', 2, now(), 1, 1);
+INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_on)
+VALUES (5, 2, 'google', 'GO1111', now());
diff --git a/app/pkg/web/context.go b/app/pkg/web/context.go
index 5bf1f328c..75245edfe 100644
--- a/app/pkg/web/context.go
+++ b/app/pkg/web/context.go
@@ -336,9 +336,11 @@ func (ctx *Context) AddCookie(name, value string, expires time.Time) {
//RemoveCookie removes a cookie
func (ctx *Context) RemoveCookie(name string) {
ctx.SetCookie(&http.Cookie{
- Name: name,
- MaxAge: -1,
- Expires: time.Now().Add(-100 * time.Hour),
+ Name: name,
+ Path: "/",
+ HttpOnly: true,
+ MaxAge: -1,
+ Expires: time.Now().Add(-100 * time.Hour),
})
}
diff --git a/app/pkg/web/renderer.go b/app/pkg/web/renderer.go
index 1121609e4..247e7738d 100644
--- a/app/pkg/web/renderer.go
+++ b/app/pkg/web/renderer.go
@@ -150,6 +150,7 @@ func (r *Renderer) Render(w io.Writer, name string, props Props, ctx *Context) {
"name": u.Name,
"email": u.Email,
"role": u.Role,
+ "status": u.Status,
"isAdministrator": u.IsAdministrator(),
"isCollaborator": u.IsCollaborator(),
}
diff --git a/app/storage/inmemory/user.go b/app/storage/inmemory/user.go
index 8ab4c01c0..63f78dde3 100644
--- a/app/storage/inmemory/user.go
+++ b/app/storage/inmemory/user.go
@@ -59,6 +59,7 @@ func (s *UserStorage) GetByProvider(provider string, uid string) (*models.User,
// Register creates a new user based on given information
func (s *UserStorage) Register(user *models.User) error {
+ user.Status = models.UserActive
if user.ID == 0 {
s.lastID = s.lastID + 1
user.ID = s.lastID
@@ -140,3 +141,13 @@ func (s *UserStorage) GetUserSettings() (map[string]string, error) {
func (s *UserStorage) HasSubscribedTo(ideaID int) (bool, error) {
return false, nil
}
+
+// Delete removes current user personal data and mark it as deleted
+func (s *UserStorage) Delete() error {
+ s.user.Name = ""
+ s.user.Email = ""
+ s.user.Role = models.RoleVisitor
+ s.user.Status = models.UserDeleted
+ s.user.Providers = make([]*models.UserProvider, 0)
+ return nil
+}
diff --git a/app/storage/postgres/idea.go b/app/storage/postgres/idea.go
index 6cc600c2b..eac9eb380 100644
--- a/app/storage/postgres/idea.go
+++ b/app/storage/postgres/idea.go
@@ -165,12 +165,14 @@ var (
u.name AS user_name,
u.email AS user_email,
u.role AS user_role,
+ u.status AS user_status,
i.response,
i.response_date,
r.id AS response_user_id,
r.name AS response_user_name,
r.email AS response_user_email,
r.role AS response_user_role,
+ r.status AS response_user_status,
d.number AS original_number,
d.title AS original_title,
d.slug AS original_slug,
@@ -324,10 +326,12 @@ func (s *IdeaStorage) GetCommentsByIdea(idea *models.Idea) ([]*models.Comment, e
u.name AS user_name,
u.email AS user_email,
u.role AS user_role,
+ u.status AS user_status,
e.id AS edited_by_id,
e.name AS edited_by_name,
e.email AS edited_by_email,
- e.role AS edited_by_role
+ e.role AS edited_by_role,
+ e.status AS edited_by_status
FROM comments c
INNER JOIN ideas i
ON i.id = c.idea_id
@@ -418,10 +422,12 @@ func (s *IdeaStorage) GetCommentByID(id int) (*models.Comment, error) {
u.name AS user_name,
u.email AS user_email,
u.role AS user_role,
+ u.status AS user_status,
e.id AS edited_by_id,
e.name AS edited_by_name,
e.email AS edited_by_email,
- e.role AS edited_by_role
+ e.role AS edited_by_role,
+ e.status AS edited_by_status
FROM comments c
INNER JOIN users u
ON u.id = c.user_id
@@ -528,13 +534,14 @@ func (s *IdeaStorage) GetActiveSubscribers(number int, channel models.Notificati
if len(event.RequiresSubscripionUserRoles) == 0 {
err = s.trx.Select(&users, `
- SELECT DISTINCT u.id, u.name, u.email, u.tenant_id, u.role
+ SELECT DISTINCT u.id, u.name, u.email, u.tenant_id, u.role, u.status
FROM users u
LEFT JOIN user_settings set
ON set.user_id = u.id
AND set.tenant_id = u.tenant_id
AND set.key = $1
WHERE u.tenant_id = $2
+ AND u.status = $5
AND (
(set.value IS NULL AND u.role = ANY($3))
OR CAST(set.value AS integer) & $4 > 0
@@ -543,10 +550,11 @@ func (s *IdeaStorage) GetActiveSubscribers(number int, channel models.Notificati
s.tenant.ID,
pq.Array(event.DefaultEnabledUserRoles),
channel,
+ models.UserActive,
)
} else {
err = s.trx.Select(&users, `
- SELECT DISTINCT u.id, u.name, u.email, u.tenant_id, u.role
+ SELECT DISTINCT u.id, u.name, u.email, u.tenant_id, u.role, u.status
FROM users u
LEFT JOIN idea_subscribers sub
ON sub.user_id = u.id
@@ -557,6 +565,7 @@ func (s *IdeaStorage) GetActiveSubscribers(number int, channel models.Notificati
AND set.key = $3
AND set.tenant_id = u.tenant_id
WHERE u.tenant_id = $4
+ AND u.status = $8
AND ( sub.status = $2 OR (sub.status IS NULL AND NOT u.role = ANY($7)) )
AND (
(set.value IS NULL AND u.role = ANY($5))
@@ -569,6 +578,7 @@ func (s *IdeaStorage) GetActiveSubscribers(number int, channel models.Notificati
pq.Array(event.DefaultEnabledUserRoles),
channel,
pq.Array(event.RequiresSubscripionUserRoles),
+ models.UserActive,
)
}
diff --git a/app/storage/postgres/user.go b/app/storage/postgres/user.go
index 9a3ae93b5..0c7b1f23d 100644
--- a/app/storage/postgres/user.go
+++ b/app/storage/postgres/user.go
@@ -1,6 +1,7 @@
package postgres
import (
+ "fmt"
"strings"
"time"
@@ -18,6 +19,7 @@ type dbUser struct {
Email sql.NullString `db:"email"`
Tenant *dbTenant `db:"tenant"`
Role sql.NullInt64 `db:"role"`
+ Status sql.NullInt64 `db:"status"`
Providers []*dbUserProvider
}
@@ -38,6 +40,7 @@ func (u *dbUser) toModel() *models.User {
Tenant: u.Tenant.toModel(),
Role: models.Role(u.Role.Int64),
Providers: make([]*models.UserProvider, len(u.Providers)),
+ Status: int(u.Status.Int64),
}
for i, p := range u.Providers {
@@ -116,10 +119,11 @@ func (s *UserStorage) GetByProvider(provider string, uid string) (*models.User,
// Register creates a new user based on given information
func (s *UserStorage) Register(user *models.User) error {
now := time.Now()
+ user.Status = models.UserActive
user.Email = strings.TrimSpace(user.Email)
if err := s.trx.Get(&user.ID,
- "INSERT INTO users (name, email, created_on, tenant_id, role) VALUES ($1, $2, $3, $4, $5) RETURNING id",
- user.Name, user.Email, now, s.tenant.ID, user.Role); err != nil {
+ "INSERT INTO users (name, email, created_on, tenant_id, role, status) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id",
+ user.Name, user.Email, now, s.tenant.ID, user.Role, models.UserActive); err != nil {
return errors.Wrap(err, "failed to register new user")
}
@@ -222,7 +226,7 @@ func (s *UserStorage) ChangeEmail(userID int, email string) error {
// GetByID returns a user based on given id
func getUser(trx *dbx.Trx, filter string, args ...interface{}) (*models.User, error) {
user := dbUser{}
- err := trx.Get(&user, "SELECT id, name, email, tenant_id, role FROM users WHERE "+filter, args...)
+ err := trx.Get(&user, "SELECT id, name, email, tenant_id, role, status FROM users WHERE "+filter, args...)
if err != nil {
return nil, err
}
@@ -238,7 +242,7 @@ func getUser(trx *dbx.Trx, filter string, args ...interface{}) (*models.User, er
// GetAll return all users of current tenant
func (s *UserStorage) GetAll() ([]*models.User, error) {
var users []*dbUser
- err := s.trx.Select(&users, "SELECT id, name, email, tenant_id, role FROM users WHERE tenant_id = $1 ORDER BY id", s.tenant.ID)
+ err := s.trx.Select(&users, "SELECT id, name, email, tenant_id, role, status FROM users WHERE tenant_id = $1 ORDER BY id", s.tenant.ID)
if err != nil {
return nil, errors.Wrap(err, "failed to get all users")
}
@@ -279,3 +283,37 @@ func (s *UserStorage) HasSubscribedTo(ideaID int) (bool, error) {
return false, nil
}
+
+// Delete removes current user personal data and mark it as deleted
+func (s *UserStorage) Delete() error {
+ if _, err := s.trx.Execute(
+ "UPDATE users SET role = $3, status = $4, name = '', email = '' WHERE id = $1 AND tenant_id = $2",
+ s.user.ID, s.tenant.ID, models.RoleVisitor, models.UserDeleted,
+ ); err != nil {
+ return errors.Wrap(err, "failed to delete current user")
+ }
+
+ var tables = []struct {
+ name string
+ userColumn string
+ }{
+ {"user_providers", "user_id"},
+ {"user_settings", "user_id"},
+ {"notifications", "user_id"},
+ {"notifications", "author_id"},
+ {"idea_supporters", "user_id"},
+ {"idea_subscribers", "user_id"},
+ {"email_verifications", "user_id"},
+ }
+
+ for _, table := range tables {
+ if _, err := s.trx.Execute(
+ fmt.Sprintf("DELETE FROM %s WHERE %s = $1 AND tenant_id = $2", table.name, table.userColumn),
+ s.user.ID, s.tenant.ID,
+ ); err != nil {
+ return errors.Wrap(err, "failed to delete current user's %s records", table)
+ }
+ }
+
+ return nil
+}
diff --git a/app/storage/postgres/user_test.go b/app/storage/postgres/user_test.go
index 99d33fb34..efd4214ae 100644
--- a/app/storage/postgres/user_test.go
+++ b/app/storage/postgres/user_test.go
@@ -112,6 +112,7 @@ func TestUserStorage_Register(t *testing.T) {
Expect(user.Role).Equals(models.RoleCollaborator)
Expect(user.Name).Equals("Rob Stark")
Expect(user.Email).Equals("[email protected]")
+ Expect(user.Status).Equals(models.UserActive)
}
func TestUserStorage_Register_WhiteSpaceEmail(t *testing.T) {
@@ -132,6 +133,7 @@ func TestUserStorage_Register_WhiteSpaceEmail(t *testing.T) {
Expect(user.Role).Equals(models.RoleCollaborator)
Expect(user.Name).Equals("Rob Stark")
Expect(user.Email).Equals("")
+ Expect(user.Status).Equals(models.UserActive)
}
func TestUserStorage_Register_MultipleProviders(t *testing.T) {
@@ -169,6 +171,7 @@ func TestUserStorage_Register_MultipleProviders(t *testing.T) {
Expect(user.ID).NotEquals(0)
Expect(user.Name).Equals("Jon Snow")
Expect(user.Email).Equals("[email protected]")
+ Expect(user.Status).Equals(models.UserActive)
}
func TestUserStorage_RegisterProvider(t *testing.T) {
@@ -187,6 +190,7 @@ func TestUserStorage_RegisterProvider(t *testing.T) {
Expect(user.Name).Equals("Jon Snow")
Expect(user.Email).Equals("[email protected]")
Expect(user.Tenant.ID).Equals(1)
+ Expect(user.Status).Equals(models.UserActive)
Expect(user.Providers).HasLen(2)
Expect(user.Providers[0].UID).Equals("FB1234")
@@ -249,8 +253,11 @@ func TestUserStorage_GetAll(t *testing.T) {
Expect(err).IsNil()
Expect(all).HasLen(3)
Expect(all[0].Name).Equals("Jon Snow")
+ Expect(all[0].Status).Equals(models.UserActive)
Expect(all[1].Name).Equals("Arya Stark")
+ Expect(all[1].Status).Equals(models.UserActive)
Expect(all[2].Name).Equals("Sansa Stark")
+ Expect(all[2].Status).Equals(models.UserActive)
}
func TestUserStorage_DefaultUserSettings(t *testing.T) {
@@ -296,3 +303,26 @@ func TestUserStorage_SaveGetUserSettings(t *testing.T) {
newSettings, _ := users.GetUserSettings()
Expect(newSettings).Equals(settings)
}
+
+func TestUserStorage_Delete(t *testing.T) {
+ SetupDatabaseTest(t)
+ defer TeardownDatabaseTest()
+
+ users.SetCurrentTenant(demoTenant)
+ users.SetCurrentUser(jonSnow)
+
+ err := users.Delete()
+ Expect(err).IsNil()
+
+ user, err := users.GetByEmail("[email protected]")
+ Expect(errors.Cause(err)).Equals(app.ErrNotFound)
+ Expect(user).IsNil()
+
+ user, err = users.GetByID(jonSnow.ID)
+ Expect(err).IsNil()
+ Expect(user.Name).Equals("")
+ Expect(user.Email).Equals("")
+ Expect(user.Role).Equals(models.RoleVisitor)
+ Expect(user.Status).Equals(models.UserDeleted)
+ Expect(user.Providers).HasLen(0)
+}
diff --git a/app/storage/storage.go b/app/storage/storage.go
index dc1ff6996..621ec4ac6 100644
--- a/app/storage/storage.go
+++ b/app/storage/storage.go
@@ -47,6 +47,7 @@ type User interface {
Register(user *models.User) error
RegisterProvider(userID int, provider *models.UserProvider) error
Update(settings *models.UpdateUserSettings) error
+ Delete() error
ChangeEmail(userID int, email string) error
ChangeRole(userID int, role models.Role) error
GetAll() ([]*models.User, error)
diff --git a/migrations/201805261834_add_user_status.up.sql b/migrations/201805261834_add_user_status.up.sql
new file mode 100644
index 000000000..354ce2d57
--- /dev/null
+++ b/migrations/201805261834_add_user_status.up.sql
@@ -0,0 +1,5 @@
+ALTER TABLE users ADD status INT NULL;
+
+UPDATE users SET status = 1;
+
+ALTER TABLE users ALTER COLUMN status SET NOT NULL;
\ No newline at end of file
diff --git a/public/components/common/Gravatar.tsx b/public/components/common/Gravatar.tsx
index 161cf0e74..d634f63d7 100644
--- a/public/components/common/Gravatar.tsx
+++ b/public/components/common/Gravatar.tsx
@@ -2,22 +2,20 @@ import "./Gravatar.scss";
import * as React from "react";
import { page, classSet } from "@fider/services";
-import { User, UserRole } from "@fider/models";
+import { User, UserRole, UserStatus, CurrentUser } from "@fider/models";
interface GravatarProps {
user?: User;
}
export const Gravatar = (props: GravatarProps) => {
- const name = props.user ? props.user.name : "_";
const id = props.user ? props.user.id : 0;
-
- const url = `${page.getBaseUrl()}/avatars/50/${id}/${encodeURIComponent(name)}`;
- const isCollaborator = props.user ? props.user.role >= UserRole.Collaborator : false;
+ const name = props.user ? props.user.name : "";
+ const url = `${page.getBaseUrl()}/avatars/50/${id}/${encodeURIComponent(name || "?")}`;
const className = classSet({
"c-avatar": true,
- "m-staff": isCollaborator
+ "m-staff": props.user && props.user.role >= UserRole.Collaborator
});
return <img className={className} title={name} src={url} />;
diff --git a/public/components/common/Modal.tsx b/public/components/common/Modal.tsx
index 8fd44a480..45fcea876 100644
--- a/public/components/common/Modal.tsx
+++ b/public/components/common/Modal.tsx
@@ -11,6 +11,7 @@ interface ModalWindowProps {
size?: "small" | "large";
canClose?: boolean;
center?: boolean;
+ onClose?: () => void;
}
interface ModalWindowState {
@@ -65,6 +66,9 @@ class ModalWindow extends React.Component<ModalWindowProps, ModalWindowState> {
private close = () => {
if (this.props.canClose) {
this.setState({ isOpen: false });
+ if (this.props.onClose) {
+ this.props.onClose();
+ }
}
};
diff --git a/public/components/common/UserName.tsx b/public/components/common/UserName.tsx
index 7c6690dae..294413e82 100644
--- a/public/components/common/UserName.tsx
+++ b/public/components/common/UserName.tsx
@@ -1,7 +1,7 @@
import "./UserName.scss";
import * as React from "react";
-import { User, UserRole } from "@fider/models";
+import { User, UserRole, CurrentUser } from "@fider/models";
import { classSet } from "@fider/services";
interface UserNameProps {
@@ -9,12 +9,10 @@ interface UserNameProps {
}
export const UserName = (props: UserNameProps) => {
- const isCollaborator = props.user.role >= UserRole.Collaborator;
-
const className = classSet({
"c-username": true,
- "m-staff": isCollaborator
+ "m-staff": props.user.role >= UserRole.Collaborator
});
- return <span className={className}>{props.user.name}</span>;
+ return <span className={className}>{props.user.name || "Anonymous"}</span>;
};
diff --git a/public/models/identity.ts b/public/models/identity.ts
index 156ee1e97..1b6528697 100644
--- a/public/models/identity.ts
+++ b/public/models/identity.ts
@@ -13,6 +13,12 @@ export interface User {
id: number;
name: string;
role: UserRole;
+ status: UserStatus;
+}
+
+export enum UserStatus {
+ Active = 1,
+ Deleted = 2
}
export enum UserRole {
@@ -26,6 +32,7 @@ export interface CurrentUser {
name: string;
email: string;
role: UserRole;
+ status: UserStatus;
isAdministrator: boolean;
isCollaborator: boolean;
}
diff --git a/public/pages/MySettings/MySettings.page.scss b/public/pages/MySettings/MySettings.page.scss
index ec47f5d22..fb1f815be 100644
--- a/public/pages/MySettings/MySettings.page.scss
+++ b/public/pages/MySettings/MySettings.page.scss
@@ -1,3 +1,5 @@
+@import '~@fider/assets/styles/variables.scss';
+
#p-my-settings {
#confirmation-modal {
text-align: center;
@@ -14,4 +16,11 @@
font-weight: 600;
}
}
+
+ .l-danger-zone {
+ h4 {
+ margin-top: 50px;
+ color: $red;
+ }
+ }
}
\ No newline at end of file
diff --git a/public/pages/MySettings/MySettings.page.tsx b/public/pages/MySettings/MySettings.page.tsx
index 83659d873..556717ad3 100644
--- a/public/pages/MySettings/MySettings.page.tsx
+++ b/public/pages/MySettings/MySettings.page.tsx
@@ -3,7 +3,7 @@ import "./MySettings.page.scss";
import * as React from "react";
import { Modal, Form, DisplayError, Button, Gravatar, Heading, Field, Input } from "@fider/components";
-import { NotificationSettings } from "./";
+import { DangerZone, NotificationSettings } from "./";
import { CurrentUser, UserSettings } from "@fider/models";
import { Failure, actions } from "@fider/services";
@@ -153,11 +153,17 @@ export class MySettingsPage extends React.Component<MySettingsPageProps, MySetti
/>
<Button color="positive" onClick={this.confirm}>
- Confirm
+ Save changes
</Button>
</Form>
</div>
</div>
+
+ <div className="row">
+ <div className="col-lg-7">
+ <DangerZone user={this.props.user} />
+ </div>
+ </div>
</div>
);
}
diff --git a/public/pages/MySettings/components/DangerZone.tsx b/public/pages/MySettings/components/DangerZone.tsx
new file mode 100644
index 000000000..6f90dd082
--- /dev/null
+++ b/public/pages/MySettings/components/DangerZone.tsx
@@ -0,0 +1,77 @@
+import * as React from "react";
+
+import { CurrentUser, UserSettings } from "@fider/models";
+import { Toggle, Segment, Segments, Field, Button, Modal, ButtonClickEvent } from "@fider/components";
+import { actions, page, notify } from "@fider/services";
+
+interface DangerZoneProps {
+ user: CurrentUser;
+}
+
+interface DangerZoneState {
+ clicked: boolean;
+}
+
+export class DangerZone extends React.Component<DangerZoneProps, DangerZoneState> {
+ constructor(props: DangerZoneProps) {
+ super(props);
+ this.state = {
+ clicked: false
+ };
+ }
+
+ public onClickDelete = async () => {
+ this.setState({ clicked: true });
+ };
+
+ public onCancel = async () => {
+ this.setState({ clicked: false });
+ };
+
+ public onConfirm = async (e: ButtonClickEvent) => {
+ const response = await actions.deleteCurrentAccount();
+ if (response.ok) {
+ e.preventEnable();
+ page.goHome();
+ } else {
+ notify.error("Failed to delete your account. Try again later");
+ }
+ };
+
+ public render() {
+ return (
+ <div className="l-danger-zone">
+ <Modal.Window canClose={true} isOpen={this.state.clicked} center={false} onClose={this.onCancel}>
+ <Modal.Header>Delete account</Modal.Header>
+ <Modal.Content>
+ <p>
+ When you choose to delete your account, we will erase all your personal information forever. The content
+ you have published will remain, but it will be anonymised.
+ </p>
+ <p>
+ This process is irreversible. <strong>Are you sure?</strong>
+ </p>
+ </Modal.Content>
+ <Modal.Footer>
+ <Button color="danger" size="tiny" onClick={this.onConfirm}>
+ Confirm
+ </Button>
+ <Button size="tiny" onClick={this.onCancel}>
+ Cancel
+ </Button>
+ </Modal.Footer>
+ </Modal.Window>
+
+ <h4>Delete account</h4>
+ <p className="info">
+ When you choose to delete your account, we will erase all your personal information forever. The content you
+ have published will remain, but it will be anonymised.
+ </p>
+ <p className="info">This process is irreversible. Please be certain.</p>
+ <Button color="danger" size="tiny" onClick={this.onClickDelete}>
+ Delete My Account
+ </Button>
+ </div>
+ );
+ }
+}
diff --git a/public/pages/MySettings/index.ts b/public/pages/MySettings/index.ts
index 992f2ac78..b4ff3c99e 100644
--- a/public/pages/MySettings/index.ts
+++ b/public/pages/MySettings/index.ts
@@ -1,2 +1,3 @@
export * from "./MySettings.page";
export * from "./components/NotificationSettings";
+export * from "./components/DangerZone";
diff --git a/public/pages/UI/UIToolkit.page.tsx b/public/pages/UI/UIToolkit.page.tsx
index 2a2f9bab1..650c7ad17 100644
--- a/public/pages/UI/UIToolkit.page.tsx
+++ b/public/pages/UI/UIToolkit.page.tsx
@@ -1,5 +1,5 @@
import * as React from "react";
-import { CurrentUser, IdeaStatus } from "@fider/models";
+import { CurrentUser, IdeaStatus, UserStatus } from "@fider/models";
import {
Heading,
Button,
@@ -27,13 +27,15 @@ import { notify, Failure } from "@fider/services";
const jonSnow: User = {
id: 0,
name: "Jon Snow",
- role: UserRole.Administrator
+ role: UserRole.Administrator,
+ status: UserStatus.Active
};
const aryaStark: User = {
id: 0,
name: "Arya Snow",
- role: UserRole.Visitor
+ role: UserRole.Visitor,
+ status: UserStatus.Active
};
const easyTag: Tag = { id: 2, slug: "easy", name: "Easy", color: "00a3a5", isPublic: true };
diff --git a/public/services/actions/user.ts b/public/services/actions/user.ts
index 6847e4971..2799aacbf 100644
--- a/public/services/actions/user.ts
+++ b/public/services/actions/user.ts
@@ -13,3 +13,7 @@ export const changeUserEmail = async (email: string): Promise<Result> => {
email
});
};
+
+export const deleteCurrentAccount = async (): Promise<Result> => {
+ return await http.delete("/api/user");
+};