Created a function to know if a user can delete a post or not.

This commit is contained in:
Pierre 2018-03-25 17:03:00 +02:00
parent 54bb812e5c
commit a4e8ada1c7
2 changed files with 11 additions and 2 deletions

View File

@ -108,6 +108,16 @@ public class Post {
return user_access_level; return user_access_level;
} }
/**
* Check whether the user can delete the post or not
*
* @return TRUE if the post can be deleted by the user / FALSE else
*/
public boolean canDelete(){
return getUser_access_level() == PostUserAccess.INTERMEDIATE_ACCESS ||
getUser_access_level() == PostUserAccess.FULL_ACCESS;
}
//Set and get file path url //Set and get file path url
void setFile_path_url(String file_path_url) { void setFile_path_url(String file_path_url) {
this.file_path_url = file_path_url; this.file_path_url = file_path_url;

View File

@ -278,8 +278,7 @@ public class PostsListFragment extends Fragment
mNumCurrPostInContextMenu = pos; mNumCurrPostInContextMenu = pos;
//Disable some options if the user is not the post owner //Disable some options if the user is not the post owner
if(post.getUser_access_level() != PostUserAccess.INTERMEDIATE_ACCESS && if(!post.canDelete()){
post.getUser_access_level() != PostUserAccess.FULL_ACCESS){
//Disable delete action //Disable delete action
menu.findItem(R.id.action_delete).setEnabled(false); menu.findItem(R.id.action_delete).setEnabled(false);