Skip to content

Commit

Permalink
⬆️ Twake 2021.Q3.700
Browse files Browse the repository at this point in the history
⬆️ Twake 2021.Q3.700
  • Loading branch information
RomaricMourgues authored Sep 13, 2021
2 parents eba9430 + 554fa39 commit 7a1554b
Show file tree
Hide file tree
Showing 358 changed files with 28,997 additions and 7,385 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: unit-test
run: cd twake && docker-compose -f docker-compose.yml.dist.tests run node npm run test:unit
run: cd twake && docker-compose -f docker-compose.yml.dist.tests run -e NODE_OPTIONS=--unhandled-rejections=warn node npm run test:unit
- name: e2e-mongo-test
run: cd twake && docker-compose -f docker-compose.yml.dist.tests run -e SEARCH_DRIVER=mongodb -e DB_DRIVER=mongodb -e PUBSUB_TYPE=local node npm run test:e2e
run: cd twake && docker-compose -f docker-compose.yml.dist.tests run -e NODE_OPTIONS=--unhandled-rejections=warn -e SEARCH_DRIVER=mongodb -e DB_DRIVER=mongodb -e PUBSUB_TYPE=local node npm run test:e2e
- name: e2e-cassandra-test
run: cd twake && docker-compose -f docker-compose.yml.dist.tests up -d scylladb elasticsearch rabbitmq && sleep 60 && docker-compose -f docker-compose.yml.dist.tests run -e SEARCH_DRIVER=elasticsearch -e DB_DRIVER=cassandra node npm run test:e2e
run: cd twake && docker-compose -f docker-compose.yml.dist.tests up -d scylladb elasticsearch rabbitmq && sleep 60 && docker-compose -f docker-compose.yml.dist.tests run -e NODE_OPTIONS=--unhandled-rejections=warn -e SEARCH_DRIVER=elasticsearch -e DB_DRIVER=cassandra node npm run test:e2e
build:
runs-on: ubuntu-20.04
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/saas-update-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
deploy-php:
runs-on: ubuntu-20.04
steps:
- run: 'echo "DOCKERTAGVERSION=2021.Q3.640" >> $GITHUB_ENV'
- run: 'echo "DOCKERTAGVERSION=2021.Q3.735" >> $GITHUB_ENV'
- name: Set env to develop
if: endsWith(github.ref, '/develop')
run: 'echo "DOCKERTAG=develop" >> $GITHUB_ENV; echo "DOCKERTAGVERSION=${{ env.DOCKERTAGVERSION }}-develop" >> $GITHUB_ENV'
Expand All @@ -34,7 +34,7 @@ jobs:
deploy-node:
runs-on: ubuntu-20.04
steps:
- run: 'echo "DOCKERTAGVERSION=2021.Q3.640" >> $GITHUB_ENV'
- run: 'echo "DOCKERTAGVERSION=2021.Q3.735" >> $GITHUB_ENV'
- name: Set env to develop
if: endsWith(github.ref, '/develop')
run: 'echo "DOCKERTAG=develop" >> $GITHUB_ENV; echo "DOCKERTAGVERSION=${{ env.DOCKERTAGVERSION }}-develop" >> $GITHUB_ENV'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/saas-update-front.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
steps:
- run: 'echo "DOCKERTAGVERSION=2021.Q3.640" >> $GITHUB_ENV'
- run: 'echo "DOCKERTAGVERSION=2021.Q3.735" >> $GITHUB_ENV'
- name: Set env to develop
if: endsWith(github.ref, '/develop')
run: 'echo "DOCKERTAG=develop" >> $GITHUB_ENV; echo "DOCKERTAGVERSION=${{ env.DOCKERTAGVERSION }}-develop" >> $GITHUB_ENV'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public function getUserWorkspaces($user)
$workspaces = array();

