@Override /* package */ void validateSave() { synchronized (mutex) { if (this.getObjectId() == null && getName() == null) { throw new IllegalStateException("New roles must specify a name."); } super.validateSave(); } }
/** * Set whether users belonging to the given role are allowed to read this object. The role must * already be saved on the server and its data must have been fetched in order to use this method. * * @param role The role to assign access. * @param allowed Whether the given role can read this object. */ public void setRoleReadAccess(ParseRole role, boolean allowed) { validateRoleState(role); setRoleReadAccess(role.getName(), allowed); }
/** * Set whether users belonging to the given role are allowed to write this object. The role must * already be saved on the server and its data must have been fetched in order to use this method. * * @param role The role to assign access. * @param allowed Whether the given role can write this object. */ public void setRoleWriteAccess(ParseRole role, boolean allowed) { validateRoleState(role); setRoleWriteAccess(role.getName(), allowed); }
/** * Get whether users belonging to the given role are allowed to write this object. Even if this * returns {@code false}, the role may still be able to write it if a parent role has write * access. The role must already be saved on the server and its data must have been fetched in * order to use this method. * * @param role The role to check for access. * @return {@code true} if the role has write access. {@code false} otherwise. */ public boolean getRoleWriteAccess(ParseRole role) { validateRoleState(role); return getRoleWriteAccess(role.getName()); }
/** * Get whether users belonging to the given role are allowed to read this object. Even if this * returns {@code false}, the role may still be able to read it if a parent role has read access. * The role must already be saved on the server and its data must have been fetched in order to * use this method. * * @param role The role to check for access. * @return {@code true} if the role has read access. {@code false} otherwise. */ public boolean getRoleReadAccess(ParseRole role) { validateRoleState(role); return getRoleReadAccess(role.getName()); }
@Test public void testConstructorWithName() { ParseRole role = new ParseRole("Test"); assertEquals("Test", role.getName()); }
@Test public void testSetName() { ParseRole role = new ParseRole(); role.setName("Test"); assertEquals("Test", role.getName()); }
@Test public void testConstructorWithNameAndACL() { ParseACL acl = new ParseACL(); ParseRole role = new ParseRole("Test", acl); assertEquals("Test", role.getName()); assertSame(acl, role.getACL()); }