@@ -796,26 +796,47 @@ public function countMyGroups($where =[]) {
796
796
return $ data === false ? 0 : $ data ->Count ;
797
797
}
798
798
799
+
800
+ /**
801
+ * Checks the user's permissions for the specified permission.
802
+ *
803
+ * Returns a boolean value indicating if the action is permitted.
804
+ *
805
+ * @param $userID
806
+ * @param $groupID
807
+ * @param null $categoryID
808
+ * @param null $permissionCategoryID
809
+ * @param null $permissions
810
+ * @param bool $fullMatch If $Permission is an array, $FullMatch indicates if all permissions specified are required.
811
+ * If false, the user only needs one of the specified permissions.
812
+ * @return boolean Returns **true** if the user has permission or **false** otherwise.
813
+ */
799
814
public function checkPermission ($ userID ,$ groupID ,$ categoryID = null , $ permissionCategoryID = null , $ permissions = null , $ fullMatch = true ){
815
+ if ($ userID === Gdn::session ()->UserID ) {
816
+ $ userPermissions = Gdn::session ()->getPermissions ();
817
+ } else {
818
+ $ userPermissions = Gdn::userModel ()->getPermissions ($ userID );
819
+ }
820
+
800
821
// Check access to a category
801
822
$ result = false ;
802
823
if ($ this ->isMemberOfGroup ($ userID ,$ groupID )) {
803
824
if ($ permissions == null ) {
804
825
$ result = true ;
805
826
} else {
806
- $ result = Gdn:: session ()-> checkPermission ($ permissions , $ fullMatch , 'Category ' , $ permissionCategoryID )
807
- || Gdn:: session ()-> checkPermission ($ permissions , $ fullMatch , 'Category ' , $ categoryID );
827
+ $ result = PermissionModel:: checkPermission ($ userPermissions , $ permissions , $ fullMatch , 'Category ' , $ permissionCategoryID )
828
+ || PermissionModel:: checkPermission ($ userPermissions , $ permissions , $ fullMatch , 'Category ' , $ categoryID );
808
829
}
809
830
} else {
810
831
// User is not a group member, checking admin group permissions
811
- if ( GDN :: session ()-> checkPermission ([
832
+ if (PermissionModel:: checkPermission ($ userPermissions , [
812
833
GroupsPlugin::GROUPS_GROUP_ADD_PERMISSION ,
813
834
GroupsPlugin::GROUPS_CATEGORY_MANAGE_PERMISSION ,
814
835
GroupsPlugin::GROUPS_MODERATION_MANAGE_PERMISSION ,
815
836
GroupsPlugin::GROUPS_EMAIL_INVITATIONS_PERMISSION
816
837
], false )) {
817
- $ result = Gdn:: session ()-> checkPermission ($ permissions , $ fullMatch , 'Category ' , $ permissionCategoryID )
818
- || Gdn:: session ()-> checkPermission ($ permissions , $ fullMatch , 'Category ' , $ categoryID ); ;
838
+ $ result = PermissionModel:: checkPermission ($ userPermissions , $ permissions , $ fullMatch , 'Category ' , $ permissionCategoryID ) ||
839
+ PermissionModel:: checkPermission ($ userPermissions , $ permissions , $ fullMatch , 'Category ' , $ categoryID );
819
840
}
820
841
}
821
842
return $ result ;
@@ -837,6 +858,8 @@ public function join($GroupID, $UserID, $watched = true, $followed = true ){
837
858
$ this ->followGroup ($ GroupID , $ UserID , $ followed );
838
859
$ this ->watchGroup ($ GroupID , $ UserID , $ watched );
839
860
self ::clearUserGroupCache ($ UserID );
861
+ $ discussionModel = new DiscussionModel ();
862
+ $ discussionModel ->updateUserDiscussionCount ($ UserID , false );
840
863
}
841
864
842
865
/**
@@ -905,6 +928,8 @@ public function removeMember($GroupID, $MemberID){
905
928
$ this ->unfollowGroup ($ GroupID , $ MemberID );
906
929
$ result = $ this ->SQL ->delete ('UserGroup ' , ['GroupID ' => $ GroupID , 'UserID ' => $ MemberID ]);
907
930
self ::clearUserGroupCache ($ MemberID );
931
+ $ discussionModel = new DiscussionModel ();
932
+ $ discussionModel ->updateUserDiscussionCount ($ MemberID , false );
908
933
return $ result ;
909
934
910
935
}
0 commit comments