Skip to content

Commit

Permalink
🌟 Feature/big companies (Back changes) (#91)
Browse files Browse the repository at this point in the history
Fixes #18 #95 #124 #107 #115 #19
Closes #59 #60

---

* Implement counters - Working on Big Companies (#59)

* Update counters if empty

* Paginate results in get members / guests / emails of workspace

* Update workspaces_users.js

Do not load group users in frontend

* 🛠 Fixes #18 #95 #124 #107 #115 and continue #60

* 🌟 Implement scoped search

* 🌟 Implement new scoped search in frontend
  • Loading branch information
RomaricMourgues authored Aug 17, 2020
1 parent c8b0ebe commit 2c598c4
Show file tree
Hide file tree
Showing 38 changed files with 507 additions and 501 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/saas-update-front.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ on:
jobs:
build-frontend:
runs-on: ubuntu-latest
env:
FRONTEND_ENV: ${{secrets.FRONTEND_ENV}}

strategy:
matrix:
Expand All @@ -31,10 +33,12 @@ jobs:
- run: npm install -g yarn
- run: cd twake/frontend/ && yarn install
- run: cd twake/frontend/ && cp src/app/environment/environment.ts.dist src/app/environment/environment.ts
- run: echo ${{ secrets.FRONTEND_ENV }} > twake/frontend/src/app/environment/environment.ts
- run: cp twake/frontend/src/app/environment/environment.ts.dist twake/frontend/src/app/environment/environment.ts
- if: ${{env.FRONTEND_ENV}}
run: echo ${{ secrets.FRONTEND_ENV }} > twake/frontend/src/app/environment/environment.ts
- run: cd twake/frontend/ && yarn build
- name: Upload frontend build artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v2
with:
name: frontend-build
path: twake/frontend/build/
Expand All @@ -51,7 +55,7 @@ jobs:
- uses: actions/checkout@v2

- name: Download frontend-build artifact
uses: actions/download-artifact@v1
uses: actions/download-artifact@v2
with:
name: frontend-build

Expand Down
6 changes: 4 additions & 2 deletions twake/backend/core/src/Twake/Core/Command/MappingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected function execute()
"_source" => Array(
"includes" => Array("id"),
"excludes" => Array(
"firstname", "lastname", "username", "language", "creation_date"
"firstname", "lastname", "username", "language", "creation_date", "groups_id", "workspaces_id"
)
),
"properties" => Array(
Expand All @@ -214,7 +214,9 @@ protected function execute()
"lastname" => Array("type" => "text"),
"username" => Array("type" => "text"),
"language" => Array("type" => "keyword"),
"creation_date" => Array("type" => "date")
"creation_date" => Array("type" => "date"),
"workspaces_id" => Array("type" => "keyword"),
"groups_id" => Array("type" => "keyword"),
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public function es_search($options = Array(), $index = null, $server = "twake")
$scroll_id = $res["_scroll_id"];
}


$result = [];
if (isset($res["hits"]) && isset($res["hits"]["hits"])) {
$res = $res["hits"]["hits"];

Expand All @@ -437,6 +437,7 @@ public function es_search($options = Array(), $index = null, $server = "twake")
}
}
$result = Array("repository" => $repository, "scroll_id" => $scroll_id, "result" => $result);

}
return $result;

Expand Down
32 changes: 0 additions & 32 deletions twake/backend/core/src/Twake/Users/Controller/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,6 @@ public function search(Request $request)

}

public function searchUsersByUsername(Request $request)
{

$data = Array(
"errors" => Array(),
"data" => Array()
);

if ($this->getUser()) {
$username = $request->request->get("username", "");
$restrictions = $request->request->get("restriction", "all");
$groupId = $request->request->get("groupId", "-1");
$workspaceId = $request->request->get("workspaceId", "-1");
$res = $this->get("app.users")->searchUsersByUsername($username, $restrictions, $groupId, $workspaceId);
if (!$res) {
$data["errors"][] = "error";
} else {
$array_user = [];
foreach ($res as $user) {
$array_user[] = $user->getAsArray();
}
$data["data"] = $array_user;
}

} else {
$data["errors"][] = "unknown";
}

return new JsonResponse($data);

}

