core: accept updated conditions automatically 31 days after the notice (#8125)

* core: test the conditions deadline after a late notice

* core: accept updated conditions automatically 31 days after the notice

* core: fixes from review of the conditions deadline
This commit is contained in:
Evgeny @ SimpleX Chat authored and GitHub committed 2026-11-11 12:44:08 +00:00
1 parent 2205de390f
commit 65c2ff8a6a
3 files changed
+20 -13

No files matched your search

+5 -11
View File
@@ -62,7 +62,7 @@ import Simplex.Messaging.Util (atomicModifyIORef'_, safeDecodeUtf8)
-- Change the conditions only in a release whose What's new announces the change:
-- the apps show changed conditions as a link in What's new, also in a release without other news.
-- The notice is recorded when What's new is shown, and the conditions are accepted automatically
-- 31 days later, if the notice was shown within 14 days after the app added the conditions to the database.
-- 31 days later.
usageConditionsCommit :: Text
usageConditionsCommit = "5cb85b913989aa4dc618a0a47ffb9a758e44f375"
@@ -119,7 +119,7 @@ data ServerOperatorConditions = ServerOperatorConditions
deriving (Show)
usageConditionsAction :: [ServerOperator] -> UsageConditions -> UTCTime -> Maybe UsageConditionsAction
usageConditionsAction operators UsageConditions {createdAt, notifiedAt} now = do
usageConditionsAction operators UsageConditions {notifiedAt} now = do
let enabledOperators = filter (\ServerOperator {enabled} -> enabled) operators
if
| null enabledOperators -> Nothing
@@ -128,18 +128,12 @@ usageConditionsAction operators UsageConditions {createdAt, notifiedAt} now = do
in Just $ UCAAccepted acceptedForOperators
| otherwise ->
let acceptForOperators = filter (not . conditionsAccepted) enabledOperators
deadline = conditionsRequiredOrDeadline createdAt (fromMaybe now notifiedAt)
deadline = Just $ conditionsDeadline (fromMaybe now notifiedAt)
showNotice = isNothing notifiedAt
in Just $ UCAReview acceptForOperators deadline showNotice
conditionsRequiredOrDeadline :: UTCTime -> UTCTime -> Maybe UTCTime
conditionsRequiredOrDeadline createdAt notifiedAtOrNow =
if notifiedAtOrNow < addUTCTime (14 * nominalDay) createdAt
then Just $ conditionsDeadline notifiedAtOrNow
else Nothing -- required
where
conditionsDeadline :: UTCTime -> UTCTime
conditionsDeadline = addUTCTime (31 * nominalDay)
conditionsDeadline :: UTCTime -> UTCTime
conditionsDeadline = addUTCTime (31 * nominalDay)
data ConditionsAcceptance
= CAAccepted {acceptedAt :: Maybe UTCTime, autoAccepted :: Bool}
+2 -2
View File
@@ -899,7 +899,7 @@ toServerOperator ((operatorId, operatorTag, tradeName, legalName, domains, BI en
serverRolesXFTP (BI storage, BI proxy) = ServerRoles {storage, proxy, names = False}
getOperatorConditions_ :: DB.Connection -> ServerOperator -> UsageConditions -> Maybe UsageConditions -> UTCTime -> IO ConditionsAcceptance
getOperatorConditions_ db ServerOperator {operatorId} UsageConditions {conditionsCommit = currentCommit, createdAt, notifiedAt} latestAcceptedConds_ now = do
getOperatorConditions_ db ServerOperator {operatorId} UsageConditions {conditionsCommit = currentCommit, notifiedAt} latestAcceptedConds_ now = do
case latestAcceptedConds_ of
Nothing -> pure $ CARequired Nothing -- no conditions accepted by any operator
Just UsageConditions {conditionsCommit = latestAcceptedCommit} -> do
@@ -918,7 +918,7 @@ getOperatorConditions_ db ServerOperator {operatorId} UsageConditions {condition
pure $ case operatorAcceptedConds_ of
Just (operatorCommit, acceptedAt_, BI autoAccept)
| operatorCommit /= latestAcceptedCommit -> CARequired Nothing -- TODO should we consider this operator disabled?
| currentCommit /= latestAcceptedCommit -> CARequired $ conditionsRequiredOrDeadline createdAt (fromMaybe now notifiedAt)
| currentCommit /= latestAcceptedCommit -> CARequired $ Just $ conditionsDeadline (fromMaybe now notifiedAt)
| otherwise -> CAAccepted acceptedAt_ autoAccept
_ -> CARequired Nothing -- no conditions were accepted for this operator
+13
View File
@@ -16,6 +16,8 @@ module OperatorTests (operatorTests) where
import Data.Bifunctor (second)
import qualified Data.List.NonEmpty as L
import Data.Time.Calendar (fromGregorian)
import Data.Time.Clock (UTCTime (..), addUTCTime, nominalDay)
import Simplex.Chat
import Simplex.Chat.Controller (ChatConfig (..), PresetServers (..))
import Simplex.Chat.Operators
@@ -34,6 +36,17 @@ operatorTests = describe "managing server operators" $ do
validateServersTest
updatedServersTest
perServerRolesTest
conditionsDeadlineTest
conditionsDeadlineTest :: Spec
conditionsDeadlineTest = describe "usage conditions deadline" $
it "should set the deadline 31 days after the notice, also after a late notice" $ do
let created = UTCTime (fromGregorian 2026 11 1) 0
notified = addUTCTime (20 * nominalDay) created
conditions = UsageConditions {conditionsId = 2, conditionsCommit = usageConditionsCommit, notifiedAt = Just notified, createdAt = created}
case usageConditionsAction [operatorSimpleXChat {operatorId = DBEntityId 1}] conditions (addUTCTime nominalDay notified) of
Just UCAReview {deadline} -> deadline `shouldBe` Just (addUTCTime (31 * nominalDay) notified)
action -> expectationFailure $ show action
validateServersTest :: Spec
validateServersTest = describe "validate user servers" $ do