Commit 833f19e2 authored by Varun Patil's avatar Varun Patil

Show edit event only when has permission

parent 8f766bc1
...@@ -29,6 +29,7 @@ import com.squareup.picasso.Picasso; ...@@ -29,6 +29,7 @@ import com.squareup.picasso.Picasso;
import app.insti.api.UnsafeOkHttpClient; import app.insti.api.UnsafeOkHttpClient;
import app.insti.data.Body; import app.insti.data.Body;
import app.insti.data.Event; import app.insti.data.Event;
import app.insti.data.Role;
import app.insti.data.User; import app.insti.data.User;
import app.insti.fragment.BackHandledFragment; import app.insti.fragment.BackHandledFragment;
import app.insti.fragment.BodyFragment; import app.insti.fragment.BodyFragment;
...@@ -374,6 +375,23 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -374,6 +375,23 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
return true; return true;
} }
public boolean editEventAccess(Event event) {
if (currentUser == null || currentUser.getUserRoles() == null || currentUser.getUserRoles().size() == 0)
return false;
for (Role role : currentUser.getUserRoles()) {
for (Body body : role.getRoleBodies()) {
for (Body eventBody : event.getEventBodies()) {
if (body.getBodyID().equals(eventBody.getBodyID())) {
return true;
}
}
}
}
return false;
}
public static void hideKeyboard(Activity activity) { public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it. //Find the currently focused view, so we can grab the correct window token from it.
......
...@@ -231,7 +231,11 @@ public class EventFragment extends BackHandledFragment { ...@@ -231,7 +231,11 @@ public class EventFragment extends BackHandledFragment {
mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime); mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
FloatingActionButton fab = (FloatingActionButton) getView().findViewById(R.id.edit_fab); FloatingActionButton fab = (FloatingActionButton) getView().findViewById(R.id.edit_fab);
if (((MainActivity) getActivity()).editEventAccess(event)) {
fab.setVisibility(View.VISIBLE); fab.setVisibility(View.VISIBLE);
}
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment