| @@ -94,8 +94,29 @@ | ||
| 94 | 94 | |
| 95 | 95 | return self::userCan(['manage_all_data', 'manage_other_calendars']); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | + /** | |
| 99 | + * Whether the current user may make $memberIds hosts. Anyone outside $allowedIds | |
| 100 | + * is someone new being assigned, which is the same act as creating a calendar | |
| 101 | + * for another user. | |
| 102 | + * | |
| 103 | + * @param int[] $memberIds | |
| 104 | + * @param int[] $allowedIds | |
| 105 | + * @return bool | |
| 106 | + */ | |
| 107 | + public static function canAssignHosts($memberIds, $allowedIds) | |
| 108 | + { | |
| 109 | + $memberIds = array_map('intval', (array) $memberIds); | |
| 110 | + $allowedIds = array_map('intval', (array) $allowedIds); | |
| 111 | + | |
| 112 | + if (!array_diff($memberIds, $allowedIds)) { | |
| 113 | + return true; | |
| 114 | + } | |
| 115 | + | |
| 116 | + return self::canManageOtherHosts(); | |
| 117 | + } | |
| 118 | + | |
| 98 | 119 | public static function hasCalendarAccess($calendar) |
| 99 | 120 | { |
| 100 | 121 | $hasAccess = self::userCan('manage_all_data') || $calendar->user_id == get_current_user_id(); |
| 101 | 122 | |
| @@ -135,8 +156,18 @@ | ||
| 135 | 156 | } |
| 136 | 157 | } |
| 137 | 158 | |
| 138 | 159 | return false; |
| 160 | + } | |
| 161 | + | |
| 162 | + /** | |
| 163 | + * Whether the current user may act for, assign or see the details of other hosts. | |
| 164 | + * | |
| 165 | + * @return bool | |
| 166 | + */ | |
| 167 | + public static function canManageOtherHosts() | |
| 168 | + { | |
| 169 | + return self::userCan(['manage_all_data', 'invite_team_members']); | |
| 139 | 170 | } |
| 140 | 171 | |
| 141 | 172 | public static function getUserPermissions($user = null, $formatted = false) |
| 142 | 173 | { |