-
-
Save dazoulay-simplicite/a7033789d8d18d5ec707258a95b7d0df to your computer and use it in GitHub Desktop.
Example of a simplified user object's code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.simplicite.objects.MyModule; | |
import java.util.List; | |
import com.simplicite.util.AppLog; | |
import com.simplicite.util.Globals; | |
import com.simplicite.util.Grant; | |
import com.simplicite.util.ModuleDB; | |
import com.simplicite.util.ObjectField; | |
import com.simplicite.util.View; | |
/** | |
* Simplified user | |
*/ | |
public class MyUser extends com.simplicite.objects.System.SimpleUser { | |
private static final long serialVersionUID = 1L; | |
@Override | |
public void postLoad() { | |
super.postLoad(); | |
final String moduleId = ModuleDB.getModuleId("MyUserModule"); | |
// Hidden language + default | |
ObjectField f = getField("usr_lang"); | |
f.setVisibility(ObjectField.VIS_NOT); | |
f.setDefaultValue(Globals.LANG_ENGLISH); | |
// Hidden home page | |
f = getField("usr_home_id"); | |
f.setVisibility(ObjectField.VIS_NOT); | |
// Hidden menu + default value | |
f = getField("row_module_id"); | |
f.setVisibility(ObjectField.VIS_NOT); | |
f.setDefaultValue(moduleId); | |
// Hidden status | |
getField("usr_active").setVisibility(ObjectField.VIS_NOT); | |
// No sub menu with statuses | |
setMenuStates(false); | |
// Required fields | |
getField("usr_first_name").setRequired(true); | |
getField("usr_last_name").setRequired(true); | |
getField("usr_email").setRequired(true); | |
// Restrict to the users of the module | |
setSearchSpec("t.row_module_id = " + moduleId); | |
} | |
@Override | |
public List<String> preValidate() { | |
// Set active status | |
getField("usr_active").setValue("1"); | |
// Set responsibility and home page depending on a custom "profile" field | |
ObjectField profile = getField("usrMyProfile"); | |
if (profile.hasChanged()) { | |
String group = "MY_GROUP_" + prf.getValue(); | |
String homeId = View.getViewId(group + "_Home"); | |
AppLog.info("Group = " + group + ", home page ID = " + homeId, getGrant()); | |
// Remove old responsibility | |
Grant.removeResponsibility(getRowId(), "MY_GROUP_" + profile.getOldValue()); | |
// Add new responsibility | |
Grant.addResponsibility(getRowId(), group); | |
// Set home page | |
setFieldValue("usr_home_id", homeId); | |
} | |
return super.preValidate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment