Skip to content

Commit

Permalink
Enhancement/contract update (#676)
Browse files Browse the repository at this point in the history
* Update claimaction call

* Update verifyclaim calls

* Replace newobjective and updobjective to use upsertobjctv

* Update upsertaction call

* Fix according to elm-review

* Add image parameter to uspertaction

* Show insufficient permissions modal

* Translate permission error modal

* Fix portuguese translation keys for insufficient permissions

* Fetch roles with profile

* Check permissions for claiming actions

* Specify all needed permissions

* Fix according to elm-review

* Show insufficient permissions modal if user doesnt have invite permission

* Fix logic for action claiming permissions

* Fix insufficient permissions modal styles
  • Loading branch information
henriquecbuss committed Feb 23, 2022
1 parent b914f15 commit 3d4b408
Show file tree
Hide file tree
Showing 25 changed files with 345 additions and 85 deletions.
1 change: 1 addition & 0 deletions public/images/girl-with-ice-cube.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions public/translations/amh-ETH.json
Original file line number Diff line number Diff line change
Expand Up @@ -1255,5 +1255,11 @@
"eos_plural": "Eos",
"eth_plural": "ቢትኮይን",
"usd_plural": "ዶላር"
},
"permissions": {
"insufficient": "እርምጃ አይፈቀድም",
"explanation": "ይህን እርምጃ ለመፈጸም የሚያስፈልጉት ፈቃዶች የሎትም። ተጨማሪ ፈቃዶችን እንዴት ማግኘት እንደሚችሉ ለማወቅ የማህበረሰብ አስተዳዳሪዎችን ያግኙ።",
"try_again": "እባክዎ በቂ ፍቃዶች ካገኙ በኋላ እንደገና ይሞክሩ!",
"ok": "ገብቶኛል"
}
}
8 changes: 8 additions & 0 deletions public/translations/cat-CAT.json
Original file line number Diff line number Diff line change
Expand Up @@ -1296,5 +1296,13 @@
"eos_plural": "Eos",
"eth_plural": "Ethereum",
"usd_plural": "Dòlars"
},
"permissions": {
"insufficient": {
"title": "Acció no permesa",
"explanation": "No teniu els permisos necessaris per dur a terme aquesta acció. Poseu-vos en contacte amb els administradors de la comunitat per saber com obtenir més permisos.",
"try_again": "Si us plau, torneu-ho a provar quan tingueu prou permisos!",
"ok": "Entès"
}
}
}
8 changes: 8 additions & 0 deletions public/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1294,5 +1294,13 @@
"eos_plural": "Eos",
"eth_plural": "Ethereum",
"usd_plural": "Dollars"
},
"permissions": {
"insufficient": {
"title": "Action not allowed",
"explanation": "You don't have the permissions needed to perform this action. Reach out to the community admins to know how to get more permissions.",
"try_again": "Please try again once you have enough permissions!",
"ok": "Got it"
}
}
}
8 changes: 8 additions & 0 deletions public/translations/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -1297,5 +1297,13 @@
"eos_plural": "Eos",
"eth_plural": "Ethereum",
"usd_plural": "Dolares"
},
"permissions": {
"insufficient": {
"title": "Acción no permitida",
"explanation": "No tienes los permisos necesarios para realizar esta acción. Comuníquese con los administradores de la comunidad para saber cómo obtener más permisos.",
"try_again": "¡Vuelva a intentarlo una vez que tenga suficientes permisos!",
"ok": "Entendí"
}
}
}
8 changes: 8 additions & 0 deletions public/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1300,5 +1300,13 @@
"eos_plural": "Eos",
"eth_plural": "Ethereum",
"usd_plural": "Dólares"
},
"permissions": {
"insufficient": {
"title": "Ação não permitida",
"explanation": "Você não tem as permissões necessárias para realizar esta ação. Contate os administradores da comunidade para saber como ganhar mais permissões.",
"try_again": "Por favor tente novamente quando tiver permissões o suficiente!",
"ok": "Entendi"
}
}
}
98 changes: 60 additions & 38 deletions src/elm/Action.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Action exposing
, ActionFeedback(..)
, ClaimingActionStatus(..)
, Community
, ExternalMsg(..)
, Model
, Msg(..)
, Objective
Expand All @@ -20,6 +21,7 @@ module Action exposing
, viewSearchActions
)

import Cambiatus.Enum.Permission as Permission exposing (Permission)
import Cambiatus.Enum.VerificationType as VerificationType exposing (VerificationType)
import Cambiatus.Object
import Cambiatus.Object.Action as ActionObject
Expand Down Expand Up @@ -127,19 +129,29 @@ type Msg
| Tick Time.Posix


type ExternalMsg
= SentFeedback Feedback.Model
| ShowInsufficientPermissions


