Skip to content

Commit

Permalink
⬆️ Merge v2021.Q2.505 to main
Browse files Browse the repository at this point in the history
⬆️  Merge v2021.Q2.505 to main
  • Loading branch information
RomaricMourgues authored May 7, 2021
2 parents 43f1a97 + 3060ffe commit f8def14
Show file tree
Hide file tree
Showing 185 changed files with 12,944 additions and 1,723 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ jobs:
- uses: actions/checkout@v2
- name: unit-test
run: cd twake && docker-compose -f docker-compose.yml.dist.tests run node npm run test:unit
#- name: e2e-mongo-test
# if: always()
# run: cd twake && docker-compose -f docker-compose.yml.dist.tests run -e DB_DRIVER=mongodb node npm run test:e2e
#- name: e2e-cassandra-test
# if: always()
# run: cd twake && docker-compose -f docker-compose.yml.dist.tests run -e DB_DRIVER=cassandra node npm run test:e2e
- name: e2e-mongo-test
run: cd twake && docker-compose -f docker-compose.yml.dist.tests run -e DB_DRIVER=mongodb node npm run test:e2e
- name: e2e-cassandra-test
run: cd twake && docker-compose -f docker-compose.yml.dist.tests up -d scylladb && sleep 60 && docker-compose -f docker-compose.yml.dist.tests run -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.Q2.481" >> $GITHUB_ENV'
- run: 'echo "DOCKERTAGVERSION=2021.Q2.505" >> $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.Q2.481" >> $GITHUB_ENV'
- run: 'echo "DOCKERTAGVERSION=2021.Q2.505" >> $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.Q2.481" >> $GITHUB_ENV'
- run: 'echo "DOCKERTAGVERSION=2021.Q2.505" >> $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
40 changes: 24 additions & 16 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Node Backend",
"request": "launch",
"cwd": "${workspaceFolder}/twake/backend/node/",
"runtimeArgs": [
"run",
"dev:debug"
],
"runtimeExecutable": "npm",
"port": 9229,
"outputCapture": "std",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"name": "Launch & Debug on Chrome",
"port": 9222,
"request": "launch",
"type": "chrome",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/twake/frontend/src"
},
{
"name": "Debug Node Backend",
"request": "launch",
"cwd": "${workspaceFolder}/twake/backend/node/",
"runtimeArgs": [
"run",
"dev:debug"
],
"runtimeExecutable": "npm",
"port": 9229,
"outputCapture": "std",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"name": "Debug Node Backend in Docker",
"port": 9229,
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Twake 2021.Q2.505

### Messages

- Performance improvement and bug fixing
- Ability to invite external users as guest directly in channel

# Twake 2021.Q2.481

### Messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class MongoConnector extends AbstractConnector<

return true;
}

async upsert(
entities: any[],
options: UpsertOptions = {}
Expand Down Expand Up @@ -202,7 +203,7 @@ export class MongoConnector extends AbstractConnector<
.toArray();

const entities: Table[] = [];
results.forEach((row) => {
results.forEach((row: any) => {
const entity = new (entityType as any)();
Object.keys(row).forEach((key) => {
entity[columnsDefinition[key].nodename] = transformValueToDbString(
Expand Down
4 changes: 2 additions & 2 deletions twake/backend/core/app/Common/BaseBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ protected function initRoutes()

$controller = $that->loadController($controller);
if (!$controller) {
return new Response("No controller " . $controller . " found", 500);
return new Response("No controller " . $handler . " found", 500);
}
if (!method_exists($controller, $handler)) {
return new Response("No controller handler " . $controller . "->" . $handler . " found", 500);
return new Response("No controller handler " . $handler . "->" . $handler . " found", 500);
}
return $controller->$handler($request ?: new Request());
});
Expand Down
2 changes: 1 addition & 1 deletion twake/backend/core/src/Twake/Core/Controller/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function getVersion(Request $request)
"auth_mode" => array_keys($auth),
"auth" => $auth,
"version" => [
"current" => /* @VERSION_DETAIL */ "2021.Q2.481",
"current" => /* @VERSION_DETAIL */ "2021.Q2.505",
"minimal" => [
"web" => /* @MIN_VERSION_WEB */ "2021.Q1.481",
"mobile" => /* @MIN_VERSION_MOBILE */ "2021.Q1.385",
Expand Down
135 changes: 132 additions & 3 deletions twake/backend/core/src/Twake/Discussion/Entity/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,136 @@ public function setIncrementAtTime($increment_at_time)
$this->increment_at_time = $increment_at_time;
}

public function getMessageTypeObject() {
switch($this->getMessageType()) {
case 1: return Array(
"type" => "message",
"subtype" => "application",
);
case 2: return Array(
"type" => "message",
"subtype" => "system",
);
case 0:
default:
return Array(
"type" => "message",
"subtype" => null,
);
}
}

public function getNewApiObjectReactions($messageEntity) {
$reactions = Array();

if($messageEntity->getReactions() == null) return $reactions;

$orignal_reactions_array = $messageEntity->getReactions();

foreach($orignal_reactions_array as $key => $value){
$new_reaction_object = Array(
"name" => $value["name"] ?: $key
);
$new_reaction_object = array_merge($new_reaction_object, $value);
$new_reaction_object["users"] = array_values($new_reaction_object["users"]);

array_push($reactions, $new_reaction_object);
}

return $reactions;
}

/**
* Set files for new api object
*/
public function setFiles($messageEntity) {
$files = Array();

if(!isset($messageEntity->getContent()['files'])) return $files;

$orignal_files = $messageEntity->getContent()['files'];

foreach($orignal_files as $file){
if($file["type"] == "file") {
$new_file_format = Array(
"company_id" => "",
"message_id" => $messageEntity->getId(),
"id" => $file["content"],
"metadata" => Array(
"source" => "drive",
"external_id" => $file["content"]
),
);
array_push($files, $new_file_format);
}
}

return $files;
}

/**
* Set blocks for new api object
*/
public function setBlocks($messageEntity) {
$blocks = Array();
$content = $messageEntity->getContent();

if(!isset($content)) return $blocks;

$markdown_element = Array(
"type" => "mrkdwn",
"text" => isset($content['original_str']) ? $content['original_str'] : ""
);

$new_block_format = Array(
"type" => "section",
"text" => $markdown_element
);

array_push($blocks, $new_block_format);

return $blocks;
}

/**
* Generate new api object
*/
public function generateNewApiObject($messageEntity, $array) {

$message_type_object = $messageEntity->getMessageTypeObject();
$api_object = Array(
"id" => $messageEntity->getId(),
"channel_id" => $messageEntity->getChannelId(),
"thread_id" => $messageEntity->getParentMessageId(),
"created_at" => ($messageEntity->getCreationDate() ? $messageEntity->getCreationDate()->getTimestamp() : null),
"application_id" => $messageEntity->getApplicationId(),
"user_id" => ($messageEntity->getSender() ? $messageEntity->getSender()->getId() : null),
"edited" => $messageEntity->getEdited(),
"text" => isset($messageEntity->getContent()['original_str']) ? $messageEntity->getContent()['original_str'] : "",
"blocks" => $messageEntity->setBlocks($messageEntity),
"files" => $messageEntity->setFiles($messageEntity),
"context" => $messageEntity->getHiddenData(),
"title" => $messageEntity->getHiddenData()['custom_title'] ?: null,
"picture" => $messageEntity->getHiddenData()['custom_icon'] ?: null,
"stats" => Array(
"answers" => $messageEntity->getResponsesCount()
),
"pinned_info" => Array(
"pinned_by" => ($messageEntity->getSender() ? $messageEntity->getSender()->getId() : null),
"pinned_at" => 0,
),
"reactions" => $messageEntity->getNewApiObjectReactions($messageEntity),
);

return $array = array_merge($api_object, $message_type_object);
}


public function getAsArray()
{
return Array(
{
$api_object = $this->generateNewApiObject($this, $api_object);

$old_message_object = Array(
"id" => $this->getId(),
"front_id" => $this->getFrontId(),
"channel_id" => $this->getChannelId(),
Expand All @@ -492,13 +619,15 @@ public function getAsArray()
"edited" => $this->getEdited(),
"pinned" => $this->getPinned(),
"hidden_data" => $this->getHiddenData(),
"reactions" => $this->getReactions(),
"_reactions" => $this->getReactions(),
"modification_date" => ($this->getModificationDate() ? $this->getModificationDate()->getTimestamp() : null),
"creation_date" => ($this->getCreationDate() ? $this->getCreationDate()->getTimestamp() : null),
"content" => $this->getContent(),
"user_specific_content" => $this->getUserSpecificContent(),
"increment_at_time" => $this->getIncrementAtTime(),
);

return array_merge($old_message_object, $api_object);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,12 @@ public function save($object, $options, $user = null, $application = null)
if (isset($object["_user_reaction"]) && $user && $message->getId()) {
$message_reaction_repo = $this->em->getRepository("Twake\Discussion:MessageReaction");
$message_reaction = $message_reaction_repo->findOneBy(Array("user_id" => $user->getId(), "message_id" => $message->getId()));
$current_reactions = $message->getReactions();
$current_reactions = [];

foreach($message->getAsArray()["reactions"] as $key => $reaction){
$current_reactions[$reaction["name"] ?: $key] = $reaction;
}

$user_reaction = $object["_user_reaction"];
$reaction = Array();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function invite(Request $request)
$workspaceId = $request->request->get("workspace_id", "");
$asExterne = false;
$emails = $request->request->get("emails", []);
$role = $request->request->get("role", "member");

// Get company code
$doctrine = $this->get("app.twake_doctrine");
Expand All @@ -85,12 +86,30 @@ public function invite(Request $request)
}

$companyCode = $company->getIdentityProviderId();
$data = [
"emails" => $emails
];

$header = "Authorization: Basic " . $this->authB64;
$response = $this->api->post(rtrim($this->endpoint, "/") . "/companies/" . $companyCode . "/users/invitation", json_encode($data), array(CURLOPT_HTTPHEADER => [$header, "Content-Type: application/json"]));

if($role === "member") {
$data = [
"emails" => $emails,
"inviter" => [
"name" => $this->getUser()->getFullName(),
"email" => $this->getUser()->getEmail()
]
];
$response = $this->api->post(rtrim($this->endpoint, "/") . "/companies/" . $companyCode . "/users/invitation", json_encode($data), array(CURLOPT_HTTPHEADER => [$header, "Content-Type: application/json"]));
}
else {
$data = [
"firstName" => $emails[0],
"lastName" => "-",
"email" => $emails[0],
"password" => base64_encode(random_bytes(6)),
"role" => $role
];
$response = $this->api->post(rtrim($this->endpoint, "/") . "/companies/" . $companyCode . "/users", json_encode($data), array(CURLOPT_HTTPHEADER => [$header, "Content-Type: application/json"]));
}

$result = json_decode($response->getContent(), 1);

return new Response(["data" => $result]);
Expand Down
18 changes: 10 additions & 8 deletions twake/backend/core/src/Twake/Users/Controller/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ class Users extends BaseController
public function search(Request $request)
{

$scroll_id = $request->request->get("scroll_id");
$repository = "Twake\Users:User";
$options = $request->request->get("query", $request->request->get("options", Array()));

if (is_string($options)) {
$options = Array("name" => $options);
}

if (isset($scroll_id) && isset($repository)) {
$globalresult = $this->get('globalsearch.pagination')->getnextelement($scroll_id, $repository);
} else {
$globalresult = $this->get("app.users")->search($options);
$globalresult = $this->get("app.users")->search($options);

$users = [];
foreach($globalresult["users"] as $obj){
$users[] = $this->get("app.users")->completeUserWithCompanies($obj, $this->getUser());
}

$globalresult["users"] = $users;

$data = Array("data" => $globalresult);

return new Response($data);
Expand All @@ -47,7 +47,9 @@ public function getById(Request $request)
}else{
$user = [];
foreach($id as $singleId){
$user[] = $this->get("app.users")->getById($singleId);
$obj = $this->get("app.users")->getById($singleId);
$obj = $this->get("app.users")->completeUserWithCompanies($obj, $this->getUser());
$user[] = $obj;
}
}

Expand Down
Loading

0 comments on commit f8def14

Please sign in to comment.