foreach ($workspaces_tab as $workspace) {
$ws = $workspacesRepository->find($workspace->getWorkspaceId());
$ws = $workspacesRepository->findOneBy(["id"=>$workspace->getWorkspaceId()]);
if($ws){
$workspaces[] = $ws->getAsArray();
$workspaces[] = $ws->getAsArray($this->em);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function findGroups(Request $request)
$workspace = $workspace_service->getOneWorkspace($search_string);

if ($workspace) {
$data['data']['workspaces'][] = $workspace->getAsArray();
$data['data']['workspaces'][] = $workspace->getAsArray($this->get("app.twake_doctrine"));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getOneWorkspace(Request $request)
$apps = $workspace_service->getWorkspaceApps($workspace);
$invited_mails = $workspace_service->getInvitedUsers($workspace);

$data["data"]["workspace"] = $workspace->getAsArray();
$data["data"]["workspace"] = $workspace->getAsArray($this->get("app.twake_doctrine"));
$data["data"]["members"] = $members;
$data["data"]["apps"] = $apps;
$data["data"]["invited"] = $invited_mails;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function getGroupWorkspaces($group_id)
$workspaces_tab = $group->getWorkspaces();

foreach ($workspaces_tab as $workspace) {
$rep[] = $workspace->getAsArray();
$rep[] = $workspace->getAsArray($this->em);
}
}
return $rep;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getOneWorkspace($workspace_id)
{
$workspacesRepository = $this->em->getRepository("Twake\Workspaces:Workspace");

$workspace = $workspacesRepository->find($workspace_id);
$workspace = $workspacesRepository->findOneBy(["id"=>$workspace_id]);

return $workspace;
}
Expand All @@ -44,7 +44,7 @@ public function getWorkspaceApps($workspace)
{
$workspaceAppsRepository = $this->em->getrepository("Twake\Workspaces:WorkspaceApp");

$apps_tab = $workspaceAppsRepository->findBy(array("workspace" => $workspace));
$apps_tab = $workspaceAppsRepository->findBy(array("workspace_id" => $workspace));

$apps = array();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function isAllowedTo($application, $action, $workspaceId)
public function containsApp($workspaceId, $application)
{
$workspaceRepository = $this->doctrine->getRepository("Twake\Workspaces:Workspace");
$workspace = $workspaceRepository->find($workspaceId);
$workspace = $workspaceRepository->findOneBy(["id"=>$workspaceId]);

if ($workspace == null) {
return false;
Expand All @@ -93,7 +93,7 @@ public function containsApp($workspaceId, $application)
if ($groupApp) {
//Group apps
$workspaceappsRepository = $this->doctrine->getRepository("Twake\Workspaces:WorkspaceApp");
$workspaceapp = $workspaceappsRepository->findOneBy(Array("workspace" => $workspace, "groupapp" => $groupApp));
$workspaceapp = $workspaceappsRepository->findOneBy(Array("workspace_id" => $workspace, "groupapp" => $groupApp));
}

return $workspaceapp != null;
Expand Down
36 changes: 34 additions & 2 deletions twake/backend/core/src/Twake/Channels/Controller/Channels.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,40 @@ class Channels extends BaseController
{
public function getAction(Request $request)
{
$options = $request->request->get("options");
$objects = $this->get("app.channels.channels_system")->get($options, $this->getUser());
$options = $request->request->get("options");

//This is only used now to get old "applications as channels" feature
//$objects = $this->get("app.channels.channels_system")->get($options, $this->getUser());
$workspace = $this->get("app.workspaces")->get($options["workspace_id"]);
$apps = $this->get("app.group_apps")->getApps($workspace->getGroup());

$objects = [];
foreach($apps as $app){
$objects[] = [
"app_bot_identifier" =>"",
"app_group_id" =>"",
"app_id" => $app["app_id"],
"application" =>true,
"channel_group_name" =>"",
"connectors" =>[],
"description" =>"",
"direct" =>false,
"ext_members" =>[],
"front_id" => $app["app_id"],
"icon" =>"",
"id" => $app["app_id"],
"last_activity" =>1626706970,
"members" =>[$this->getUser()->getId()],
"members_count" => null,
"messages_increment" =>0,
"name" =>"",
"original_group" => $workspace->getGroup(),
"original_workspace" => $options["workspace_id"],
"private" =>false,
"tabs" =>[]
];
}

if ($objects === false) {
return new Response(Array("status" => "error"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function getApplicationChannel($application, $workspace)
$channel->setDirect(false);
$channel->setApplication(true);

$channel->setOriginalGroupId($workspace->getGroup()->getId());
$channel->setOriginalGroupId($workspace->getGroup());
$channel->setOriginalWorkspaceId($workspace->getId());

$channel->setAppId($application->getId());
Expand Down
6 changes: 3 additions & 3 deletions twake/backend/core/src/Twake/Core/Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private function importGroup()
if ($logo !== '') {
$workspace_bdd->setLogo($contents["logo"]);
}
$workspace_bdd->setGroup($group);
$workspace_bdd->setGroup($group->getId());
$manager->persist($workspace_bdd);
$workspace_id = $workspace_bdd->getId();
$manager->flush();
Expand All @@ -313,14 +313,14 @@ private function importGroup()
$contents = json_decode(fread($handle_workspace_members, filesize($workspace_members_file)), true);
$level_admin_bdd = new WorkspaceLevel();
$level_admin_bdd->setIsAdmin(true);
$level_admin_bdd->setWorkspace($workspace_bdd);
$level_admin_bdd->setWorkspace($workspace_bdd->getId());
$level_admin_bdd->setLabel("Administrator");
$manager->persist($level_admin_bdd);
$manager->flush();
$level_admin_id = $level_admin_bdd->getId();

$level_none_bdd = new WorkspaceLevel();
$level_none_bdd->setWorkspace($workspace_bdd);
$level_none_bdd->setWorkspace($workspace_bdd->getId());
$level_none_bdd->setLabel("Basic user");
$manager->persist($level_none_bdd);
$manager->flush();
Expand Down
6 changes: 3 additions & 3 deletions twake/backend/core/src/Twake/Core/Controller/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ function getVersion(Request $request)
"auth_mode" => array_keys($auth),
"auth" => $auth,
"version" => [
"current" => /* @VERSION_DETAIL */ "2021.Q3.640",
"current" => /* @VERSION_DETAIL */ "2021.Q3.735",
"minimal" => [
"web" => /* @MIN_VERSION_WEB */ "2021.Q3.640",
"mobile" => /* @MIN_VERSION_MOBILE */ "2021.Q3.640",
"web" => /* @MIN_VERSION_WEB */ "2021.Q3.735",
"mobile" => /* @MIN_VERSION_MOBILE */ "2021.Q3.735",
]
],
"elastic_search_available" => !!$this->container->getParameter("es.host"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\StringType;


class TwakeTextType extends StringType
{
/**
Expand All @@ -14,10 +15,6 @@ class TwakeTextType extends StringType
private $secretKey;
protected $searchable = false;

/**
* Initialization of encryptor
* @param string $key
*/
public function setEncryptionKey($key)
{
$this->secretKey = $key;
Expand All @@ -26,28 +23,14 @@ public function setEncryptionKey($key)

public function convertToPHPValue($original_data, AbstractPlatform $platform)
{
if (substr($original_data, 0, 10) == "encrypted_") {
$data = substr($original_data, 10);
$data = explode("_", $data);
$salt = isset($data[1]) ? $data[1] : "";
$iv = isset($data[2]) ? base64_decode($data[2]) : $this->iv;
$data = base64_decode($data[0]);
try {
$data = openssl_decrypt(
$data,
"AES-256-CBC",
$this->secretKey . $salt,
true,
$iv
);
} catch (\Exception $e) {
$data = $original_data;
}
} else {
$data = $original_data;
$data = $this->v2Decrypt($original_data);
if(!$data["done"]){
$data = $this->v1Decrypt($original_data);
}

return $data;
if(!$data["done"]){
$data = ["data" => $this->legacyDecrypt($original_data)];
}
return $data["data"];
}

public function convertToDatabaseValue($data, AbstractPlatform $platform)
Expand Down Expand Up @@ -89,4 +72,95 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
return "TEXT";
}

public function v2Decrypt($data){
$key = substr(hash("sha256", unpack("H*", $this->secretKey)[1]), 0, 32);
$encryptedArray = explode(":", $data);

if (!count($encryptedArray) || count($encryptedArray) !== 3) {
return [
"data" => $data,
"done" => false,
];
}

$iv = base64_decode($encryptedArray[0]);
if ($encryptedArray[0] === "0000000000000000") {
$iv = "0000000000000000";
}

try {
$tag = base64_decode($encryptedArray[1]);
$str = openssl_decrypt(base64_decode($encryptedArray[2]), 'aes-256-gcm', $key, OPENSSL_RAW_DATA, $iv, $tag);
$decrypt = json_decode($str);

return [
"data" => $decrypt,
"done" => true,
];
} catch (Error $err) {
return [
"data" => $data,
"done" => false,
];
}
}

public function v1Decrypt($data){
$key = substr(base64_encode(hash("sha256", unpack("H*", $this->secretKey)[1], true)), 0, 32);
$encryptedArray = explode(":", $data);

if (!count($encryptedArray) || count($encryptedArray) !== 2) {
return [
"data" => $data,
"done" => false,
];
}

try {

$iv = @hex2bin($encryptedArray[0]);
if ($encryptedArray[0] === "0000000000000000") {
$iv = "0000000000000000";
}

$str = openssl_decrypt(@hex2bin($encryptedArray[1]), 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
$decrypt = json_decode($str);

return [
"data" => $decrypt,
"done" => true,
];
} catch (Error $err) {
return [
"data" => $data,
"done" => false,
];
}
}

public function legacyDecrypt($original_data){
if (substr($original_data, 0, 10) == "encrypted_") {
$data = substr($original_data, 10);
$data = explode("_", $data);
$salt = isset($data[1]) ? $data[1] : "";
$iv = isset($data[2]) ? base64_decode($data[2]) : $this->iv;
$data = base64_decode($data[0]);
try {
$data = openssl_decrypt(
$data,
"AES-256-CBC",
$this->secretKey . $salt,
true,
$iv
);
} catch (\Exception $e) {
$data = $original_data;
}
} else {
$data = $original_data;
}

return $data;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ private function notifyConnectors(DriveFile $file, $did_create = true, $current_

$notification_data = Array(
"group" => $workspace->getGroup()->getAsArray(),
"workspace" => $workspace->getAsArray(),
"workspace" => $workspace->getAsArray($this->em),
"file" => $file->getAsArray(),
"user" => $current_user
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getUserToken(Request $request)
//Ok
$tokenE = new Token();
$tokenE->setUser($this->getUser());
$tokenE->setWorkspace($useringroup->getWorkspace($manager));
$tokenE->setWorkspace($useringroup->getWorkspace($manager)->getId());
$tokenE->setApplication($app);

$manager->persist($tokenE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ public function event(Request $request)
$event = $request->request->get("event");
$evt_data = $request->request->get("data");


$workspace = $this->get("app.workspaces")->get($workspace_id, $this->getUser()->getId());
if ($workspace && $workspace->getGroup()->getId() == $group_id) {
if ($workspace && $workspace->getGroup() == $group_id) {
$can = $this->get("app.applications_api")->hasCapability($app_id, $group_id);
if ($can) {

$evt_data["workspace"] = $workspace->getAsArray();
$evt_data["group"] = $workspace->getGroup()->getAsArray();
$evt_data["workspace"] = $workspace->getAsArray($this->get("app.twake_doctrine"));
$evt_data["group"] = $evt_data["workspace"]["group"];
$evt_data["user"] = $this->getUser()->getAsArray();
$evt_data["user"]["email"] = $this->getUser()->getEmail();

Expand Down
Loading

0 comments on commit 7a1554b

Please sign in to comment.