PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.5.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.5.0
2.5.0 2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 All 34 releases
← All changes | app/Services/PermissionManager.php +64 -10 1.5.22 → 2.5.0 View file →
@@ -1,10 +1,11 @@
1 1 <?php
2 2
3 3 namespace FluentBooking\App\Services;
4 4
5 +use FluentBooking\App\Models\Meta;
5 6 use FluentBooking\App\Models\Calendar;
6 -use FluentBooking\App\Models\Meta;
7 +use FluentBooking\App\Models\CalendarSlot;
7 8 use FluentBooking\Framework\Support\Arr;
8 9
9 10 class PermissionManager
10 11 {
@@ -16,20 +17,21 @@
16 17 'manage_all_bookings' => __('Read & Write Access to All Bookings', 'fluent-booking'),
17 18 'read_other_calendars' => __('Read Access of Other Users Calendars', 'fluent-booking'),
18 19 'manage_other_calendars' => __('Manage Other Users Calendars', 'fluent-booking'),
19 20 'read_and_use_other_availabilities' => __('Read & Use Access of All Availabilities', 'fluent-booking'),
20 - 'manage_other_availabilities' => __('Manage All Availabilities', 'fluent-booking')
21 + 'manage_other_availabilities' => __('Manage All Availabilities', 'fluent-booking'),
22 + 'manage_all_data' => __('Manage All Data and Settings', 'fluent-booking')
21 23 ];
22 24 }
23 25
24 26 public static function hasAllCalendarAccess($readAccess = false)
25 27 {
26 - $hasCalendarAccess = self::userCan('manage_other_calendars');
28 + $hasCalendarAccess = self::userCan(['manage_all_data', 'manage_other_calendars']);
27 29
28 30 if ($readAccess) {
29 31 $hasCalendarAccess = $hasCalendarAccess || self::userCan('read_other_calendars');
30 32 }
31 -
33 +
32 34 return apply_filters('fluent_booking/has_all_calendar_access', current_user_can('manage_options')) || $hasCalendarAccess;
33 35 }
34 36
35 37 public static function canReadCalendar($calendarId)
@@ -47,10 +49,32 @@
47 49 if ($calendar->user_id == get_current_user_id()) {
48 50 return true;
49 51 }
50 52
53 + if (CalendarService::isSharedCalendar($calendar)) {
54 + return true;
55 + }
56 +
57 + return self::userCan(['manage_all_data', 'read_other_calendars', 'manage_other_calendars']);
58 + }
51 59
52 - return self::userCan(['read_other_calendars', 'manage_other_calendars']);
60 + public static function canUpdateCalendarEvent($slotId)
61 + {
62 + $calendarSlot = CalendarSlot::find($slotId);
63 +
64 + if (!$calendarSlot) {
65 + return false;
66 + }
67 +
68 + $userId = get_current_user_id();
69 +
70 + $teamMembers = Arr::get($calendarSlot, 'settings.team_members', []);
71 +
72 + if ($calendarSlot->user_id == $userId || in_array($userId, $teamMembers)) {
73 + return true;
74 + }
75 +
76 + return self::userCan(['manage_all_data', 'manage_other_calendars']);
53 77 }
54 78
55 79 public static function canWriteCalendar($calendarId)
56 80 {
@@ -67,19 +91,40 @@
67 91 if ($calendar->user_id == get_current_user_id()) {
68 92 return true;
69 93 }
70 94
71 - return self::userCan('manage_other_calendars');
95 + return self::userCan(['manage_all_data', 'manage_other_calendars']);
72 96 }
73 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 +
74 119 public static function hasCalendarAccess($calendar)
75 120 {
76 - $hasAccess = current_user_can('manage_options') || $calendar->user_id == get_current_user_id();
121 + $hasAccess = self::userCan('manage_all_data') || $calendar->user_id == get_current_user_id();
77 122
78 123 return apply_filters('fluent_booking/has_calendar_access', $hasAccess, $calendar);
79 124 }
80 125
81 - public static function currentUserHasAnyPemrmission()
126 + public static function currentUserHasAnyPermission()
82 127 {
83 128 if (current_user_can('manage_options')) {
84 129 return true;
85 130 }
@@ -113,8 +158,18 @@
113 158
114 159 return false;
115 160 }
116 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']);
170 + }
171 +
117 172 public static function getUserPermissions($user = null, $formatted = false)
118 173 {
119 174 if ($user === null) {
120 175 $user = wp_get_current_user();
@@ -178,9 +233,8 @@
178 233 }
179 234
180 235 public static function getMetaPermissions($userId = null)
181 236 {
182 -
183 237 if ($userId === null) {
184 238 $userId = get_current_user_id();
185 239 }
186 240
@@ -231,7 +285,7 @@
231 285 }
232 286
233 287 public static function userCanSeeAllBookings()
234 288 {
235 - return self::userCan(['read_all_bookings', 'manage_all_bookings']);
289 + return self::userCan(['manage_all_data', 'read_all_bookings', 'manage_all_bookings']);
236 290 }
237 291 }