use of db.access.RoleAccessPolicy in project common by zenlunatics.
the class EventProvider method _newViewDef.
// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
if (name.equals(m_name)) {
ViewDef view_def = new EventViewDef(m_name, m_support_registrations);
view_def.addFormHook(new FormHook() {
@Override
public void after(View view, View.Mode mode, boolean printer_friendly, Request request) throws IOException {
writeAutomaticReminders(view, request);
}
});
if (m_access_policy != null)
view_def.setAccessPolicy(m_access_policy);
view_def.setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM);
view_def.setFrom(m_events_table);
view_def.setRecordName("Event");
ArrayList<String> column_names_form = new ArrayList<String>();
DBConnection db = new DBConnection(site);
for (int i = 0; i < m_filter_columns.size(); i += 2) {
column_names_form.add(m_filter_columns.get(i));
view_def.setColumn(new Column(m_filter_columns.get(i)).setDefaultValue(m_filter_columns.get(i + 1)).setIsHidden(true));
}
db.close();
column_names_form.add("date");
view_def.setColumn(new Column("date").setDisplayName(m_start_date_label).setIsRequired(true));
if (m_events_have_start_time) {
column_names_form.add("start_time");
column_names_form.add("end_time");
}
if (m_events_have_event) {
column_names_form.add("event");
view_def.setColumn(new Column("event").setIsRequired(true));
}
column_names_form.add("notes");
if (m_events_can_repeat) {
column_names_form.add("repeat");
view_def.setColumn(new Column("repeat").setInputAndValueRenderers(new SelectRenderer(s_repeat_periods).setOnChange("var i=this.selectedIndex;var d=document.querySelector('#date_row input');var ed=document.querySelector('#end_date_row input');if(i==0)ed.value='';else if(i==1){if(ed.value=='')ed.value=d.value;}else if(ed.value==d.value)ed.value='';$('end_date_row').style.display=i==0?'none':null;return false"), true));
column_names_form.add("end_date");
view_def.setColumn(new Column("end_date").setDisplayName(m_end_date_label));
}
if (m_events_have_category) {
column_names_form.add(m_events_table + "_categories_id");
m_categories.setAllowEditing(!m_only_admins_can_edit_categories);
view_def.setColumn(m_categories.newColumn(m_events_table + "_categories_id").setDisplayName("category"));
}
if (m_events_have_location) {
String locations_table = getLocationsTable();
column_names_form.add(locations_table + "_id");
m_locations.setAllowEditing(!m_only_admins_can_edit_locations);
view_def.setColumn(m_locations.newColumn(locations_table + "_id").setDisplayName("location"));
}
if (m_events_have_color) {
column_names_form.add("color");
view_def.setColumn(new ColorColumn("color"));
}
if (m_support_reminders)
view_def.addRelationshipDef(new OneToMany(m_name + "_reminders").setSpanFormCols(false));
if (m_support_registrations) {
column_names_form.add("register_people");
view_def.setColumn(new Column("register_people").setDisplayName("allow people to register for this " + getEventCrumb()));
}
if (m_events_are_owned) {
if (m_access_policy == null)
view_def.setAccessPolicy(new Or(new RecordOwnerAccessPolicy().add().delete().edit(), new RoleAccessPolicy("calendar editor")));
column_names_form.add("_owner_");
LookupColumn owner_column = new PersonColumn("_owner_", false, site.getPeopleFilter()).setDefaultToUserId().setDisplayName("posted by");
if (m_role == null)
owner_column.setIsReadOnly(true);
view_def.setColumn(owner_column);
}
column_names_form.add("_timestamp_");
view_def.setColumn(new Column("_timestamp_").setDisplayName("added").setIsReadOnly(true).setShowOnAddForm(false));
view_def.setColumnNamesForm(column_names_form.toArray(new String[column_names_form.size()]));
return view_def;
}
if (name.equals(getCategoriesTable()))
return m_categories.addHooks(new ViewDef(name).setColumn(new ColorColumn("color")));
if (name.equals(getLocationsTable()))
return m_locations.newViewDef(name, site).setDefaultOrderBy("lower(text)").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM).setRecordName("Location").setColumn(new Column("text").setDisplayName("location").setIsRequired(true));
if (name.equals(m_name + "_registrations"))
return new ViewDef(name).setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM).setFrom(m_events_table + "_registrations").setRecordName("Registration").setColumnNamesTableAndForm(new String[] { "person", "note" }).setColumn(new LookupColumn("person", "people", "first,last").setDefaultToUserId().setFilter(site.getPeopleFilter()));
if (name.equals(m_name + "_reminders")) {
RecordOwnerAccessPolicy access_policy = (RecordOwnerAccessPolicy) new RecordOwnerAccessPolicy().add().delete().edit();
return new ViewDef(name).setAccessPolicy(access_policy).setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM).setFrom(m_events_table + "_reminders").setRecordName("Reminder").setColumnNamesForm(new String[] { "before", "note", "email" }).setColumnNamesTable(new String[] { "email", "before" }).setColumn(new EmailColumn("email") {
@Override
public String getDefaultValue(Request request) {
return request.getUser().getEmail();
}
@Override
public String validate(String table, String value, int id, Request request) {
if ("poster".equals(value))
return null;
return super.validate(table, value, id, request);
}
}.setDisplayName("send to").setIsRequired(true)).setColumn(new ReminderWhenColumn("before", m_name, m_events_table, m_events_have_start_time, m_events_can_repeat, false).setDisplayName("when")).setColumn(access_policy.getColumn("person", site));
}
if (name.equals(m_name + "_reminders auto"))
return new ViewDef(name).setBaseFilter(m_events_table + "_id IS NULL").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM).setFrom(m_events_table + "_reminders").setRecordName("Reminder").setColumnNamesForm(new String[] { "before", "note", "email" }).setColumnNamesTable(new String[] { "email", "before" }).setColumn(new EmailColumn("email") {
@Override
public String validate(String table, String value, int id, Request request) {
if ("poster".equals(value))
return null;
return super.validate(table, value, id, request);
}
}.setDisplayName("send to").setIsRequired(true).setTitle("Enter the special value \"poster\" to send to the event poster")).setColumn(new ReminderWhenColumn("before", m_name, m_events_table, m_events_have_start_time, m_events_can_repeat, true).setDisplayName("when"));
return null;
}
use of db.access.RoleAccessPolicy in project common by zenlunatics.
the class Documents method _newViewDef.
// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
if (name.equals("documents")) {
ViewDef view_def = new ViewDef(name);
view_def.setAccessPolicy(new RoleAccessPolicy("docs").add().delete().edit());
view_def.setCenter(false);
view_def.setDefaultOrderBy("title");
view_def.setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM);
view_def.setRecordName("Document");
view_def.setRichTextEditId("db_filename_text");
view_def.setShowDoneLink(true);
view_def.setTimestampRecords(true);
ArrayList<String> column_names = new ArrayList<String>();
column_names.add("title");
column_names.add("type");
column_names.add("filename");
if (m_extra_columns != null)
for (JDBCColumn column : m_extra_columns) column_names.add(column.name);
view_def.setColumnNamesForm(column_names.toArray(new String[column_names.size()]));
view_def.setColumnNamesTable(new String[] { "filename" });
FileColumn file_column = new FileColumn("filename", view_def, "documents").setTitleColumn("title");
if (m_dir_column != null)
file_column.setDirColumn(m_dir_column);
view_def.setColumn(file_column.setDisplayName("document").setPrintUrl("/Documents?db_key_value="));
view_def.setColumn(new Column("title").setIsRequired(true).setOrderBy("lower(title)"));
view_def.setColumn(((Options) site.getObjects("documents_types")).newColumn("type"));
return addHooks(view_def);
}
if (name.equals("documents_types"))
return site.getObjects(name).newViewDef(name, site).setRecordName("Type").setShowNumRecords(false).setColumn(new Column("text").setIsRequired(true));
return null;
}
use of db.access.RoleAccessPolicy in project common by zenlunatics.
the class MailLists method _newViewDef.
// --------------------------------------------------------------------------
// @AdminTask
// public static void
// moveAllMessagesToDisk(Request request)
// {
// try {
// List<String> lists = request.db.readValues(new Select("name").from("mail_lists").where("NOT store_on_disk"));
// for (String list : lists) {
// request.writer.write("writing " + list + "<br />");
// System.out.println("writing " + list);
// new MailList(list, request.site, request.db).moveMessagesToDisk(request);
// }
// } catch (IOException e) {
// request.abort(e);
// }
// }
// --------------------------------------------------------------------------
// @AdminTask({"list name"})
// public static void
// moveMessagesToDisk(String list_name, Request request)
// {
// try {
// new MailList(list_name, request.site, request.db).moveMessagesToDisk(request);
// } catch (IOException e) {
// request.abort(e);
// }
// }
// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
if (name.equals("additional_emails"))
return new ViewDef(name).setDefaultOrderBy("email").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM).setRecordName("Additional email");
if (name.equals("mail_lists"))
return new ViewDef(name) {
@Override
public boolean beforeUpdate(int id, NameValuePairs name_value_pairs, Map<String, Object> previous_values, Request request) {
if (!name_value_pairs.getBoolean("active") && request.db.lookupBoolean(new Select("active").from("mail_lists").whereIdEquals(id)))
request.db.delete("mail_lists_people", "mail_lists_id=" + id);
return super.beforeUpdate(id, name_value_pairs, previous_values, request);
}
}.addDeleteHook(this).addInsertHook(this).addUpdateHook(this).setDefaultOrderBy("name").setRecordName("Mail List").setColumnNamesForm(new String[] { "name", "send_to", "active", "announce_only", "archive", "archives_public", "footer", "allow_from_outside", "allow_from_outside_subscribers", "subscribers", "username", "host", "password", "store_on_disk" }).setColumnNamesFormTable(new String[] { "name" }).setColumnNamesTable(new String[] { "name", "send_to", "active" }).setColumn(new Column("allow_from_outside").setDisplayName("accept posts from outside non-subscribers (i.e. anyone)")).setColumn(new Column("allow_from_outside_subscribers").setDisplayName("accept posts from outside subscribers")).setColumn(new Column("announce_only").setTitle("If this is checked, replies to posts from this list will be ignored.")).setColumn(new Column("footer").setTitle("Optional text that will be added to the bottom of every post to this list")).setColumn(new Column("host").setIsHidden(true)).setColumn(new Column("name").setPostText("@" + site.getDomain()).setDisplayName("address").setIsRequired(true)).setColumn(new Column("password").setDefaultToUUID().setIsHidden(true)).setColumn(new Column("send_to") {
@Override
protected void writeInput(Mode mode, String default_value, View view, Form form, Request request) throws IOException {
String value = null;
if (mode == Mode.EDIT_FORM)
value = view.data().getString("send_to");
HTMLWriter writer = request.writer;
writer.write("<select name=\"send_to\"><option value=\"Subscribers\">Subscribers</options>");
for (MailHandlerFactory mail_handler_factory : m_mail_handler_factories) mail_handler_factory.writeSendToOptions(value, request.db, writer);
writer.write("</select>");
}
@Override
public boolean writeValue(View view, Map<String, Object> data, Request request) throws IOException {
String send_to = view.data().getString("send_to");
if ("Subscribers".equals(send_to))
request.writer.write(send_to);
else {
MailHandler mail_handler = getMailHandler(view.data().getString("name"), request.db);
if (mail_handler != null)
request.writer.write(mail_handler.getDisplayName());
}
return true;
}
}).setColumn(new Column("store_on_disk").setIsHidden(true)).setColumn(new Column("username").setIsHidden(true)).addRelationshipDef(new ManyToMany("people", "mail_lists_people", "first,last").setViewRole("administrator")).addRelationshipDef(new OneToMany("subscribers").setSpanFormCols(false));
if (name.equals("mail_lists_people"))
return new ViewDef(name).setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM).setColumn(new LookupColumn("mail_lists_id", "mail_lists", "name", new Select("id,name,send_to,active").from("mail_lists").orderBy("name"), "name").setFilter(new Filter() {
@Override
public boolean accept(ResultSet rs, Request request) {
try {
return rs.getBoolean("active") && "Subscribers".equals(rs.getString("send_to"));
} catch (SQLException e) {
request.abort(e);
}
return false;
}
}).setDisplayName("mail list")).setColumn(new LookupColumn("people_id", "people", "first,last").setFilter(site.getPeopleFilter()));
if (name.startsWith("ml_"))
return new ViewDef(name).setAccessPolicy(new RoleAccessPolicy("admin").delete()).setDefaultOrderBy("arrived DESC").setRecordName("Message").setRowWindowSize(0).setShowFilterLink(false).setShowHead(false).setColumnNamesTable(new String[] { "arrived", "sender", "subject" }).setColumn(new Column("subject") {
@Override
public boolean writeValue(View view, Map<String, Object> data, Request request) throws IOException {
String subject = view.data().getString("subject");
if (subject == null || subject.length() == 0)
subject = "(no subject)";
request.writer.aOnClick(subject, "new Dialog({url:context+'/MailLists?list=" + view.getViewDef().getName() + "&cmd=get_message&db_key_value=" + view.data().getString("id") + "',title:'" + HTMLWriter.escapeJSString(subject) + "'});");
return true;
}
});
if (name.equals("people mail_lists"))
return new ViewDef(name).setAccessPolicy(new AccessPolicy().add().delete()).setAddButtonText("subscribe").setDeleteButtonText("unsubscribe").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM).setFrom("mail_lists").setRecordName("Mail List").setColumnNamesTable(new String[] { "name" });
if (name.equals("subscribers"))
return new ViewDef(name).setDefaultOrderBy("email").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM).setRecordName("Outside Subscriber");
return null;
}
use of db.access.RoleAccessPolicy in project common by zenlunatics.
the class EventProvider method adjustTables.
// --------------------------------------------------------------------------
protected void adjustTables(DBConnection db) {
if (m_events_table != null) {
JDBCTable table_def = new JDBCTable().add(new JDBCColumn("date", Types.DATE)).add(new JDBCColumn("notes", Types.VARCHAR)).add(new JDBCColumn("uuid", Types.VARCHAR));
if (m_events_are_owned)
table_def.add(new JDBCColumn("_owner_", "people").setOnDeleteSetNull(true));
if (m_events_can_repeat) {
table_def.add(new JDBCColumn("repeat", Types.VARCHAR));
table_def.add(new JDBCColumn("end_date", Types.DATE));
}
if (m_events_have_category) {
String categories_table = m_events_table + "_categories";
table_def.add(new JDBCColumn(categories_table).setOnDeleteSetNull(true));
JDBCTable table_def2 = new JDBCTable().add(new JDBCColumn("text", Types.VARCHAR)).add(new JDBCColumn("color", Types.VARCHAR));
if (db.tableExists(categories_table))
db.getTable(categories_table).createMissingColumns(table_def2, db).dropExtraColumns(table_def2, db);
else
db.createTable(categories_table, "text VARCHAR,color VARCHAR");
m_categories = (Options) m_site.getObjects(categories_table);
if (m_categories == null) {
m_categories = new Options(new Select("*").from(categories_table).orderBy("lower(text)"), true, m_site).setAllowEditing(true);
m_categories.setObjectClass(Category.class);
m_site.addObjects(m_categories);
}
}
if (m_events_have_color)
table_def.add(new JDBCColumn("color", Types.VARCHAR));
if (m_events_have_event)
table_def.add(new JDBCColumn("event", Types.VARCHAR));
if (m_events_have_location) {
String locations_table = getLocationsTable();
table_def.add(new JDBCColumn(locations_table).setOnDeleteSetNull(true));
db.createTable(locations_table, "text VARCHAR");
m_locations = (Options) m_site.getObjects(locations_table);
if (m_locations == null) {
m_locations = new Options(new Select("*").from(locations_table).orderBy("lower(text)"), true, m_site).setAllowEditing(true);
m_site.addObjects(m_locations);
}
}
if (m_events_have_start_time) {
table_def.add(new JDBCColumn("start_time", Types.TIME));
table_def.add(new JDBCColumn("end_time", Types.TIME));
}
if (m_one_table != null)
table_def.add(new JDBCColumn(m_one_table));
if (m_support_registrations)
table_def.add(new JDBCColumn("register_people", Types.BOOLEAN));
table_def.add(new JDBCColumn("_timestamp_", Types.TIMESTAMP));
for (JDBCColumn column : m_additional_columns) table_def.add(column);
db.getTable(m_events_table, true).matchColumns(table_def, db);
db.createIndex(m_events_table, "date");
if (m_support_registrations) {
table_def = new JDBCTable().add(new JDBCColumn(m_events_table)).add(new JDBCColumn("person", Types.INTEGER)).add(new JDBCColumn("note", Types.VARCHAR));
db.getTable(m_events_table + "_registrations", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
}
adjustRemindersTables(db);
}
if (m_role != null) {
Roles.add(m_role, m_site, db);
setAccessPolicy(new RoleAccessPolicy(m_role).add().delete().edit());
} else
setAccessPolicy(null);
}
Aggregations