public function getById(Request $request)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,11 @@ public function setIdentity(Request $request)

public function getUploader()
{
$aws = $this->getParameter('aws');
if (isset($aws["S3"]["use"]) && $aws["S3"]["use"]) {
$storage = $this->getParameter('storage');
if (isset($storage["S3"]["use"]) && $storage["S3"]["use"]) {
return $this->get("app.aws_uploader");
}
$openstack = $this->getParameter('openstack');
if (isset($openstack["use"]) && $openstack["use"]) {
if (isset($storage["use"]) && $storage["use"]) {
return $this->get("app.openstack_uploader");
}
return $this->get("app.uploader");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,20 @@ public function currentUser(Request $request)
$workspaces_obj = $this->get("app.workspace_members")->getWorkspaces($this->getUser()->getId() . "");

$workspaces = Array();
$workspaces_ids = Array();
$groups_ids = Array();
foreach ($workspaces_obj as $workspace_obj) {
$value = $workspace_obj["workspace"]->getAsArray();
$value["_user_last_access"] = $workspace_obj["last_access"]->getTimestamp();
$value["_user_hasnotifications"] = $workspace_obj["hasnotifications"];

$workspaces[] = $value;

$workspaces_ids[] = $value["id"];
$groups_ids[] = $value["group"]["id"];
}

$this->get("app.workspace_members")->updateUser($this->getUser(), $workspaces_ids, $groups_ids);

$mails = $this->get("app.user")->getSecondaryMails($this->getUser()->getId());

Expand Down
42 changes: 28 additions & 14 deletions twake/backend/core/src/Twake/Users/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
class User extends SearchableObject
{


protected $es_type = "users";

/**
Expand Down Expand Up @@ -60,10 +59,15 @@ class User extends SearchableObject
protected $thumbnail;

/**
* @ORM\OneToMany(targetEntity="Twake\Workspaces\Entity\WorkspaceUser", mappedBy="User")
* @ORM\Column(name="workspaces", type="twake_text")
*/
protected $workspaces;

/**
* @ORM\Column(name="groups", type="twake_text")
*/
protected $groups;

/**
* @var int
* @ORM\Column(name="connections", type="integer")
Expand Down Expand Up @@ -335,18 +339,6 @@ public function setThumbnail($thumbnail)
$this->thumbnail = $thumbnail;
}

public function getWorkspaces()
{

$workspaces = Array();

for ($i = 0; $i < count($this->workspaces); ++$i) {
$workspaces[] = $this->workspaces[$i]->getWorkspace();
}

return $workspaces;
}

public function isActive()
{
$this->lastactivity = date("U");
Expand Down Expand Up @@ -576,10 +568,32 @@ public function getIndexationArray()
"lastname" => $this->getLastName(),
"language" => $this->getLanguage(),
"creation_date" => ($this->getCreationDate() ? $this->getCreationDate()->format('Y-m-d') : null),
"groups_id" => [], //TODO
"workspaces_id" => [], //TODO
);
return $return;
}

public function setGroups($ids)
{
$this->groups = json_encode($ids);
}

public function setWorkspaces($ids)
{
$this->workspaces = json_encode($ids);
}

public function getGroups()
{
return json_decode($this->groups, 1);
}

public function getWorkspaces()
{
return json_decode($this->workspaces, 1);
}

/**
* @return mixed
*/
Expand Down
1 change: 0 additions & 1 deletion twake/backend/core/src/Twake/Users/Resources/Routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class Routing extends BaseRouting
// Get and search
"all/get" => ["handler" => "Users:getById", "methods" => ["POST"], "security" => ["user_connected_security"]],
"all/search" => ["handler" => "Users:search", "methods" => ["POST"], "security" => ["user_connected_security"]],
"all/search/username" => ["handler" => "Users:searchUsersByUsername", "methods" => ["POST"], "security" => ["user_connected_security"]],
// CAS
"cas/login" => ["handler" => "Adapters/CAS:login", "methods" => ["GET"]],
"cas/verify" => ["handler" => "Adapters/CAS:verify", "methods" => ["GET"]],
Expand Down
86 changes: 38 additions & 48 deletions twake/backend/core/src/Twake/Users/Services/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public function __construct(App $app)
public function search($options = Array())
{
$name = $options["name"];

$scope = $options["scope"] ?: "all";
$workspace_id = $options["workspace_id"];
$group_id = $options["group_id"];

$should = Array();

if (isset($name)) {
Expand Down Expand Up @@ -57,6 +62,29 @@ public function search($options = Array())
);
}

$match = null;

if($scope == "workspace"){
$match = Array(
"workspaces_id" => $workspace_id
);
}

if($scope == "group"){
$match = Array(
"groups_id" => $group_id
);
}

$search_bool = Array(
"should" => $should,
"minimum_should_match" => 1
);
if($match){
$search_bool["filter"] = [
"match" => $match
];
}

$options = Array(
"repository" => "Twake\Users:User",
Expand All @@ -65,10 +93,7 @@ public function search($options = Array())
"query" => Array(
"bool" => Array(
"must" => Array(
"bool" => Array(
"should" => $should,
"minimum_should_match" => 1
)
"bool" => $search_bool
)
)
),
Expand All @@ -87,17 +112,20 @@ public function search($options = Array())

$scroll_id = $result["scroll_id"];

$userRepository = $this->em->getRepository("Twake\Users:User");
$user = $userRepository->findOneBy(Array("usernamecanonical" => strtolower($name)));
if($scope === "all"){
$userRepository = $this->em->getRepository("Twake\Users:User");
$user = $userRepository->findOneBy(Array("usernamecanonical" => strtolower($name)));

if ($user) {
$this->list_users["users"][] = $user;
if ($user) {
$this->list_users["users"][] = Array($user->getAsArray(), 0);
}
}

//on traite les données recu d'Elasticsearch
foreach ($result["result"] as $user) {
//var_dump($file->getAsArray());
$this->list_users["users"][] = Array($user[0]->getAsArray(), $user[1][0]);;
if($user[0]){
$this->list_users["users"][] = Array($user[0]->getAsArray(), $user[1][0]);
}
}

$this->list_users["scroll_id"] = $scroll_id;
Expand All @@ -124,42 +152,4 @@ public function getByEmail($email, $entity = false)
}
return false;
}

public function searchUsersByUsername($username, $restrictions, $groupId, $workspaceId)
{
if ($username == "")
return "empty username";
$userRepository = $this->em->getRepository("TwakeUsersBundle:User");

$users = $userRepository->findByName($username);

if ($restrictions == "all") {
return $users;
}
$res = [];
if ($restrictions == "group") {
$groupUserRepository = $this->em->getRepository("TwakeWorkspacesBundle:GroupUser");

foreach ($users as $user) {
$groupuser = $groupUserRepository->findOneBy(Array("user" => $user->getId(), "group" => $groupId));
if ($groupuser) {
$res[] = $user;
}
}
}

if ($restrictions == "workspace") {
$workspaceUsers = $this->em->getRepository("TwakeWorkspacesBundle:WorkspaceUser");

foreach ($users as $user) {
$workspaceUser = $workspaceUsers->findOneBy(Array("workspace" => $workspaceId, "user" => $user));
if ($workspaceUser) {
$res[] = $user;
}
}
}

return $res;

}
}
Loading

0 comments on commit 2c598c4

Please sign in to comment.