String ID to Integer ID

pull/5/head
Felix Prahl-Kamps 2019-07-17 12:41:24 +02:00
parent cd802fbccf
commit fc4efa9787
2 changed files with 39 additions and 29 deletions

View File

@ -130,36 +130,47 @@ public class LoginActivity extends AppCompatActivity {
public void available() { public void available() {
mispRestClient.getRoles(new MispRestClient.AllRolesCallback() { mispRestClient.getRoles(new MispRestClient.AllRolesCallback() {
@Override @Override
public void success(Role[] roles) { public void success(final Role[] roles) {
preferenceManager.setRoles(roles); preferenceManager.setRoles(roles);
}
@Override mispRestClient.getMyUser(new MispRestClient.UserCallback() {
public void failure(String error) {
// TODO what to do if an error occures?
Snackbar.make(constraintLayout, error, Snackbar.LENGTH_LONG).show();
}
});
mispRestClient.getMyUser(new MispRestClient.UserCallback() {
@Override
public void success(final User user) {
preferenceManager.setUserInfo(user);
mispRestClient.getOrganisation(user.org_id, new MispRestClient.OrganisationCallback() {
@Override @Override
public void success(Organisation organisation) { public void success(final User user) {
preferenceManager.setUserOrgInfo(organisation); preferenceManager.setUserInfo(user);
for (Role role: roles) {
if (role.getId().equals(user.role_id)) {
if (!role.getPermAdmin()) {
progressBar.setVisibility(View.GONE);
Snackbar.make(constraintLayout, "You have no admin rights", Snackbar.LENGTH_LONG).show();
return;
}
}
}
// save authkey mispRestClient.getOrganisation(user.org_id, new MispRestClient.OrganisationCallback() {
preferenceManager.setAutomationKey(authkey); @Override
public void success(Organisation organisation) {
preferenceManager.setUserOrgInfo(organisation);
// save url // save authkey
preferenceManager.setServerUrl(url); preferenceManager.setAutomationKey(authkey);
progressBar.setVisibility(View.GONE); // save url
Intent home = new Intent(getApplicationContext(), HomeActivity.class); preferenceManager.setServerUrl(url);
startActivity(home);
finish(); progressBar.setVisibility(View.GONE);
Intent home = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(home);
finish();
}
@Override
public void failure(String error) {
progressBar.setVisibility(View.GONE);
Snackbar.make(constraintLayout, error, Snackbar.LENGTH_LONG).show();
}
});
} }
@Override @Override
@ -181,8 +192,7 @@ public class LoginActivity extends AppCompatActivity {
@Override @Override
public void unavailable(String error) { public void unavailable(String error) {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
Snackbar sb = Snackbar.make(constraintLayout, error, Snackbar.LENGTH_LONG); Snackbar.make(constraintLayout, error, Snackbar.LENGTH_LONG).show();
sb.show();
} }
}); });
} }

View File

@ -4,7 +4,7 @@ import com.google.gson.annotations.SerializedName;
public class Role { public class Role {
@SerializedName("id") @SerializedName("id")
private String id; private Integer id;
@SerializedName("name") @SerializedName("name")
private String name; private String name;
@SerializedName("created") @SerializedName("created")
@ -62,11 +62,11 @@ public class Role {
@SerializedName("permission_description") @SerializedName("permission_description")
private String permissionDescription; private String permissionDescription;
public String getId() { public Integer getId() {
return id; return id;
} }
public void setId(String id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }