use of com.instructure.canvasapi2.models.User in project modules.playframework.org by playframework.
the class AllowToVote method isAllowed.
@Override
public boolean isAllowed(String name, String meta, DeadboltHandler deadboltHandler, Http.Context ctx) {
boolean allowed = true;
if (StringUtils.isEmpty(meta)) {
Logger.error("HasVoted required a moduleKey in the meta data");
} else {
User user = (User) deadboltHandler.getRoleHolder(ctx);
if (user != null) {
for (Iterator<Vote> iterator = user.votes.iterator(); allowed && iterator.hasNext(); ) {
Vote vote = iterator.next();
allowed = !meta.equals(vote.playModule.key);
}
}
}
return allowed;
}
use of com.instructure.canvasapi2.models.User in project modules.playframework.org by playframework.
the class UserServices method createUser.
public User createUser(String userName, String displayName, String password, List<UserRole> roles) {
User user = new User();
user.userName = userName;
user.displayName = displayName;
user.password = password;
user.accountActive = true;
user.roles = new ArrayList<UserRole>(roles);
user.rates = new ArrayList<Rate>();
user.save();
user.saveManyToManyAssociations("roles");
return user;
}
use of com.instructure.canvasapi2.models.User in project instructure-android by instructure.
the class ProfileUtilsTest method getUserInitials_string3.
@Test
public void getUserInitials_string3() throws Exception {
User user = new User();
user.setShortName("Billy Bob Thorton");
String testValue = ProfileUtils.getUserInitials(user.getShortName());
assertEquals("B", testValue);
}
use of com.instructure.canvasapi2.models.User in project instructure-android by instructure.
the class ProfileUtilsTest method getUserInitials_string1.
@Test
public void getUserInitials_string1() throws Exception {
User user = new User();
user.setShortName("Billy Bob");
String testValue = ProfileUtils.getUserInitials(user.getShortName());
assertEquals("BB", testValue);
}
use of com.instructure.canvasapi2.models.User in project instructure-android by instructure.
the class BaseParentActivity method handleError.
public void handleError(int code, String error) {
if (code == 418) {
// Parse the message from the response body
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonElement mJson = parser.parse(error);
RevokedTokenResponse revokedTokenResponse = gson.fromJson(mJson, RevokedTokenResponse.class);
showRevokedTokenDialog(revokedTokenResponse, this);
}
if (code == 403) {
// Parse the message from the response body
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonElement mJson = parser.parse(error);
BlockedStudentResponse blockedStudentResponse = gson.fromJson(mJson, BlockedStudentResponse.class);
if (blockedStudentResponse.code.equals("studentBlocked")) {
Prefs prefs = new Prefs(this, getString(R.string.app_name_parent));
String parentId = prefs.load(Const.ID, "");
// We want to refresh cache so the main activity can load quickly with accurate information
UserManager.getStudentsForParentAirwolf(ApiPrefs.getAirwolfDomain(), parentId, new StatusCallback<List<Student>>() {
@Override
public void onResponse(@NonNull Response<List<Student>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (response.body() != null && !response.body().isEmpty()) {
// They have students that they are observing, take them to that activity
startActivity(StudentViewActivity.createIntent(BaseParentActivity.this, response.body()));
overridePendingTransition(0, 0);
finish();
} else {
// Take the parent to the add user page.
FindSchoolActivity.Companion.createIntent(BaseParentActivity.this, true);
finish();
}
}
});
}
}
if (code == 451) {
// Parse the message from the response body
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonElement mJson = parser.parse(error);
MismatchedRegionResponse mismatchedRegionResponse = gson.fromJson(mJson, MismatchedRegionResponse.class);
showMismatchedRegionDialog(mismatchedRegionResponse.getStudentRegion(), this);
}
}
Aggregations