Search in sources :

Example 16 with User

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;
}
Also used : Vote(models.Vote) User(models.User)

Example 17 with User

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;
}
Also used : User(models.User) UserRole(models.UserRole) Rate(models.Rate)

Example 18 with 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);
}
Also used : User(com.instructure.canvasapi2.models.User) Test(org.junit.Test)

Example 19 with User

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);
}
Also used : User(com.instructure.canvasapi2.models.User) Test(org.junit.Test)

Example 20 with User

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);
    }
}
Also used : BlockedStudentResponse(com.instructure.canvasapi2.models.BlockedStudentResponse) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Gson(com.google.gson.Gson) Prefs(com.instructure.pandautils.utils.Prefs) ApiPrefs(com.instructure.canvasapi2.utils.ApiPrefs) MismatchedRegionResponse(com.instructure.canvasapi2.models.MismatchedRegionResponse) RevokedTokenResponse(com.instructure.canvasapi2.models.RevokedTokenResponse) JsonElement(com.google.gson.JsonElement) ApiType(com.instructure.canvasapi2.utils.ApiType) List(java.util.List) JsonParser(com.google.gson.JsonParser)

Aggregations

User (models.User)30 User (com.instructure.canvasapi2.models.User)25 RestParams (com.instructure.canvasapi2.builders.RestParams)22 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)19 Test (org.junit.Test)16 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)8 CurrentUser (actions.CurrentUser)7 CurrentUser.currentUser (actions.CurrentUser.currentUser)7 NonNull (android.support.annotation.NonNull)7 View (android.view.View)7 List (java.util.List)7 Result (play.mvc.Result)7 ApiType (com.instructure.canvasapi2.utils.ApiType)6 ArrayList (java.util.ArrayList)6 Module (models.Module)6 UnitTest (play.test.UnitTest)6 Intent (android.content.Intent)5 RoleHolderPresent (be.objectify.deadbolt.actions.RoleHolderPresent)5 StatusCallback (com.instructure.canvasapi2.StatusCallback)5 Course (com.instructure.canvasapi2.models.Course)5