on master help sign in
Got delete working
commit39837b5495d53a0c2262763b6309c0d0dc7524d8 authoriko <ilyakooo0@gmail.com> dateSat 13 Aug 2022, 20:30 (4 years ago) parentb191b74
8 files changed+55−5
backend/BW.js+1 backend/BW.purs+1 backend/Bridge.purs+2 backend/Main.purs+7 bridge.yaml+2 frontend/Bridge.elm+6 frontend/Main.elm+15−2 frontend/Pages/EditCipher.elm+21−3
backend/BW.js+1
@@ -79,6 +79,7 @@ export function getServices() {
7979 getSync: () => api.getSync().then(sanitize),
8080 postCipherCreate: (cipher) => api.postCipherCreate(makeCipherCreateRequest(cipher)),
8181 putCipher: (cipher) => api.putCipher(cipher.id, makeCipherRequest(cipher)),
82+ deleteCipher: (id) => api.deleteCipher(id),
8283 }
8384 },
8485 crypto: bg.cryptoService,
backend/BW.purs+1
@@ -34,6 +34,7 @@ type ApiService
3434 , getSync :: Unit -> Promise SyncResponse
3535 , postCipherCreate :: CipherResponse -> Promise CipherResponse
3636 , putCipher :: CipherResponse -> Promise CipherResponse
37+ , deleteCipher :: String -> Promise Unit
3738 }
3839
3940type PasswordGeneration =
backend/Bridge.purs+2
@@ -449,6 +449,7 @@ derive instance ordCmd_Login :: Ord Cmd_Login
449449data Cmd =
450450 Copy String
451451 | CreateCipher FullCipher
452+ | DeleteCipher FullCipher
452453 | GeneratePassword PasswordGeneratorConfig
453454 | Init
454455 | Login Cmd_Login
@@ -561,6 +562,7 @@ derive instance ordSub_NeedsMasterPassword :: Ord Sub_NeedsMasterPassword
561562data Sub =
562563 CaptchaDone
563564 | CipherChanged FullCipher
565+ | CipherDeleted FullCipher
564566 | Error String
565567 | GeneratedPassword String
566568 | LoadCipher FullCipher
backend/Main.purs+7
@@ -206,6 +206,13 @@ main = do
206206 send $ Bridge.CipherChanged newCipher
207207 performSync
208208 pure unit
209+ Bridge.DeleteCipher c@(Bridge.FullCipher { id, name }) ->
210+ runWithDecryptionKey do
211+ api <- getAuthedApi
212+ liftPromise $ api.deleteCipher id
213+ send $ Bridge.CipherDeleted c
214+ performSync
215+ pure unit
209216
210217processCipher ::
211218 forall r.
bridge.yaml+2
@@ -19,6 +19,7 @@ Sub:
1919- RecieveEmail: String
2020- CipherChanged: FullCipher
2121- GeneratedPassword: String
22+- CipherDeleted: FullCipher
2223
2324Cmd:
2425- Init
@@ -36,6 +37,7 @@ Cmd:
3637- UpdateCipher: FullCipher
3738- CreateCipher: FullCipher
3839- GeneratePassword: PasswordGeneratorConfig
40+- DeleteCipher: FullCipher
3941
4042FullCipher:
4143 reprompt: Int
frontend/Bridge.elm+6
@@ -503,6 +503,7 @@ jsonEncCmd_Login val =
503503type Cmd =
504504 Copy String
505505 | CreateCipher FullCipher
506+ | DeleteCipher FullCipher
506507 | GeneratePassword PasswordGeneratorConfig
507508 | Init
508509 | Login Cmd_Login
@@ -519,6 +520,7 @@ jsonDecCmd =
519520 let jsonDecDictCmd = Dict.fromList
520521 [ ("Copy", Json.Decode.lazy (\_ -> Json.Decode.map Copy (Json.Decode.string)))
521522 , ("CreateCipher", Json.Decode.lazy (\_ -> Json.Decode.map CreateCipher (jsonDecFullCipher)))
523+ , ("DeleteCipher", Json.Decode.lazy (\_ -> Json.Decode.map DeleteCipher (jsonDecFullCipher)))
522524 , ("GeneratePassword", Json.Decode.lazy (\_ -> Json.Decode.map GeneratePassword (jsonDecPasswordGeneratorConfig)))
523525 , ("Init", Json.Decode.lazy (\_ -> Json.Decode.succeed Init))
524526 , ("Login", Json.Decode.lazy (\_ -> Json.Decode.map Login (jsonDecCmd_Login)))
@@ -538,6 +540,7 @@ jsonEncCmd val =
538540 let keyval v = case v of
539541 Copy v1 -> ("Copy", encodeValue (Json.Encode.string v1))
540542 CreateCipher v1 -> ("CreateCipher", encodeValue (jsonEncFullCipher v1))
543+ DeleteCipher v1 -> ("DeleteCipher", encodeValue (jsonEncFullCipher v1))
541544 GeneratePassword v1 -> ("GeneratePassword", encodeValue (jsonEncPasswordGeneratorConfig v1))
542545 Init -> ("Init", encodeValue (Json.Encode.list identity []))
543546 Login v1 -> ("Login", encodeValue (jsonEncCmd_Login v1))
@@ -700,6 +703,7 @@ jsonEncSub_NeedsMasterPassword val =
700703type Sub =
701704 CaptchaDone
702705 | CipherChanged FullCipher
706+ | CipherDeleted FullCipher
703707 | Error String
704708 | GeneratedPassword String
705709 | LoadCipher FullCipher
@@ -717,6 +721,7 @@ jsonDecSub =
717721 let jsonDecDictSub = Dict.fromList
718722 [ ("CaptchaDone", Json.Decode.lazy (\_ -> Json.Decode.succeed CaptchaDone))
719723 , ("CipherChanged", Json.Decode.lazy (\_ -> Json.Decode.map CipherChanged (jsonDecFullCipher)))
724+ , ("CipherDeleted", Json.Decode.lazy (\_ -> Json.Decode.map CipherDeleted (jsonDecFullCipher)))
720725 , ("Error", Json.Decode.lazy (\_ -> Json.Decode.map Error (Json.Decode.string)))
721726 , ("GeneratedPassword", Json.Decode.lazy (\_ -> Json.Decode.map GeneratedPassword (Json.Decode.string)))
722727 , ("LoadCipher", Json.Decode.lazy (\_ -> Json.Decode.map LoadCipher (jsonDecFullCipher)))
@@ -737,6 +742,7 @@ jsonEncSub val =
737742 let keyval v = case v of
738743 CaptchaDone -> ("CaptchaDone", encodeValue (Json.Encode.list identity []))
739744 CipherChanged v1 -> ("CipherChanged", encodeValue (jsonEncFullCipher v1))
745+ CipherDeleted v1 -> ("CipherDeleted", encodeValue (jsonEncFullCipher v1))
740746 Error v1 -> ("Error", encodeValue (Json.Encode.string v1))
741747 GeneratedPassword v1 -> ("GeneratedPassword", encodeValue (Json.Encode.string v1))
742748 LoadCipher v1 -> ("LoadCipher", encodeValue (jsonEncFullCipher v1))
frontend/Main.elm+15−2
@@ -63,6 +63,7 @@ type Msg
6363 | GeneratePassword Bridge.PasswordGeneratorConfig
6464 | OpenNewCipherEditPage Bridge.CipherType
6565 | WrongPassword
66+ | DeleteCipher Bridge.FullCipher
6667
6768
6869type alias Model =
@@ -227,6 +228,9 @@ subscriptions model =
227228
228229 Bridge.WrongPassword ->
229230 WrongPassword
231+
232+ Bridge.CipherDeleted c ->
233+ ShowInfo "Entry deleted" ("The entry “" ++ c.name ++ "” has been successfully deleted.")
230234 )
231235 ]
232236 ++ optional (List.isEmpty model.notifications |> not) (Time.every 1000 (\t -> ClearNotification { currentTime = t }))
@@ -601,6 +605,15 @@ update msg model =
601605 ]
602606 )
603607
608+ DeleteCipher cipher ->
609+ ( model
610+ , Cmd.batch
611+ [ pureCmd PopView
612+ , pureCmd PopView
613+ , FFI.sendBridge (Bridge.DeleteCipher cipher)
614+ ]
615+ )
616+
604617
605618loginCallbacks : Login.Callbacks Msg
606619loginCallbacks =
@@ -622,12 +635,12 @@ cipherCallbacks =
622635
623636editCipherCallbacks : EditCipher.Callbacks Msg
624637editCipherCallbacks =
625− { save = UpdateCipher, generatePassword = GeneratePassword }
638+ { save = UpdateCipher, generatePassword = GeneratePassword, delete = Just DeleteCipher }
626639
627640
628641createCipherCallbacks : EditCipher.Callbacks Msg
629642createCipherCallbacks =
630− { save = CreateCipher, generatePassword = GeneratePassword }
643+ { save = CreateCipher, generatePassword = GeneratePassword, delete = Nothing }
631644
632645
633646captchaCallbacks : Captcha.Callbacks
frontend/Pages/EditCipher.elm+21−3
@@ -24,11 +24,13 @@ type Msg
2424 | OpenGeneratePasword
2525 | CloseGeneratePassword
2626 | GeneratePassword Bridge.PasswordGeneratorConfig
27+ | Delete
2728
2829
2930type alias Callbacks msg =
3031 { save : Bridge.FullCipher -> msg
3132 , generatePassword : Bridge.PasswordGeneratorConfig -> msg
33+ , delete : Maybe (Bridge.FullCipher -> msg)
3234 }
3335
3436
@@ -110,6 +112,12 @@ update _ msg model =
110112 GeneratePassword cfg ->
111113 ( Ok model, pureCmd (model.callbacks.generatePassword cfg) )
112114
115+ Delete ->
116+ ( Ok model
117+ , Maybe.withDefault Cmd.none
118+ (Maybe.map (\f -> f model.fullCipher |> pureCmd) model.callbacks.delete)
119+ )
120+
113121
114122subscriptions : Model emsg -> Sub Msg
115123subscriptions _ =
@@ -131,7 +139,7 @@ row { name, nameIcon, attrs } =
131139
132140
133141view : Model emsg -> List (Html Msg)
134−view { fullCipher, passwordGenerator } =
142+view { fullCipher, passwordGenerator, callbacks } =
135143 maybeList passwordGenerator
136144 (\x ->
137145 modal
@@ -256,7 +264,8 @@ view { fullCipher, passwordGenerator } =
256264 , Attr.type_ "text"
257265 , Attr.value (Maybe.withDefault "" expMonth)
258266 , Ev.onInput (\x -> edit { cipher | expMonth = Just x })
259− , Attr.style "width" "20%"
267+ , Attr.style "width" "30%"
268+ , Attr.style "min-width" "initial"
260269 , Attr.class "u-align--right"
261270 ]
262271 []
@@ -266,7 +275,8 @@ view { fullCipher, passwordGenerator } =
266275 , Attr.type_ "text"
267276 , Attr.value (Maybe.withDefault "" expYear)
268277 , Ev.onInput (\x -> edit { cipher | expYear = Just x })
269− , Attr.style "width" "20%"
278+ , Attr.style "width" "30%"
279+ , Attr.style "min-width" "initial"
270280 ]
271281 []
272282 ]
@@ -432,6 +442,14 @@ view { fullCipher, passwordGenerator } =
432442 }
433443 ]
434444 )
445+ ++ optional (callbacks.delete /= Nothing)
446+ (button
447+ [ Attr.style "width" "100%"
448+ , Attr.class "p-button--negative"
449+ , Ev.onClick Delete
450+ ]
451+ [ text "Delete" ]
452+ )
435453
436454
437455iconButton : String -> msg -> Html msg