update :
Bool
-> List Permission
-> Shared
-> Symbol
-> Eos.Name
-> Msg
-> Model
-> UR.UpdateResult Model Msg Feedback.Model
update isPinConfirmed shared selectedCommunity accName msg model =
-> UR.UpdateResult Model Msg ExternalMsg
update isPinConfirmed permissions shared selectedCommunity accName msg model =
let
{ t, tr } =
shared.translators

hasPermissions necessaryPermissions =
List.all (\permission -> List.member permission permissions)
necessaryPermissions

claimOrAskForPin actionId photoUrl code time m =
if isPinConfirmed then
m
Expand All @@ -148,7 +160,8 @@ update isPinConfirmed shared selectedCommunity accName msg model =
(claimActionPort
msg
shared.contracts.community
{ actionId = actionId
{ communityId = selectedCommunity
, actionId = actionId
, maker = accName
, proofPhoto = photoUrl
, proofCode = code
Expand All @@ -168,12 +181,18 @@ update isPinConfirmed shared selectedCommunity accName msg model =
|> UR.init

( ActionClaimed action Nothing, _ ) ->
{ model
| status = ClaimInProgress action Nothing
, feedback = Nothing
, needsPinConfirmation = not isPinConfirmed
}
|> claimOrAskForPin action.id "" "" 0
if hasPermissions [ Permission.Claim ] then
{ model
| status = ClaimInProgress action Nothing
, feedback = Nothing
, needsPinConfirmation = not isPinConfirmed
}
|> claimOrAskForPin action.id "" "" 0

else
{ model | status = NotAsked }
|> UR.init
|> UR.addExt ShowInsufficientPermissions

( ActionClaimed action (Just proofRecord), _ ) ->
let
Expand All @@ -185,21 +204,27 @@ update isPinConfirmed shared selectedCommunity accName msg model =
Proof _ Nothing ->
( "", 0 )
in
case proofRecord.image of
Just image ->
{ model
| status = ClaimInProgress action (Just proofRecord)
, feedback = Nothing
, needsPinConfirmation = not isPinConfirmed
}
|> claimOrAskForPin action.id image proofCode time
if hasPermissions [ Permission.Claim ] then
case proofRecord.image of
Just image ->
{ model
| status = ClaimInProgress action (Just proofRecord)
, feedback = Nothing
, needsPinConfirmation = not isPinConfirmed
}
|> claimOrAskForPin action.id image proofCode time

Nothing ->
{ model
| feedback = Failure (t "community.actions.proof.no_upload_error") |> Just
, needsPinConfirmation = False
}
|> UR.init
Nothing ->
{ model
| feedback = Failure (t "community.actions.proof.no_upload_error") |> Just
, needsPinConfirmation = False
}
|> UR.init

else
{ model | status = NotAsked }
|> UR.init
|> UR.addExt ShowInsufficientPermissions

( AgreedToClaimWithProof action, _ ) ->
{ model
Expand Down Expand Up @@ -339,7 +364,7 @@ update isPinConfirmed shared selectedCommunity accName msg model =
}
)
GotFormMsg
UR.addExt
(SentFeedback >> UR.addExt)
model

( GotFormMsg subMsg, PhotoUploaderShowed action (Proof formModel proofCode) ) ->
Expand All @@ -349,7 +374,7 @@ update isPinConfirmed shared selectedCommunity accName msg model =
{ model | status = PhotoUploaderShowed action (Proof newForm proofCode) }
)
GotFormMsg
UR.addExt
(SentFeedback >> UR.addExt)
model

( Tick timer, PhotoUploaderShowed action (Proof photoStatus (Just proofCode)) ) ->
Expand Down Expand Up @@ -692,7 +717,8 @@ encode action =
{ symbol = action.objective.community.symbol, amount = amount }
in
Encode.object
[ ( "action_id", Encode.int action.id )
[ ( "community_id", Eos.encodeSymbol action.objective.community.symbol )
, ( "action_id", Encode.int action.id )
, ( "objective_id", Encode.int action.objective.id )
, ( "description", Markdown.encode action.description )
, ( "reward", Eos.encodeAsset (makeAsset action.reward) )
Expand Down Expand Up @@ -722,6 +748,7 @@ encode action =
, ( "has_proof_photo", Eos.encodeEosBool (Eos.boolToEosBool action.hasProofPhoto) )
, ( "has_proof_code", Eos.encodeEosBool (Eos.boolToEosBool action.hasProofCode) )
, ( "photo_proof_instructions", Markdown.encode (Maybe.withDefault Markdown.empty action.photoProofInstructions) )
, ( "image", Encode.string "" )
]


Expand All @@ -738,32 +765,26 @@ updateAction accountName shared action =


claimActionPort : msg -> String -> ClaimedAction -> Ports.JavascriptOutModel msg
claimActionPort msg contractsCommunity { actionId, maker, proofPhoto, proofCode, proofTime } =
claimActionPort msg contractsCommunity action =
{ responseAddress = msg
, responseData = Encode.null
, data =
Eos.encodeTransaction
[ { accountName = contractsCommunity
, name = "claimaction"
, authorization =
{ actor = maker
{ actor = action.maker
, permissionName = Eos.samplePermission
}
, data =
{ actionId = actionId
, maker = maker
, proofPhoto = proofPhoto
, proofCode = proofCode
, proofTime = proofTime
}
|> encodeClaimAction
, data = encodeClaimAction action
}
]
}


type alias ClaimedAction =
{ actionId : Int
{ communityId : Symbol
, actionId : Int
, maker : Eos.Name
, proofPhoto : String
, proofCode : String
Expand All @@ -774,7 +795,8 @@ type alias ClaimedAction =
encodeClaimAction : ClaimedAction -> Encode.Value
encodeClaimAction c =
Encode.object
[ ( "action_id", Encode.int c.actionId )
[ ( "community_id", Eos.encodeSymbol c.communityId )
, ( "action_id", Encode.int c.actionId )
, ( "maker", Eos.encodeName c.maker )
, ( "proof_photo", Encode.string c.proofPhoto )
, ( "proof_code", Encode.string c.proofCode )
Expand Down
7 changes: 4 additions & 3 deletions src/elm/Claim.elm
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ pendingValidators claim =
claim.action.validators


encodeVerification : ClaimId -> Eos.Name -> Bool -> Encode.Value
encodeVerification claimId validator vote =
encodeVerification : ClaimId -> Eos.Name -> Bool -> Eos.Symbol -> Encode.Value
encodeVerification claimId validator vote communityId =
let
encodedClaimId : Encode.Value
encodedClaimId =
Expand All @@ -163,7 +163,8 @@ encodeVerification claimId validator vote =
|> Eos.encodeEosBool
in
Encode.object
[ ( "claim_id", encodedClaimId )
[ ( "community_id", Eos.encodeSymbol communityId )
, ( "claim_id", encodedClaimId )
, ( "verifier", encodedVerifier )
, ( "vote", encodedVote )
]
Expand Down
13 changes: 8 additions & 5 deletions src/elm/Community.elm
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ objectiveSelectionSet =


type alias CreateObjectiveAction =
{ asset : Eos.Asset
{ communityId : Eos.Symbol
, description : Markdown
, creator : Eos.Name
}
Expand All @@ -470,14 +470,16 @@ type alias CreateObjectiveAction =
encodeCreateObjectiveAction : CreateObjectiveAction -> Value
encodeCreateObjectiveAction c =
Encode.object
[ ( "cmm_asset", Eos.encodeAsset c.asset )
[ ( "community_id", Eos.encodeSymbol c.communityId )
, ( "objective_id", Encode.int 0 )
, ( "description", Markdown.encode c.description )
, ( "creator", Eos.encodeName c.creator )
, ( "editor", Eos.encodeName c.creator )
]


type alias UpdateObjectiveAction =
{ objectiveId : Int
{ communityId : Eos.Symbol
, objectiveId : Int
, description : Markdown
, editor : Eos.Name
}
Expand All @@ -486,7 +488,8 @@ type alias UpdateObjectiveAction =
encodeUpdateObjectiveAction : UpdateObjectiveAction -> Value
encodeUpdateObjectiveAction c =
Encode.object
[ ( "objective_id", Encode.int c.objectiveId )
[ ( "community_id", Eos.encodeSymbol c.communityId )
, ( "objective_id", Encode.int c.objectiveId )
, ( "description", Markdown.encode c.description )
, ( "editor", Eos.encodeName c.editor )
]
Expand Down
2 changes: 2 additions & 0 deletions src/elm/Page/Community/ActionEditor.elm
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ update msg model ({ shared } as loggedIn) =
formOutput
)
|> LoggedIn.withPrivateKey loggedIn
[]
model
{ successMsg = msg, errorMsg = ClosedAuthModal }

Expand All @@ -300,6 +301,7 @@ update msg model ({ shared } as loggedIn) =
formOutput
)
|> LoggedIn.withPrivateKey loggedIn
[]
model
{ successMsg = msg, errorMsg = ClosedAuthModal }

Expand Down
1 change: 1 addition & 0 deletions src/elm/Page/Community/New.elm
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ update msg model loggedIn =
]
}
|> LoggedIn.withPrivateKey loggedIn
[]
model
{ successMsg = msg, errorMsg = ClosedAuthModal }
|> UR.addBreadcrumb
Expand Down
Loading

0 comments on commit 3d4b408

Please sign in to comment.