Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Do not consider deleted users in votingPower, `findDelegationsBySco…
Browse files Browse the repository at this point in the history
…pe`. Related: #830.
  • Loading branch information
fisx committed Jul 6, 2016
1 parent a6baa94 commit 98c6085
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
26 changes: 20 additions & 6 deletions src/Persistent/Pure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ import Control.Lens
import Control.Monad.Except (MonadError, ExceptT(ExceptT), runExceptT, throwError)
import Control.Monad.Reader (MonadReader, runReader, asks)
import Control.Monad.State (MonadState, gets, put)
import Control.Monad (foldM, unless, when, replicateM, forM)
import Control.Monad (foldM, unless, when, replicateM, forM, filterM)
import Data.Acid.Core
import Data.Acid.Memory.Pure (Event(UpdateEvent))
import Data.Acid (UpdateEvent, EventState, EventResult)
Expand Down Expand Up @@ -687,7 +687,7 @@ delegateesInScope delegate scope =
<$> views dbDelegations (Data.Delegation.delegateesInScope delegate scope)

votingPower :: AUID User -> DScope -> EQuery [User]
votingPower uid scope = do
votingPower uid scope = filter isActiveUser <$> do
ancestors <- scopeAncestors scope
catMaybes
<$> (mapM findUser
Expand All @@ -706,10 +706,24 @@ scopeAncestors = \case
IdeaLocationTopic _s t -> DScopeTopicId t)

findDelegationsByScope :: DScope -> Query (Map.Map (Delegate (AUID User)) [(DScope, Delegatee (AUID User))])
findDelegationsByScope scope =
Map.fromList
<$> ((\(d,s,ds) -> (d, (,) s <$> ds))
<$$> views dbDelegations (Data.Delegation.findDelegationsByScope scope))
findDelegationsByScope scope = do
delegs <- views dbDelegations (Data.Delegation.findDelegationsByScope scope)
delegs' <- sequence $ f <$> delegs
pure . Map.fromList . catMaybes $ delegs'
where
f (d, s, ds) = do
yes <- isActiveDelegate d
if yes
then do
ds' <- filterM isActiveDelegatee ds
pure $ Just (d, (s,) <$> ds')
else pure Nothing

isActiveDelegate :: Delegate (AUID User) -> Query Bool
isActiveDelegate (Delegate u) = maybe False isActiveUser <$> findUser u

isActiveDelegatee :: Delegatee (AUID User) -> Query Bool
isActiveDelegatee (Delegatee u) = maybe False isActiveUser <$> findUser u

findImplicitDelegationsByScope :: DScope -> EQuery (Map.Map (Delegate (AUID User)) [(DScope, Delegatee (AUID User))])
findImplicitDelegationsByScope scope = do
Expand Down
1 change: 0 additions & 1 deletion src/Types/Instances/JSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ instance Aeson.ToJSON DelegationNetwork where
, "links" Aeson..= array (renderLink <$> links)
]

-- FIXME: It shouldn't be rendered for deleted users.
renderNode (u, p) = Aeson.object
[ "name" Aeson..= (u ^. userLogin . unUserLogin)
, "avatar" Aeson..= (u ^. userAvatar avatarDefaultSize)
Expand Down

0 comments on commit 98c6085

Please sign in to comment.