Automatically add all devices to the Admin

Eugeny Shlyagin a year ago

I have a question about simplifying the administrator's work.
If another user added a device himself, is it possible to link all added devices to the Admin with one SQL command:

INSERT INTO tc_user_user (userid, manageduserid)
SELECT 1, u.id
FROM tc_users u
WHERE u.id != 1
  AND u.id NOT IN (
    SELECT manageduserid
    FROM tc_user_user
    WHERE userid = 1
  );

By making changes only to the table "tc_user_user", or can this break something?

(Taking this opportunity, Anton, thank you for the great work you have done.)

Anton Tananaev a year ago

This doesn't link any devices. It just links users.

Eugeny Shlyagin a year ago

Oh my mistake i meant three similar requests. Thanks for the answer!

INSERT INTO tc_user_device (userid, deviceid)
SELECT 1, u.id
FROM tc_users u
WHERE u.id != 1
  AND u.id NOT IN (
    SELECT deviceid
    FROM tc_user_device
    WHERE userid = 1
  );
INSERT INTO tc_user_user (userid, manageduserid)
SELECT 1, u.id
FROM tc_users u
WHERE u.id != 1
  AND u.id NOT IN (
    SELECT manageduserid
    FROM tc_user_user
    WHERE userid = 1
  );
INSERT INTO tc_user_group (userid, groupid)
SELECT 1, u.id
FROM tc_users u
WHERE u.id != 1
  AND u.id NOT IN (
    SELECT groupid
    FROM tc_user_group
    WHERE userid = 1
  );

Link users and groups so that there is no error when opening the list of devices in the control panel.
These three requests will be enough, right?

Anton Tananaev a year ago

Yeah, but seems overcomplicated. You can just select all devices and add a record for each one.