_binary From 972059109aedc3d1692b83a584ca91e0952c363d Mon Sep 17 00:00:00 2001
From: Prajna Puranik <prajnagp@gmail.com>
Date: Mon, 14 Nov 2022 22:59:05 -0800
Subject: [PATCH] Add differential privacy to mask number of users

---
 .../components/SocialComponent.php            | 25 ++++++++++++++++---
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/controllers/components/SocialComponent.php b/src/controllers/components/SocialComponent.php
index 04aabeae9..662b187cd 100644
--- a/src/controllers/components/SocialComponent.php
+++ b/src/controllers/components/SocialComponent.php
@@ -1179,12 +1179,15 @@ class SocialComponent extends Component implements CrawlConstants
             $user_filter = "";
         }
         $data['USER_FILTER'] = $user_filter;
-        $data['NUM_USERS_GROUP'] =
-            $group_model->countGroupUsers($group_id, $user_filter);
+        $num_users =  $group_model->countGroupUsers($group_id, $user_filter);
+        if (C\DIFFERENTIAL_PRIVACY) {
+            $data['NUM_USERS_GROUP'] = $this -> groupUserPrivacy($num_users);
+        }else{
+            $data['NUM_USERS_GROUP'] = $num_users;
+        }
         if (isset($_REQUEST['group_limit'])) {
             $group_limit = min($parent->clean(
-                $_REQUEST['group_limit'], 'int'),
-                $data['NUM_USERS_GROUP']);
+                $_REQUEST['group_limit'], 'int'), $num_users);
             $group_limit = max($group_limit, 0);
         } else {
             $group_limit = 0;
@@ -1194,6 +1197,20 @@ class SocialComponent extends Component implements CrawlConstants
             $group_model->getGroupUsers($group_id, $user_filter,
             $data['USER_SORTS'], $group_limit);
     }
+
+    /**
+     * Used to add Differential Privacy to fuzzify number of users in each group
+     *
+     * @param object $num_users contains number of users per group,
+     *        returned from the database
+     * @return object $fuzzy_users returns number of users per group, now masked
+     */
+    public function groupUserPrivacy($num_users)
+    {
+        $parent = $this->parent;
+        $fuzzy_users = $parent->addDifferentialPrivacy($num_users);
+        return $fuzzy_users;
+    }
     /**
      * Used by $this->manageGroups to check and clean $_REQUEST variables
      * related to groups, to check that a user has the correct permissions
-- 
2.37.0 (Apple Git-136)

