Commit 4c6051cc authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX MERGE] with dev and testing (social lists)

parents d3547991 20e86c92
...@@ -29,7 +29,6 @@ import Gargantext.API.Prelude (GargError) ...@@ -29,7 +29,6 @@ import Gargantext.API.Prelude (GargError)
import Gargantext.Core (Lang(..)) import Gargantext.Core (Lang(..))
import Gargantext.Core.Types.Individu (User(..)) import Gargantext.Core.Types.Individu (User(..))
import Gargantext.Database.Action.Flow (FlowCmdM, flowCorpusFile, flowAnnuaire, TermType(..)) import Gargantext.Database.Action.Flow (FlowCmdM, flowCorpusFile, flowAnnuaire, TermType(..))
import Gargantext.Database.Query.Table.User (insertUsersDemo)
import Gargantext.Database.Admin.Types.Hyperdata (toHyperdataDocument) import Gargantext.Database.Admin.Types.Hyperdata (toHyperdataDocument)
import Gargantext.Database.Admin.Types.Node (CorpusId) import Gargantext.Database.Admin.Types.Node (CorpusId)
import Gargantext.Database.Prelude (Cmd) import Gargantext.Database.Prelude (Cmd)
...@@ -42,9 +41,6 @@ main = do ...@@ -42,9 +41,6 @@ main = do
--{- --{-
let createUsers :: Cmd GargError Int64
createUsers = insertUsersDemo
let let
--tt = (Unsupervised EN 6 0 Nothing) --tt = (Unsupervised EN 6 0 Nothing)
tt = (Multi EN) tt = (Multi EN)
...@@ -70,10 +66,6 @@ main = do ...@@ -70,10 +66,6 @@ main = do
--} --}
withDevEnv iniPath $ \env -> do withDevEnv iniPath $ \env -> do
_ <- if fun == "users"
then runCmdDev env createUsers
else pure 0 --(cs "false")
_ <- if fun == "corpus" _ <- if fun == "corpus"
then runCmdDev env corpus then runCmdDev env corpus
else pure 0 --(cs "false") else pure 0 --(cs "false")
......
...@@ -20,10 +20,10 @@ import Data.Either (Either(..)) ...@@ -20,10 +20,10 @@ import Data.Either (Either(..))
import Gargantext.API.Dev (withDevEnv, runCmdDev) import Gargantext.API.Dev (withDevEnv, runCmdDev)
import Gargantext.API.Prelude (GargError) import Gargantext.API.Prelude (GargError)
import Gargantext.API.Node () -- instances only import Gargantext.API.Node () -- instances only
import Gargantext.Core.Types.Individu (User(..)) import Gargantext.Core.Types.Individu (User(..), arbitraryNewUsers, NewUser(..), arbitraryUsername, GargPassword(..))
import Gargantext.Database.Action.Flow (getOrMkRoot, getOrMk_RootWithCorpus) import Gargantext.Database.Action.Flow (getOrMkRoot, getOrMk_RootWithCorpus)
import Gargantext.Database.Query.Table.Node (getOrMkList) import Gargantext.Database.Query.Table.Node (getOrMkList)
import Gargantext.Database.Query.Table.User (insertUsersDemo) import Gargantext.Database.Query.Table.User (insertNewUsers, )
import Gargantext.Database.Admin.Config (userMaster, corpusMasterName) import Gargantext.Database.Admin.Config (userMaster, corpusMasterName)
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Admin.Trigger.Init (initFirstTriggers, initLastTriggers) import Gargantext.Database.Admin.Trigger.Init (initFirstTriggers, initLastTriggers)
...@@ -31,6 +31,7 @@ import Gargantext.Database.Admin.Types.Hyperdata (HyperdataCorpus) ...@@ -31,6 +31,7 @@ import Gargantext.Database.Admin.Types.Hyperdata (HyperdataCorpus)
import Gargantext.Database.Prelude (Cmd, ) import Gargantext.Database.Prelude (Cmd, )
import Gargantext.Prelude import Gargantext.Prelude
import System.Environment (getArgs) import System.Environment (getArgs)
import Prelude (getLine)
-- TODO put this in gargantext.ini -- TODO put this in gargantext.ini
secret :: Text secret :: Text
...@@ -40,12 +41,21 @@ main :: IO () ...@@ -40,12 +41,21 @@ main :: IO ()
main = do main = do
[iniPath] <- getArgs [iniPath] <- getArgs
putStrLn "Enter master user (gargantua) _password_ :"
password <- getLine
putStrLn "Enter master user (gargantua) _email_ :"
email <- getLine
let createUsers :: Cmd GargError Int64 let createUsers :: Cmd GargError Int64
createUsers = insertUsersDemo createUsers = insertNewUsers (NewUser "gargantua" (cs email) (GargPassword $ cs password)
: arbitraryNewUsers
)
let let
mkRoots :: Cmd GargError [(UserId, RootId)] mkRoots :: Cmd GargError [(UserId, RootId)]
mkRoots = mapM getOrMkRoot $ map UserName ["gargantua", "user1", "user2", "user3"] mkRoots = mapM getOrMkRoot $ map UserName ("gargantua" : arbitraryUsername)
-- TODO create all users roots -- TODO create all users roots
let let
......
{ ghc { ghc
, pkgs ? import ./pinned.nix {} , pkgs ? import ./pinned-20.09.nix {}
}: }:
let let
buildInputs = with pkgs; [ buildInputs = with pkgs; [
......
# this version of nixpkgs contains liblapack at ?
# this version of nixpkgs contains gsl at ?
import (builtins.fetchGit {
# Descriptive name to make the store path easier to identify
name = "nixos-20.09";
url = "https://github.com/nixos/nixpkgs/";
# Last commit hash for nixos-unstable
# `git ls-remote https://github.com/nixos/nixpkgs-channels nixos-20.09`
ref = "refs/heads/nixos-20.09";
rev = "19db3e5ea2777daa874563b5986288151f502e27";
})
...@@ -419,6 +419,7 @@ tableNgramsPostChartsAsync utn logStatus = do ...@@ -419,6 +419,7 @@ tableNgramsPostChartsAsync utn logStatus = do
-- printDebug "[tableNgramsPut] Terms, updating Metrics (Histo), cId" cId -- printDebug "[tableNgramsPut] Terms, updating Metrics (Histo), cId" cId
(logRef, logRefSuccess, getRef) <- runJobLog 6 logStatus (logRef, logRefSuccess, getRef) <- runJobLog 6 logStatus
logRef logRef
{-
_ <- Metrics.updateChart cId (Just listId) tabType Nothing _ <- Metrics.updateChart cId (Just listId) tabType Nothing
logRefSuccess logRefSuccess
_ <- Metrics.updatePie cId (Just listId) tabType Nothing _ <- Metrics.updatePie cId (Just listId) tabType Nothing
...@@ -430,6 +431,7 @@ tableNgramsPostChartsAsync utn logStatus = do ...@@ -430,6 +431,7 @@ tableNgramsPostChartsAsync utn logStatus = do
_ <- Metrics.updateTree cId (Just listId) tabType CandidateTerm _ <- Metrics.updateTree cId (Just listId) tabType CandidateTerm
logRefSuccess logRefSuccess
_ <- Metrics.updateTree cId (Just listId) tabType MapTerm _ <- Metrics.updateTree cId (Just listId) tabType MapTerm
-}
logRefSuccess logRefSuccess
getRef getRef
......
...@@ -210,10 +210,10 @@ nodeAPI p uId id' = withAccess (Proxy :: Proxy (NodeAPI a)) Proxy uId (PathNode ...@@ -210,10 +210,10 @@ nodeAPI p uId id' = withAccess (Proxy :: Proxy (NodeAPI a)) Proxy uId (PathNode
-- TODO gather it -- TODO gather it
:<|> tableApi id' :<|> tableApi id'
:<|> apiNgramsTableCorpus id' :<|> apiNgramsTableCorpus id'
:<|> catApi id' :<|> catApi id'
:<|> Search.api id' :<|> Search.api id'
:<|> Share.api id' :<|> Share.api (RootId $ NodeId uId) id'
-- Pairing Tools -- Pairing Tools
:<|> pairWith id' :<|> pairWith id'
:<|> pairs id' :<|> pairs id'
......
...@@ -19,20 +19,21 @@ import Data.Aeson ...@@ -19,20 +19,21 @@ import Data.Aeson
import Data.Swagger import Data.Swagger
import Data.Text (Text) import Data.Text (Text)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Servant
import Test.QuickCheck (elements)
import Test.QuickCheck.Arbitrary
import Gargantext.API.Prelude import Gargantext.API.Prelude
import Gargantext.Core.Types.Individu (User(..)) import Gargantext.Core.Types.Individu (User(..), arbitraryUsername)
import Gargantext.Database.Action.User
import Gargantext.Database.Action.User.New
import Gargantext.Database.Action.Share (ShareNodeWith(..)) import Gargantext.Database.Action.Share (ShareNodeWith(..))
import Gargantext.Database.Action.Share as DB (shareNodeWith, unPublish) import Gargantext.Database.Action.Share as DB (shareNodeWith, unPublish)
import Gargantext.Database.Action.User
import Gargantext.Database.Action.User.New
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Prelude import Gargantext.Database.Prelude
import Gargantext.Database.Query.Tree (findNodesId)
import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..)) import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..))
import Gargantext.Prelude import Gargantext.Prelude
import Servant
import Test.QuickCheck (elements)
import Test.QuickCheck.Arbitrary
import qualified Data.List as List
------------------------------------------------------------------------ ------------------------------------------------------------------------
data ShareNodeParams = ShareTeamParams { username :: Text } data ShareNodeParams = ShareTeamParams { username :: Text }
...@@ -51,23 +52,42 @@ instance Arbitrary ShareNodeParams where ...@@ -51,23 +52,42 @@ instance Arbitrary ShareNodeParams where
] ]
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- TODO permission -- TODO permission
-- TODO refactor userId which is used twice
-- TODO change return type for better warning/info/success/error handling on the front
api :: HasNodeError err api :: HasNodeError err
=> NodeId => User
-> NodeId
-> ShareNodeParams -> ShareNodeParams
-> CmdR err Int -> CmdR err Int
api nId (ShareTeamParams user') = do api userInviting nId (ShareTeamParams user') = do
user <- case guessUserName user' of user <- case guessUserName user' of
Nothing -> pure user' Nothing -> pure user'
Just (u,_) -> do Just (u,_) -> do
isRegistered <- getUserId' (UserName u) isRegistered <- getUserId' (UserName u)
case isRegistered of case isRegistered of
Just _ -> pure u Just _ -> do
printDebug "[G.A.N.Share.api]" ("Team shared with " <> u)
pure u
Nothing -> do Nothing -> do
_ <- newUsers [u] username' <- getUsername userInviting
_ <- case List.elem username' arbitraryUsername of
True -> do
printDebug "[G.A.N.Share.api]" ("demo users are not allowed to invite" :: Text)
pure ()
False -> do
children <- findNodesId nId [NodeCorpus]
_ <- case List.null children of
True -> do
printDebug "[G.A.N.Share.api]" ("Invitation is enabled if you share a corpus at least" :: Text)
pure 0
False -> do
printDebug "[G.A.N.Share.api]" ("Your invitation is sent to: " <> user')
newUsers [user']
pure ()
pure u pure u
fromIntegral <$> DB.shareNodeWith (ShareNodeWith_User NodeFolderShared (UserName user)) nId fromIntegral <$> DB.shareNodeWith (ShareNodeWith_User NodeFolderShared (UserName user)) nId
api nId2 (SharePublicParams nId1) = api _uId nId2 (SharePublicParams nId1) =
fromIntegral <$> DB.shareNodeWith (ShareNodeWith_Node NodeFolderPublic nId1) nId2 fromIntegral <$> DB.shareNodeWith (ShareNodeWith_Node NodeFolderPublic nId1) nId2
......
...@@ -98,7 +98,7 @@ buildNgramsOthersList user uCid groupParams (nt, MapListSize mapListSize) = do ...@@ -98,7 +98,7 @@ buildNgramsOthersList user uCid groupParams (nt, MapListSize mapListSize) = do
socialLists' :: FlowCont Text FlowListScores socialLists' :: FlowCont Text FlowListScores
<- flowSocialList' MySelfFirst user nt ( FlowCont Map.empty <- flowSocialList' MySelfFirst user nt ( FlowCont Map.empty
$ Map.fromList $ Map.fromList
$ List.zip (Map.keys allTerms) $ List.zip (Map.keys allTerms)
(List.cycle [mempty]) (List.cycle [mempty])
) )
let let
...@@ -136,7 +136,6 @@ buildNgramsTermsList :: ( HasNodeError err ...@@ -136,7 +136,6 @@ buildNgramsTermsList :: ( HasNodeError err
buildNgramsTermsList user uCid mCid groupParams (nt, _mapListSize)= do buildNgramsTermsList user uCid mCid groupParams (nt, _mapListSize)= do
-- | Filter 0 With Double -- | Filter 0 With Double
-- Computing global speGen score -- Computing global speGen score
allTerms :: Map Text Double <- getTficf uCid mCid nt allTerms :: Map Text Double <- getTficf uCid mCid nt
...@@ -171,6 +170,7 @@ buildNgramsTermsList user uCid mCid groupParams (nt, _mapListSize)= do ...@@ -171,6 +170,7 @@ buildNgramsTermsList user uCid mCid groupParams (nt, _mapListSize)= do
-- Filter 1 With Set NodeId and SpeGen -- Filter 1 With Set NodeId and SpeGen
selectedTerms = Set.toList $ hasTerms (groupedMonoHead <> groupedMultHead) selectedTerms = Set.toList $ hasTerms (groupedMonoHead <> groupedMultHead)
-- TO remove (and remove HasNodeError instance) -- TO remove (and remove HasNodeError instance)
userListId <- defaultList uCid userListId <- defaultList uCid
masterListId <- defaultList mCid masterListId <- defaultList mCid
...@@ -214,7 +214,7 @@ buildNgramsTermsList user uCid mCid groupParams (nt, _mapListSize)= do ...@@ -214,7 +214,7 @@ buildNgramsTermsList user uCid mCid groupParams (nt, _mapListSize)= do
(monoScored, multScored) = Map.partitionWithKey (\t _v -> size t < 2) groupedTreeScores_SpeGen (monoScored, multScored) = Map.partitionWithKey (\t _v -> size t < 2) groupedTreeScores_SpeGen
-- filter with max score -- filter with max score
partitionWithMaxScore = Map.partition (\g -> (view scored_genInc $ view gts'_score g) partitionWithMaxScore = Map.partition (\g -> (view scored_genInc $ view gts'_score g)
> (view scored_speExc $ view gts'_score g) > (view scored_speExc $ view gts'_score g)
) )
...@@ -228,8 +228,8 @@ buildNgramsTermsList user uCid mCid groupParams (nt, _mapListSize)= do ...@@ -228,8 +228,8 @@ buildNgramsTermsList user uCid mCid groupParams (nt, _mapListSize)= do
inclSize = 0.4 :: Double inclSize = 0.4 :: Double
exclSize = 1 - inclSize exclSize = 1 - inclSize
splitAt' n' = (both (Map.fromList)) . (List.splitAt (round $ n' * listSizeLocal)) splitAt' n' = (both (Map.fromList)) . (List.splitAt (round $ n' * listSizeLocal))
sortOn f = (List.sortOn (Down . (view (gts'_score . f)) . snd)) . Map.toList sortOn f = (List.sortOn (Down . (view (gts'_score . f)) . snd)) . Map.toList
monoInc_size = splitAt' $ monoSize * inclSize / 2 monoInc_size = splitAt' $ monoSize * inclSize / 2
......
...@@ -67,7 +67,7 @@ groupWith :: GroupParams ...@@ -67,7 +67,7 @@ groupWith :: GroupParams
-> Text -> Text
-> Text -> Text
groupWith GroupIdentity = identity groupWith GroupIdentity = identity
groupWith (GroupParams l _m _n _) = groupWith (GroupParams l _m _n _) =
Text.intercalate " " Text.intercalate " "
. map (stem l) . map (stem l)
-- . take n -- . take n
...@@ -81,7 +81,7 @@ groupWithStem_SetNodeId :: GroupParams ...@@ -81,7 +81,7 @@ groupWithStem_SetNodeId :: GroupParams
-> FlowCont Text (GroupedTreeScores (Set NodeId)) -> FlowCont Text (GroupedTreeScores (Set NodeId))
-> FlowCont Text (GroupedTreeScores (Set NodeId)) -> FlowCont Text (GroupedTreeScores (Set NodeId))
groupWithStem_SetNodeId g flc groupWithStem_SetNodeId g flc
| g == GroupIdentity = FlowCont ( (<>) | g == GroupIdentity = FlowCont ( (<>)
(view flc_scores flc) (view flc_scores flc)
(view flc_cont flc) (view flc_cont flc)
) mempty ) mempty
...@@ -91,7 +91,7 @@ groupWithStem_Double :: GroupParams ...@@ -91,7 +91,7 @@ groupWithStem_Double :: GroupParams
-> FlowCont Text (GroupedTreeScores Double) -> FlowCont Text (GroupedTreeScores Double)
-> FlowCont Text (GroupedTreeScores Double) -> FlowCont Text (GroupedTreeScores Double)
groupWithStem_Double g flc groupWithStem_Double g flc
| g == GroupIdentity = FlowCont ( (<>) | g == GroupIdentity = FlowCont ( (<>)
(view flc_scores flc) (view flc_scores flc)
(view flc_cont flc) (view flc_cont flc)
) mempty ) mempty
......
...@@ -52,7 +52,7 @@ data NewUser a = NewUser { _nu_username :: Username ...@@ -52,7 +52,7 @@ data NewUser a = NewUser { _nu_username :: Username
deriving (Show) deriving (Show)
arbitraryUsername :: [Username] arbitraryUsername :: [Username]
arbitraryUsername = ["gargantua"] <> users arbitraryUsername = {- ["gargantua"] <> -} users
where where
users = zipWith (\a b -> a <> (pack . show) b) users = zipWith (\a b -> a <> (pack . show) b)
(repeat "user") ([1..20]::[Int]) (repeat "user") ([1..20]::[Int])
...@@ -68,12 +68,13 @@ toUserHash (NewUser u m (GargPassword p)) = do ...@@ -68,12 +68,13 @@ toUserHash (NewUser u m (GargPassword p)) = do
h <- Auth.createPasswordHash p h <- Auth.createPasswordHash p
pure $ NewUser u m h pure $ NewUser u m h
-- TODO remove
arbitraryUsersHash :: MonadIO m arbitraryUsersHash :: MonadIO m
=> m [NewUser HashPassword] => m [NewUser HashPassword]
arbitraryUsersHash = mapM toUserHash arbitraryUsers arbitraryUsersHash = mapM toUserHash arbitraryNewUsers
arbitraryUsers :: [NewUser GargPassword] arbitraryNewUsers :: [NewUser GargPassword]
arbitraryUsers = map (\u -> NewUser u (u <> "@gargantext.org") (GargPassword $ reverse u)) arbitraryNewUsers = map (\u -> NewUser u (u <> "@gargantext.org") (GargPassword $ reverse u))
arbitraryUsername arbitraryUsername
...@@ -31,7 +31,7 @@ getUserId u = do ...@@ -31,7 +31,7 @@ getUserId u = do
maybeUser <- getUserId' u maybeUser <- getUserId' u
case maybeUser of case maybeUser of
Nothing -> nodeError NoUserFound Nothing -> nodeError NoUserFound
Just u -> pure u Just u' -> pure u'
getUserId' :: HasNodeError err getUserId' :: HasNodeError err
=> User => User
......
...@@ -44,9 +44,10 @@ newUserQuick n = do ...@@ -44,9 +44,10 @@ newUserQuick n = do
pass <- gargPass pass <- gargPass
let u = case guessUserName n of let u = case guessUserName n of
Just (u', _m) -> u' Just (u', _m) -> u'
Nothing -> panic "Email invalid" Nothing -> panic "[G.D.A.U.N.newUserQuick]: Email invalid"
pure (NewUser u n (GargPassword pass)) pure (NewUser u n (GargPassword pass))
------------------------------------------------------------------------
isEmail :: Text -> Bool isEmail :: Text -> Bool
isEmail = ((==) 2) . List.length . (splitOn "@") isEmail = ((==) 2) . List.length . (splitOn "@")
...@@ -69,12 +70,17 @@ newUsers' address us = do ...@@ -69,12 +70,17 @@ newUsers' address us = do
_ <- liftBase $ mapM (mail Invitation address) us _ <- liftBase $ mapM (mail Invitation address) us
pure r pure r
------------------------------------------------------------------------ ------------------------------------------------------------------------
data SendEmail = SendEmail Bool
updateUser :: HasNodeError err updateUser :: HasNodeError err
=> Text -> NewUser GargPassword -> Cmd err Int64 => SendEmail -> Text -> NewUser GargPassword -> Cmd err Int64
updateUser address u = do updateUser (SendEmail send) address u = do
u' <- liftBase $ toUserHash u u' <- liftBase $ toUserHash u
n <- updateUserDB $ toUserWrite u' n <- updateUserDB $ toUserWrite u'
_ <- liftBase $ mail Update address u _ <- case send of
True -> liftBase $ mail Update address u
False -> pure ()
pure n pure n
------------------------------------------------------------------------ ------------------------------------------------------------------------
......
...@@ -24,7 +24,7 @@ module Gargantext.Database.Query.Table.User ...@@ -24,7 +24,7 @@ module Gargantext.Database.Query.Table.User
, updateUserDB , updateUserDB
, queryUserTable , queryUserTable
, getUser , getUser
, insertUsersDemo , insertNewUsers
, selectUsersLightWith , selectUsersLightWith
, userWithUsername , userWithUsername
, userWithId , userWithId
...@@ -81,7 +81,7 @@ toUserWrite (NewUser u m (Auth.PasswordHash p)) = ...@@ -81,7 +81,7 @@ toUserWrite (NewUser u m (Auth.PasswordHash p)) =
(pgStrictText "first_name") (pgStrictText "first_name")
(pgStrictText "last_name") (pgStrictText "last_name")
(pgStrictText m) (pgStrictText m)
(pgBool True) (pgBool True)
(pgBool True) Nothing (pgBool True) Nothing
------------------------------------------------------------------ ------------------------------------------------------------------
...@@ -141,9 +141,9 @@ getUser u = userLightWithUsername u <$> usersLight ...@@ -141,9 +141,9 @@ getUser u = userLightWithUsername u <$> usersLight
---------------------------------------------------------------------- ----------------------------------------------------------------------
insertUsersDemo :: Cmd err Int64 insertNewUsers :: [NewUser GargPassword] -> Cmd err Int64
insertUsersDemo = do insertNewUsers newUsers = do
users <- liftBase arbitraryUsersHash users <- liftBase $ mapM toUserHash newUsers
insertUsers $ map toUserWrite users insertUsers $ map toUserWrite users
---------------------------------------------------------------------- ----------------------------------------------------------------------
......
...@@ -48,6 +48,8 @@ runJobLog num logStatus = do ...@@ -48,6 +48,8 @@ runJobLog num logStatus = do
logStatus jl logStatus jl
logRefSuccessF ref = do logRefSuccessF ref = do
jl <- liftBase $ readIORef ref jl <- liftBase $ readIORef ref
liftBase $ writeIORef ref $ jobLogSuccess jl let jl' = jobLogSuccess jl
liftBase $ writeIORef ref jl'
logStatus jl'
getRefF ref = do getRefF ref = do
liftBase $ readIORef ref liftBase $ readIORef ref
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment