Skip to content

Commit 3364278

Browse files
Release v4.2.6
1 parent dbd61ba commit 3364278

File tree

33 files changed

+649
-145
lines changed

33 files changed

+649
-145
lines changed

php_monolith/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM docker.getcompass.ru/service/php-8:8.1.25-15-devonpremise
33
ARG BRANCH
44

55
RUN apk update && apk add --no-cache curl-dev
6-
ARG COUNT=102
6+
ARG COUNT=106
77
COPY --chown=www-data:www-data . /app
88

99
COPY --from=packages /tmp/migrate /usr/local/bin/migrate

php_monolith/src/Compass/Company/api/includes/apiv2/member.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,20 @@ class Apiv2_Member extends \BaseFrame\Controller\Api {
4242
*/
4343
public function getList():array {
4444

45-
$query = $this->post(\Formatter::TYPE_STRING, "query", "");
46-
$offset = $this->post(\Formatter::TYPE_INT, "offset", 0);
47-
$limit = $this->post(\Formatter::TYPE_INT, "limit", 100);
48-
$filter_npc_type = $this->post(\Formatter::TYPE_ARRAY, "filter_npc_type", []);
49-
$filter_role = $this->post(\Formatter::TYPE_ARRAY, "filter_role", []);
50-
$sort_field = $this->post(\Formatter::TYPE_STRING, "sort_field", "");
45+
$query = $this->post(\Formatter::TYPE_STRING, "query", "");
46+
$offset = $this->post(\Formatter::TYPE_INT, "offset", 0);
47+
$limit = $this->post(\Formatter::TYPE_INT, "limit", 100);
48+
$filter_npc_type = $this->post(\Formatter::TYPE_ARRAY, "filter_npc_type", []);
49+
$filter_role = $this->post(\Formatter::TYPE_ARRAY, "filter_role", []);
50+
$filter_query_field = $this->post(\Formatter::TYPE_ARRAY, "filter_query_field", []);
51+
$sort_field = $this->post(\Formatter::TYPE_STRING, "sort_field", "");
5152

5253
try {
5354

5455
$member_id_list = Domain_Member_Scenario_Apiv2::getList(
55-
$this->user_id, $this->role, $this->permissions, $query, $limit + 1, $offset, $filter_npc_type, $filter_role, $sort_field
56+
$this->user_id, $this->role, $this->permissions, $query, $limit + 1, $offset, $filter_npc_type, $filter_role, $filter_query_field, $sort_field
5657
);
57-
} catch (IsNotAdministrator|\CompassApp\Domain\Member\Exception\ActionNotAllowed) {
58+
} catch (IsNotAdministrator | \CompassApp\Domain\Member\Exception\ActionNotAllowed) {
5859
throw new CaseException(Permission::ACTION_NOT_ALLOWED_ERROR_CODE, "action not allowed");
5960
} catch (UserIsGuest) {
6061

php_monolith/src/Compass/Company/api/includes/domain/join_link/scenario/socket.php

+2-14
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,6 @@ public static function getCreatorUserId(string $invite_link_uniq):int {
9797
/**
9898
* Принимаем инвайт
9999
*
100-
* @param int $user_id
101-
* @param string $invite_link_uniq
102-
* @param string $comment
103-
* @param string $full_name
104-
* @param string $avatar_file_key
105-
* @param int $avatar_color_id
106-
* @param string $locale
107-
* @param bool $is_force_exit_task_not_exist
108-
* @param int $avg_screen_time
109-
* @param int $total_action_count
110-
* @param int $avg_message_answer_time
111-
*
112-
* @return array
113100
* @throws \BaseFrame\Exception\Domain\LocaleTextNotFound
114101
* @throws \BaseFrame\Exception\Domain\ParseFatalException
115102
* @throws \BaseFrame\Exception\Domain\ReturnFatalException
@@ -129,7 +116,7 @@ public static function getCreatorUserId(string $invite_link_uniq):int {
129116
*/
130117
public static function acceptInvite(int $user_id, string $invite_link_uniq, string $comment, string $full_name, string $avatar_file_key, int $avatar_color_id,
131118
string $locale, bool $is_force_exit_task_not_exist, int $avg_screen_time, int $total_action_count, int $avg_message_answer_time,
132-
bool $force_postmoderation):array {
119+
bool $force_postmoderation, array $ldap_account_data):array {
133120

134121
// смотрим, что компания не удалена
135122
Domain_Company_Entity_Dynamic::assertCompanyIsNotDeleted();
@@ -190,6 +177,7 @@ public static function acceptInvite(int $user_id, string $invite_link_uniq, s
190177
avg_screen_time: $avg_screen_time,
191178
total_action_count: $total_action_count,
192179
avg_message_answer_time: $avg_message_answer_time,
180+
ldap_account_data: $ldap_account_data,
193181
);
194182

195183
// создаем диалог с создателем заявки

php_monolith/src/Compass/Company/api/includes/domain/member/action/get_list_by_query.php

+50-8
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,25 @@ class Domain_Member_Action_GetListByQuery {
2424
"left" => Member::ROLE_LEFT,
2525
];
2626

27+
protected const _ALLOWED_FILTER_QUERY_FIELDS = [
28+
"badge",
29+
];
30+
31+
protected const _FILTER_BADGE_FOR_GUEST = [
32+
"гость",
33+
"guest",
34+
];
35+
2736
/**
2837
* Получаем список пользователей по запросу
2938
*/
30-
public static function do(string $query, int $limit, int $offset, array $filter_npc_type, array $filter_role, array $sort_fields, bool $is_legacy = false):array {
39+
public static function do(string $query, int $limit, int $offset, array $filter_npc_type, array $filter_role, array $filter_query_field, array $sort_fields, bool $is_legacy = false):array {
3140

3241
// для старых версий получаем пользователей старым способом
3342
if ($is_legacy) {
3443
return Gateway_Db_CompanyData_MemberList::getListByQueryLegacy($query, $limit, $offset, $filter_npc_type, $filter_role);
3544
} else {
36-
return Gateway_Db_CompanyData_MemberList::getListByQuery($query, $limit, $offset, $filter_npc_type, $filter_role, $sort_fields);
45+
return Gateway_Db_CompanyData_MemberList::getListByQuery($query, $limit, $offset, $filter_npc_type, $filter_role, $filter_query_field, $sort_fields);
3746
}
3847
}
3948

@@ -46,13 +55,15 @@ public static function do(string $query, int $limit, int $offset, array $filter_
4655
* @param string $sort_field
4756
* @param array $filter_npc_type
4857
* @param array $filter_role
58+
* @param array $filter_query_field
59+
* @param string $query
4960
*
5061
* @return array
5162
* @throws ParamException
52-
* @throws \BaseFrame\Exception\Domain\ParseFatalException
5363
* @throws \BaseFrame\Exception\Request\ParamException
64+
* @long - множество проверок
5465
*/
55-
public static function prepareParams(int $member_role, int $limit, int $offset, string $sort_field, array $filter_npc_type, array $filter_role):array {
66+
public static function prepareParams(int $member_role, int $limit, int $offset, string $sort_field, array $filter_npc_type, array $filter_role, array $filter_query_field, string $query):array {
5667

5768
if ($limit < 1 || $offset < 0) {
5869
throw new ParamException("invalid limit or offset");
@@ -75,21 +86,37 @@ public static function prepareParams(int $member_role, int $limit, int $offset,
7586
$filter_role = self::_prepareFilterRole($filter_role);
7687
}
7788

89+
if (count($filter_query_field) > 0) {
90+
91+
self::_prepareFilterQueryField($filter_query_field);
92+
93+
// если клиент ожидает получить гостей по бейджу
94+
if (in_array(mb_strtolower($query), self::_FILTER_BADGE_FOR_GUEST)) {
95+
96+
// актуализируем параметры для поиска - роль "гость" и поисковый запрос "Guest"
97+
$filter_role = [Member::ROLE_GUEST];
98+
$query = "guest";
99+
}
100+
}
101+
78102
$sort_field = self::_prepareSortFields($member_role, $sort_field);
79103

80-
return [$sort_field, $filter_npc_type, $filter_role];
104+
return [$sort_field, $filter_npc_type, $filter_role, $query];
81105
}
82106

83107
/**
84108
* получаем список npc_type для фильтра
85-
*
86-
* @throws \BaseFrame\Exception\Domain\ParseFatalException
87109
*/
88110
protected static function _prepareFilterNpcTypeList(array $filter_client_npc_type):array {
89111

90112
$filter_npc_type = [];
91113
foreach ($filter_client_npc_type as $user_type) {
92-
$filter_npc_type[] = Type_User_Main::getNpcTypeByUserType($user_type);
114+
115+
try {
116+
$filter_npc_type[] = Type_User_Main::getNpcTypeByUserType($user_type);
117+
} catch (\BaseFrame\Exception\Domain\ParseFatalException) {
118+
throw new ParamException("invalid client npc_type");
119+
}
93120
}
94121

95122
return $filter_npc_type;
@@ -115,6 +142,21 @@ protected static function _prepareFilterRole(array $filter_client_role):array {
115142
return $filter_role;
116143
}
117144

145+
/**
146+
* получаем список полей для фильтра по поисковому запросу
147+
*
148+
* @throws ParamException
149+
*/
150+
protected static function _prepareFilterQueryField(array $filter_client_query_field):void {
151+
152+
foreach ($filter_client_query_field as $query_field) {
153+
154+
if (!in_array($query_field, self::_ALLOWED_FILTER_QUERY_FIELDS)) {
155+
throw new ParamException("unknown filter_query_field: {$query_field}");
156+
}
157+
}
158+
}
159+
118160
/**
119161
* получаем строку для сортировки
120162
*

php_monolith/src/Compass/Company/api/includes/domain/member/scenario/api.php

-27
Original file line numberDiff line numberDiff line change
@@ -429,33 +429,6 @@ public static function setDescriptionBadgeAndJoinTime(int $role, int $perm
429429
Domain_Member_Action_SetDescriptionBadgeAndJoinTime::do($modified_user_id, $description, $time, $color_id, $content);
430430
}
431431

432-
/**
433-
* Получить список участников компании
434-
*
435-
* @throws \BaseFrame\Exception\Domain\ParseFatalException
436-
* @throws \BaseFrame\Exception\Domain\ReturnFatalException
437-
* @throws \BaseFrame\Exception\Gateway\BusFatalException
438-
* @throws \BaseFrame\Exception\Request\CompanyNotServedException
439-
* @throws \BaseFrame\Exception\Request\ControllerMethodNotFoundException
440-
* @throws \CompassApp\Domain\Member\Exception\ActionNotAllowed
441-
* @throws \ParamException
442-
* @throws \cs_RowIsEmpty
443-
* @throws \queryException
444-
*/
445-
public static function getList(int $user_id, int $role, int $method_version, string $query, int $limit, int $offset, array $filter_npc_type,
446-
array $filter_role = [], string $sort_field = ""):array {
447-
448-
// проверяем параметры
449-
[$sort_field, $filter_npc_type, $filter_role] = Domain_Member_Action_GetListByQuery::prepareParams($role,
450-
$limit, $offset, $sort_field, $filter_npc_type, $filter_role
451-
);
452-
453-
Domain_Member_Entity_Permission::checkSpace($user_id, $method_version, Permission::IS_SHOW_COMPANY_MEMBER_ENABLED);
454-
455-
// получаем список участников
456-
return Domain_Member_Action_GetListByQuery::do($query, $limit, $offset, $filter_npc_type, $filter_role, $sort_field, true);
457-
}
458-
459432
/**
460433
* Получить права
461434
*

php_monolith/src/Compass/Company/api/includes/domain/member/scenario/apiv2.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ class Domain_Member_Scenario_Apiv2 {
4141
* @throws \queryException
4242
*/
4343
public static function getList(int $user_id, int $role, int $permissions, string $query, int $limit, int $offset, array $filter_npc_type,
44-
array $filter_role = [], string $sort_field = ""):array {
44+
array $filter_role = [], array $filter_query_field = [], string $sort_field = ""):array {
4545

4646
Member::assertUserNotGuest($role);
4747

4848
// проверяем параметры
49-
[$sort_fields, $filter_npc_type, $filter_role] = Domain_Member_Action_GetListByQuery::prepareParams(
50-
$role, $limit, $offset, $sort_field, $filter_npc_type, $filter_role
49+
[$sort_fields, $filter_npc_type, $filter_role, $query] = Domain_Member_Action_GetListByQuery::prepareParams(
50+
$role, $limit, $offset, $sort_field, $filter_npc_type, $filter_role, $filter_query_field, $query
5151
);
5252

5353
// если получаем ботов или удалённых, то проверяем права на админа
@@ -63,6 +63,6 @@ public static function getList(int $user_id, int $role, int $permissions, stri
6363
}
6464

6565
// получаем список участников
66-
return Domain_Member_Action_GetListByQuery::do($query, $limit, $offset, $filter_npc_type, $filter_role, $sort_fields);
66+
return Domain_Member_Action_GetListByQuery::do($query, $limit, $offset, $filter_npc_type, $filter_role, $filter_query_field, $sort_fields);
6767
}
6868
}

php_monolith/src/Compass/Company/api/includes/domain/user/action/add_user.php

+28-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static function do(
4545
int $avg_screen_time = 0,
4646
int $total_action_count = 0,
4747
int $avg_message_answer_time = 0,
48+
array $ldap_account_data = [],
4849
):string {
4950

5051
try {
@@ -56,7 +57,7 @@ public static function do(
5657

5758
// добавляем участника в компанию
5859
self::_add($user_id, $role, $npc_type, $permissions, $mbti_type, $full_name, $avatar_file_key, $avatar_color_id, $comment,
59-
$locale, $is_creator, $pin_code, $avg_screen_time, $total_action_count, $avg_message_answer_time);
60+
$locale, $is_creator, $pin_code, $avg_screen_time, $total_action_count, $avg_message_answer_time, $ldap_account_data);
6061

6162
// создаем запись в dynamic-данных для карточки
6263
Type_User_Card_DynamicData::add($user_id);
@@ -121,11 +122,16 @@ public static function do(
121122
*/
122123
protected static function _add(int $user_id, int $role, int $npc_type, int $permissions, string $mbti_type, string $full_name, string $avatar_file_key,
123124
int $avatar_color_id, string $comment, string $locale, bool $is_creator, string|false $pin_code = false,
124-
int $avg_screen_time = 0, int $total_action_count = 0, int $avg_message_answer_time = 0):int {
125+
int $avg_screen_time = 0, int $total_action_count = 0, int $avg_message_answer_time = 0, array $ldap_account_data = []):int {
125126

126127
// получаем первоначальные данные вступаемого участника
127128
[$short_description, $badge_color_id, $badge_content] = Domain_Member_Entity_EmployeeCard::getJoiningInitialData($role, $is_creator, $locale);
128129

130+
// если переданы ldap учётное записи - актуализируем первоначальные данные
131+
if (count($ldap_account_data) > 0) {
132+
[$badge_content, $short_description, $comment] = self::_actualizeJoinDataByLdap($ldap_account_data, $badge_content, $short_description, $comment);
133+
}
134+
129135
Gateway_Db_CompanyData_Main::beginTransaction();
130136

131137
// инициализируем extra
@@ -155,6 +161,26 @@ protected static function _add(int $user_id, int $role, int $npc_type, int $perm
155161
return $time;
156162
}
157163

164+
/**
165+
* Актуализировать первоначальные данные из ldap данных учётной записи.
166+
*/
167+
protected static function _actualizeJoinDataByLdap(array $ldap_account_data, string $badge_content, string $short_description, string $comment):array {
168+
169+
if (isset($ldap_account_data["role"]) && $ldap_account_data["role"] !== false) {
170+
$short_description = Domain_Member_Entity_Sanitizer::sanitizeDescription($ldap_account_data["role"]);
171+
}
172+
173+
if (isset($ldap_account_data["bio"]) && $ldap_account_data["bio"] !== false) {
174+
$comment = Domain_Member_Entity_Sanitizer::sanitizeStatus($ldap_account_data["bio"]);
175+
}
176+
177+
if (isset($ldap_account_data["badge"]) && $ldap_account_data["badge"] !== false) {
178+
$badge_content = Domain_Member_Entity_Sanitizer::sanitizeBadgeContent($ldap_account_data["badge"]);
179+
}
180+
181+
return [$badge_content, $short_description, $comment];
182+
}
183+
158184
/**
159185
* шлем эвент о вступлении пользователя в компанию
160186
*

php_monolith/src/Compass/Company/api/includes/domain/user/scenario/socket.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public static function addCreator(
5858
string $user_agent,
5959
int $avg_screen_time,
6060
int $total_action_count,
61-
int $avg_message_answer_time
61+
int $avg_message_answer_time,
62+
array $ldap_account_data,
6263
):array {
6364

6465
// получаем статус увольнения кандидата (уволился, вообще не увольнялся, на этапе увольнения)
@@ -75,7 +76,8 @@ public static function addCreator(
7576
$avatar_file_key, $avatar_color_id, "", $locale, $pin_code, $inviter_user_id, npc_type: $npc_type, approved_by_user_id: $user_id,
7677
is_trial_activated: (bool) $is_trial_activated, is_need_create_intercom_conversation: $is_need_create_intercom_conversation,
7778
ip: $ip, user_agent: $user_agent, is_creator: true,
78-
avg_screen_time: $avg_screen_time, total_action_count: $total_action_count, avg_message_answer_time: $avg_message_answer_time);
79+
avg_screen_time: $avg_screen_time, total_action_count: $total_action_count, avg_message_answer_time: $avg_message_answer_time,
80+
ldap_account_data: $ldap_account_data);
7981
return [$entry_id, $token_hash, $role, $permissions];
8082
}
8183

0 commit comments

Comments
 (0)