Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable22] filter allowed type of member #864

Merged
merged 1 commit into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/FederatedItems/SingleMemberAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ protected function generateMember(FederatedEvent $event, Circle $circle, Member
throw new FederatedItemBadRequestException(StatusCode::$MEMBER_ADD[120], 120);
}

$allowedTypes = $this->configService->getAppValueInt(ConfigService::ALLOWED_TYPES);
if ($federatedUser->getUserType() < Member::TYPE_APP
&& ($allowedTypes & $federatedUser->getUserType()) === 0) {
throw new FederatedItemBadRequestException(StatusCode::$MEMBER_ADD[132], 132);
}

if ($federatedUser->getBasedOn()->isConfig(Circle::CFG_ROOT)) {
throw new FederatedItemBadRequestException(StatusCode::$MEMBER_ADD[125], 125);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/Model/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class Member extends ManagedModel implements
public const TYPE_CIRCLE = 16;
public const TYPE_APP = 10000;

public const ALLOWING_ALL_TYPES = 31;

public const APP_CIRCLES = 10001;
public const APP_OCC = 10002;

Expand Down
3 changes: 3 additions & 0 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class ConfigService {
public const SELF_SIGNED_CERT = 'self_signed_cert';
public const MEMBERS_LIMIT = 'members_limit';
public const ACTIVITY_ON_NEW_CIRCLE = 'creation_activity';
public const ALLOWED_TYPES = 'allowed_types';

public const MIGRATION_BYPASS = 'migration_bypass';
public const MIGRATION_22 = 'migration_22';
Expand Down Expand Up @@ -176,6 +177,8 @@ class ConfigService {
self::SELF_SIGNED_CERT => '0',
self::MEMBERS_LIMIT => '-1',
self::ACTIVITY_ON_NEW_CIRCLE => '1',
self::ALLOWED_TYPES => Member::ALLOWING_ALL_TYPES,

self::MIGRATION_BYPASS => '0',
self::MIGRATION_22 => '0',
self::MIGRATION_22_1 => '0',
Expand Down
3 changes: 2 additions & 1 deletion lib/StatusCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class StatusCode {
128 => 'Cannot add Circle as its own Member',
129 => 'Member does not contains a patron',
130 => 'Member is invited by an entity that does not belongs to the instance at the origin of the request',
131 => 'Member is a non-local Circle'
131 => 'Member is a non-local Circle',
132 => 'Member type not allowed'
];

public static $MEMBER_LEVEL = [
Expand Down