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

probeCircles() with dataProbe for initiator returns wrong member level. #1757

Open
mejo- opened this issue Nov 18, 2024 · 0 comments · May be fixed by #1758
Open

probeCircles() with dataProbe for initiator returns wrong member level. #1757

mejo- opened this issue Nov 18, 2024 · 0 comments · May be fixed by #1758

Comments

@mejo-
Copy link
Member

mejo- commented Nov 18, 2024

Using CirclesManager like in the following code, $level is always 9 (owner), regardless of the real membership level of the initiator:

$dataProbe = new DataProbe();
$dataProbe->add(DataProbe::INITIATOR);
$circles = $this->circlesManager->probeCircles(null, $dataProbe);
$level = $circles[0]->getInitiator->getLevel();

This is because the built SQL query fetches the row from oc_circles_memberships that matches the singleId of the user and level = 9 (which will always be the entry for the internal user circle):

SELECT `b`.`unique_id`, `b`.`name`, `b`.`display_name`, `b`.`sanitized_name`, `b`.`source`, `b`.`description`, `b`.`settings`, `b`.`config`, `b`.`contact_addressbook`, `b`.`contact_groupname`, `b`.`creation`,
    `b_j`.`single_id` AS `b_j_single_id`, `b_j`.`circle_id` AS `b_j_circle_id`, `b_j`.`level` AS `b_j_level`, `b_j`.`inheritance_first` AS `b_j_inheritance_first`, `b_j`.`inheritance_last` AS `b_j_inheritance_last`, `b_j`.`inheritance_path` AS `b_j_inheritance_path`, `b_j`.`inheritance_depth` AS `b_j_inheritance_depth`,
    `b_h`.`circle_id` AS `b_h_circle_id`, `b_h`.`member_id` AS `b_h_member_id`, `b_h`.`single_id` AS `b_h_single_id`, `b_h`.`user_id` AS `b_h_user_id`, `b_h`.`instance` AS `b_h_instance`, `b_h`.`user_type` AS `b_h_user_type`, `b_h`.`level` AS `b_h_level`, `b_h`.`status` AS `b_h_status`, `b_h`.`note` AS `b_h_note`, `b_h`.`contact_id` AS `b_h_contact_id`, `b_h`.`cached_name` AS `b_h_cached_name`, `b_h`.`cached_update` AS `b_h_cached_update`, `b_h`.`contact_meta` AS `b_h_contact_meta`, `b_h`.`joined` AS `b_h_joined`
    FROM `oc_circles_circle` `b`
    INNER JOIN `oc_circles_membership` `b_j` ON `b_j`.`circle_id` = `b`.`unique_id`
    LEFT JOIN `oc_circles_member` `b_h` ON (`b_h`.`circle_id` = `b_j`.`circle_id`) AND (`b_h`.`level` = 9)
    WHERE ((`b`.`config` & 1) = 0) AND (`b_j`.`single_id` = 'lJP1dHBWxDPRQVuAiJdMXRINhUQANjp') ORDER BY `b`.`creation` asc;

The query results in the following for a user who is simple member (not admin/owner!) of only one circle:

*************************** 1. row ***************************
            unique_id: s1MLI2cvAvaiZiqgZdpNPYKl2IvCRbV
                 name: Mountpoints
         display_name: Mountpoints
       sanitized_name: Mountpoints
               source: 16
          description: 
             settings: {"population":5,"populationInherited":5}
               config: 131072
  contact_addressbook: 0
    contact_groupname: 
             creation: 2024-11-18 14:24:11
        b_j_single_id: lJP1dHBWxDPRQVuAiJdMXRINhUQANjp
        b_j_circle_id: s1MLI2cvAvaiZiqgZdpNPYKl2IvCRbV
            b_j_level: 4
b_j_inheritance_first: lJP1dHBWxDPRQVuAiJdMXRINhUQANjp
 b_j_inheritance_last: s1MLI2cvAvaiZiqgZdpNPYKl2IvCRbV
 b_j_inheritance_path: ["lJP1dHBWxDPRQVuAiJdMXRINhUQANjp"]
b_j_inheritance_depth: 1
        b_h_circle_id: s1MLI2cvAvaiZiqgZdpNPYKl2IvCRbV
        b_h_member_id: Km4TbpvMCOhECEsOyYQBl1fKp4uJycn
        b_h_single_id: LNJW3yFpJny55cWdmLKvQiHc98AFe4H
          b_h_user_id: jane
         b_h_instance: 
        b_h_user_type: 1
            b_h_level: 9
           b_h_status: Member
             b_h_note: {"invitedBy":{"id":"LNJW3yFpJny55cWdmLKvQiHc98AFe4H","userId":"jane","userType":1,"displayName":"jane","instance":"nextcloud.local","basedOn":{"id":"LNJW3yFpJny55cWdmLKvQiHc98AFe4H","name":"user:jane:LNJW3yFpJny55cWdmLKvQiHc98AFe4H","displayName":"jane","sanitizedName":"","source":1,"population":0,"config":1,"description":"","url":"\/index.php\/apps\/contacts\/direct\/circle\/LNJW3yFpJny55cWdmLKvQiHc98AFe4H","creation":1731414937,"initiator":null}}}
       b_h_contact_id: 
      b_h_cached_name: jane
    b_h_cached_update: 2024-11-18 14:24:11
     b_h_contact_meta: NULL
           b_h_joined: 2024-11-18 14:24:11
1 row in set (0.004 sec)

See the b_h_level field in the result above. It should be 4 in this case, not 9!

mejo- added a commit that referenced this issue Nov 18, 2024
Before, the member entry that matched the `singleId` of the user and
`level = 9` was used as initiator, which in practice means the member
entry for the internal user circle of the user most of the time.

Instead, we want to use the member entry that matches `singleId` of
the user and `circleId` of the circle in question.

This fixes the wrong `level` being set for `initiator` when calling
`circleProbe()` with `DataProbe::INITIATOR`.

Fixes: #1757

Signed-off-by: Jonas <jonas@freesources.org>
mejo- added a commit that referenced this issue Nov 19, 2024
Before, the member entry that matched the `singleId` of the user and
`level = 9` was used as initiator, which in practice means the member
entry for the internal user circle of the user most of the time.

Instead, we want to use the member entry that matches `singleId` of
the user and `circleId` of the circle in question.

This fixes the wrong `level` being set for `initiator` when calling
`circleProbe()` with `DataProbe::INITIATOR`.

Fixes: #1757

Signed-off-by: Jonas <jonas@freesources.org>
mejo- added a commit that referenced this issue Nov 20, 2024
Before, the member entry that matched the `singleId` of the user and
`level = 9` was used as initiator, which in practice means the member
entry for the internal user circle of the user most of the time.

Instead, we want to use the member entry that matches `singleId` of
the user and `circleId` of the circle in question.

This fixes the wrong `level` being set for `initiator` when calling
`circleProbe()` with `DataProbe::INITIATOR`.

Fixes: #1757

Signed-off-by: Jonas <jonas@freesources.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant