added Members and Unjoin functionality, setting of public/private/invitation-
only for communities
This commit is contained in:
@@ -614,4 +614,14 @@ class GroupObject implements DynamoGroup
|
||||
|
||||
} // end getMemberCount
|
||||
|
||||
public List getMembers(int offset, int count) throws DatabaseException
|
||||
{
|
||||
int[] ids = m_ops.getMembers(m_gid,offset,count);
|
||||
ArrayList rc = new ArrayList(ids.length);
|
||||
for (int i=0; i<ids.length; i++)
|
||||
rc.add(m_upm.getUserProxy(ids[i]));
|
||||
return Collections.unmodifiableList(rc);
|
||||
|
||||
} // end getMembers
|
||||
|
||||
} // end class GroupObject
|
||||
|
||||
@@ -58,6 +58,8 @@ abstract class GroupObjectOps extends OpsBase
|
||||
|
||||
abstract int[] getMembers(int gid) throws DatabaseException;
|
||||
|
||||
abstract int[] getMembers(int gid, int offset, int count) throws DatabaseException;
|
||||
|
||||
abstract void setAclID(int gid, int aclid) throws DatabaseException;
|
||||
|
||||
abstract int getMemberCount(int gid) throws DatabaseException;
|
||||
|
||||
@@ -517,6 +517,52 @@ class GroupObjectOps_mysql extends GroupObjectOps
|
||||
|
||||
} // end getMembers
|
||||
|
||||
int[] getMembers(int gid, int offset, int count) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
int[] tmp = new int[count+1];
|
||||
int level = 0;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// create the statement that does the lookup
|
||||
stmt = conn.prepareStatement("SELECT u.uid FROM users u, groupmembers g WHERE u.uid = g.uid AND g.gid = ? "
|
||||
+ "ORDER BY u.username LIMIT ?, ?;");
|
||||
stmt.setInt(1,gid);
|
||||
stmt.setInt(2,offset);
|
||||
stmt.setInt(3,count+1);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
// fill the temporary array
|
||||
while (rs.next())
|
||||
tmp[level++] = rs.getInt(1);
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
// set up the return value
|
||||
if (level==tmp.length)
|
||||
return tmp;
|
||||
int[] rc = new int[level];
|
||||
System.arraycopy(tmp,0,rc,0,level);
|
||||
return rc;
|
||||
|
||||
} // end getMembers
|
||||
|
||||
void setAclID(int gid, int aclid) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
|
||||
@@ -241,6 +241,12 @@ abstract class GroupProxy implements DynamoGroup, DynamicWrapper
|
||||
|
||||
} // end getMemberCount
|
||||
|
||||
public List getMembers(int offset, int count) throws DatabaseException
|
||||
{
|
||||
return getRealGroup().getMembers(offset,count);
|
||||
|
||||
} // end getMembers
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface DynamicWrapper
|
||||
*--------------------------------------------------------------------------------
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
@@ -20,6 +20,7 @@ package com.silverwrist.dynamo.iface;
|
||||
import java.security.Principal;
|
||||
import java.security.acl.AclNotFoundException;
|
||||
import java.security.acl.Group;
|
||||
import java.util.List;
|
||||
import com.silverwrist.dynamo.except.DatabaseException;
|
||||
import com.silverwrist.dynamo.except.DynamoSecurityException;
|
||||
|
||||
@@ -47,4 +48,6 @@ public interface DynamoGroup extends Group, NamedObject, SecureObjectStore
|
||||
|
||||
public int getMemberCount() throws DatabaseException;
|
||||
|
||||
public List getMembers(int offset, int count) throws DatabaseException;
|
||||
|
||||
} // end interface DynamoGroup
|
||||
|
||||
@@ -95,6 +95,12 @@ public class LibraryCast
|
||||
|
||||
} // end newIntArray
|
||||
|
||||
public final AuthenticatorLookup queryAuthenticatorLookup(Object obj)
|
||||
{
|
||||
return (AuthenticatorLookup)query(obj,AuthenticatorLookup.class);
|
||||
|
||||
} // end queryAuthenticatorLookup
|
||||
|
||||
public final ChainParameterInput queryChainParameterInput(Object obj)
|
||||
{
|
||||
return (ChainParameterInput)query(obj,ChainParameterInput.class);
|
||||
|
||||
@@ -73,4 +73,7 @@ public interface VeniceNamespaces
|
||||
public static final String COMMUNITY_NAMESPACE =
|
||||
"http://www.silverwrist.com/NS/venice/2003/06/15/community";
|
||||
|
||||
public static final String COMMUNITY_SECURITY_NAMESPACE =
|
||||
"http://www.silverwrist.com/NS/venice/2003/06/18/community.security";
|
||||
|
||||
} // end interface VeniceNamespaces
|
||||
|
||||
@@ -275,4 +275,46 @@ public class AdvancedUserManager implements NamedObject, ComponentInitialize, Co
|
||||
|
||||
} // end getSearchUserCount
|
||||
|
||||
public List searchForMembers(DynamoUser caller, DynamoGroup group, UserSearchField field, SearchMode mode,
|
||||
String term, int offset, int count) throws DatabaseException
|
||||
{
|
||||
int[] rc = null;
|
||||
String prop = null;
|
||||
if (UserSearchField.USERNAME.equals(field))
|
||||
rc = m_ops.searchName(group.getGID(),mode,term,offset,count);
|
||||
else if (UserSearchField.DESCRIPTION.equals(field))
|
||||
prop = "description";
|
||||
else if (UserSearchField.FIRSTNAME.equals(field))
|
||||
prop = "name.given";
|
||||
else if (UserSearchField.LASTNAME.equals(field))
|
||||
prop = "name.family";
|
||||
else
|
||||
throw new IllegalArgumentException("invalid search field (shouldn't happen)");
|
||||
if ((rc==null) && (prop!=null))
|
||||
rc = m_ops.searchProperty(group.getGID(),m_ns_cache.namespaceNameToId(VeniceNamespaces.USER_PROFILE_NAMESPACE),
|
||||
prop,mode,term,offset,count);
|
||||
return translateUIDArray(rc);
|
||||
|
||||
} // end searchForMembers
|
||||
|
||||
public int getSearchMemberCount(DynamoUser caller, DynamoGroup group, UserSearchField field, SearchMode mode,
|
||||
String term) throws DatabaseException
|
||||
{
|
||||
String prop = null;
|
||||
if (UserSearchField.USERNAME.equals(field))
|
||||
return m_ops.searchNameCount(group.getGID(),mode,term);
|
||||
else if (UserSearchField.DESCRIPTION.equals(field))
|
||||
prop = "description";
|
||||
else if (UserSearchField.FIRSTNAME.equals(field))
|
||||
prop = "name.given";
|
||||
else if (UserSearchField.LASTNAME.equals(field))
|
||||
prop = "name.family";
|
||||
else
|
||||
throw new IllegalArgumentException("invalid search field (shouldn't happen)");
|
||||
return m_ops.searchPropertyCount(group.getGID(),
|
||||
m_ns_cache.namespaceNameToId(VeniceNamespaces.USER_PROFILE_NAMESPACE),
|
||||
prop,mode,term);
|
||||
|
||||
} // end getSearchMemberCount
|
||||
|
||||
} // end class AdvancedUserManager
|
||||
|
||||
@@ -43,12 +43,23 @@ abstract class AdvancedUserOps extends OpsBase
|
||||
abstract int[] searchProperty(int nsid, String name, SearchMode mode, String term, int offset, int count)
|
||||
throws DatabaseException;
|
||||
|
||||
abstract int[] searchProperty(int member_gid, int nsid, String name, SearchMode mode, String term, int offset,
|
||||
int count) throws DatabaseException;
|
||||
|
||||
abstract int searchPropertyCount(int nsid, String name, SearchMode mode, String term) throws DatabaseException;
|
||||
|
||||
abstract int searchPropertyCount(int member_gid, int nsid, String name, SearchMode mode, String term)
|
||||
throws DatabaseException;
|
||||
|
||||
abstract int[] searchName(SearchMode mode, String term, int offset, int count) throws DatabaseException;
|
||||
|
||||
abstract int[] searchName(int member_gid, SearchMode mode, String term, int offset, int count)
|
||||
throws DatabaseException;
|
||||
|
||||
abstract int searchNameCount(SearchMode mode, String term) throws DatabaseException;
|
||||
|
||||
abstract int searchNameCount(int member_gid, SearchMode mode, String term) throws DatabaseException;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static operations
|
||||
*--------------------------------------------------------------------------------
|
||||
|
||||
@@ -116,6 +116,58 @@ public class AdvancedUserOps_mysql extends AdvancedUserOps
|
||||
tmp[ct++] = rs.getInt(1);
|
||||
|
||||
// Create the actual return array and fill it.
|
||||
if (ct==tmp.length)
|
||||
return tmp;
|
||||
int[] rc = new int[ct];
|
||||
System.arraycopy(tmp,0,rc,0,ct);
|
||||
return rc;
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end searchProperty
|
||||
|
||||
int[] searchProperty(int member_gid, int nsid, String name, SearchMode mode, String term, int offset,
|
||||
int count) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// prepare and execute a query (note that we assemble it in SQL form)
|
||||
StringBuffer sql = new StringBuffer("SELECT u.uid FROM users u, userprop p, groupmembers g WHERE u.uid = p.uid "
|
||||
+ "AND u.is_anon = 0 AND u.uid = g.uid AND g.gid = ");
|
||||
sql.append(member_gid).append(" AND p.nsid = ").append(nsid).append(" AND p.prop_name = '");
|
||||
sql.append(m_utils.encodeString(name)).append("' AND p.prop_value ");
|
||||
sql.append(preparePropertySearchTerm(mode,term));
|
||||
sql.append(" ORDER BY u.name LIMIT ").append(offset).append(", ").append(count+1).append(';');
|
||||
stmt = conn.createStatement();
|
||||
rs = stmt.executeQuery(sql.toString());
|
||||
|
||||
// We *know* the maximum number of indexes that can be returned, so allocate a temporary array big
|
||||
// enough to hold them all.
|
||||
int[] tmp = new int[count+1];
|
||||
int ct = 0;
|
||||
while (rs.next())
|
||||
tmp[ct++] = rs.getInt(1);
|
||||
|
||||
// Create the actual return array and fill it.
|
||||
if (ct==tmp.length)
|
||||
return tmp;
|
||||
int[] rc = new int[ct];
|
||||
System.arraycopy(tmp,0,rc,0,ct);
|
||||
return rc;
|
||||
@@ -171,6 +223,41 @@ public class AdvancedUserOps_mysql extends AdvancedUserOps
|
||||
|
||||
} // end searchPropertyCount
|
||||
|
||||
int searchPropertyCount(int member_gid, int nsid, String name, SearchMode mode, String term) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// prepare and execute a query (note that we assemble it in SQL form)
|
||||
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM users u, userprop p, groupmembers g "
|
||||
+ "WHERE u.uid = p.uid AND u.is_anon = 0 AND u.uid = g.uid AND g.gid = ");
|
||||
sql.append(member_gid).append(" AND p.nsid = ").append(nsid).append(" AND p.prop_name = '");
|
||||
sql.append(m_utils.encodeString(name)).append("' AND p.prop_value ");
|
||||
sql.append(preparePropertySearchTerm(mode,term)).append(';');
|
||||
stmt = conn.createStatement();
|
||||
rs = stmt.executeQuery(sql.toString());
|
||||
return SQLUtils.getReturnCountInt(rs,1);
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end searchPropertyCount
|
||||
|
||||
int[] searchName(SearchMode mode, String term, int offset, int count) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
@@ -200,6 +287,61 @@ public class AdvancedUserOps_mysql extends AdvancedUserOps
|
||||
tmp[ct++] = rs.getInt(1);
|
||||
|
||||
// Create the actual return array and fill it.
|
||||
if (ct==tmp.length)
|
||||
return tmp;
|
||||
int[] rc = new int[ct];
|
||||
System.arraycopy(tmp,0,rc,0,ct);
|
||||
return rc;
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end searchName
|
||||
|
||||
int[] searchName(int member_gid, SearchMode mode, String term, int offset, int count) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// prepare and execute a query (note that we assemble it in SQL form)
|
||||
StringBuffer sql = new StringBuffer("SELECT u.uid FROM users u, groupmembers g WHERE u.is_anon = 0 "
|
||||
+ "AND u.uid = g.uid AND g.gid = ");
|
||||
sql.append(member_gid).append(" AND u.username ");
|
||||
if (SearchMode.PREFIX.equals(mode))
|
||||
sql.append("LIKE '").append(m_utils.encodeStringWildcards(term)).append("%'");
|
||||
else if (SearchMode.SUBSTRING.equals(mode))
|
||||
sql.append("LIKE '%").append(m_utils.encodeStringWildcards(term)).append("%'");
|
||||
else if (SearchMode.REGEXP.equals(mode))
|
||||
sql.append("REGEXP '").append(m_utils.encodeString(term)).append('\'');
|
||||
sql.append(" ORDER BY u.username LIMIT ").append(offset).append(", ").append(count+1).append(';');
|
||||
stmt = conn.createStatement();
|
||||
rs = stmt.executeQuery(sql.toString());
|
||||
|
||||
// We *know* the maximum number of indexes that can be returned, so allocate a temporary array big
|
||||
// enough to hold them all.
|
||||
int[] tmp = new int[count+1];
|
||||
int ct = 0;
|
||||
while (rs.next())
|
||||
tmp[ct++] = rs.getInt(1);
|
||||
|
||||
// Create the actual return array and fill it.
|
||||
if (ct==tmp.length)
|
||||
return tmp;
|
||||
int[] rc = new int[ct];
|
||||
System.arraycopy(tmp,0,rc,0,ct);
|
||||
return rc;
|
||||
@@ -258,4 +400,44 @@ public class AdvancedUserOps_mysql extends AdvancedUserOps
|
||||
|
||||
} // end searchNameCount
|
||||
|
||||
int searchNameCount(int member_gid, SearchMode mode, String term) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// prepare and execute a query (note that we assemble it in SQL form)
|
||||
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM users u, groupmembers g WHERE u.is_anon = 0 "
|
||||
+ "AND u.uid = g.uid AND g.gid = ");
|
||||
sql.append(member_gid).append(" AND u.username ");
|
||||
if (SearchMode.PREFIX.equals(mode))
|
||||
sql.append("LIKE '").append(m_utils.encodeStringWildcards(term)).append("%'");
|
||||
else if (SearchMode.SUBSTRING.equals(mode))
|
||||
sql.append("LIKE '%").append(m_utils.encodeStringWildcards(term)).append("%'");
|
||||
else if (SearchMode.REGEXP.equals(mode))
|
||||
sql.append("REGEXP '").append(m_utils.encodeString(term)).append('\'');
|
||||
sql.append(';');
|
||||
stmt = conn.createStatement();
|
||||
rs = stmt.executeQuery(sql.toString());
|
||||
return SQLUtils.getReturnCountInt(rs,1);
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end searchNameCount
|
||||
|
||||
} // end class AdvancedUserOps_mysql
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.silverwrist.venice.app;
|
||||
import java.util.List;
|
||||
import com.silverwrist.dynamo.db.UserManagement;
|
||||
import com.silverwrist.dynamo.except.DatabaseException;
|
||||
import com.silverwrist.dynamo.iface.DynamoGroup;
|
||||
import com.silverwrist.dynamo.iface.DynamoUser;
|
||||
import com.silverwrist.venice.SearchMode;
|
||||
import com.silverwrist.venice.UserSearchField;
|
||||
@@ -32,4 +33,10 @@ public interface AdvancedUserService extends UserManagement
|
||||
public int getSearchUserCount(DynamoUser caller, UserSearchField field, SearchMode mode, String term)
|
||||
throws DatabaseException;
|
||||
|
||||
public List searchForMembers(DynamoUser caller, DynamoGroup group, UserSearchField field, SearchMode mode,
|
||||
String term, int offset, int count) throws DatabaseException;
|
||||
|
||||
public int getSearchMemberCount(DynamoUser caller, DynamoGroup group, UserSearchField field, SearchMode mode,
|
||||
String term) throws DatabaseException;
|
||||
|
||||
} // end interface AdvancedUserService
|
||||
|
||||
@@ -880,7 +880,8 @@ class CommunityImpl implements VeniceCommunity
|
||||
synchronized (this)
|
||||
{ // update the access table and touch the community
|
||||
java.util.Date update = m_ops.revokeAccess(m_id,ugid,is_group);
|
||||
m_lastaccessed = m_lastupdate = update;
|
||||
if (update!=null)
|
||||
m_lastaccessed = m_lastupdate = update;
|
||||
|
||||
} // end synchronized block
|
||||
|
||||
@@ -953,7 +954,8 @@ class CommunityImpl implements VeniceCommunity
|
||||
logger.debug("CommunityImpl.join: " + joiner.getName() + " joining " + m_name);
|
||||
|
||||
// If the user is already a member, return the value that dictates that we are already a member.
|
||||
if (m_users.getGroup(m_member_gid).isMember(joiner))
|
||||
DynamoGroup mbr_group = m_users.getGroup(m_member_gid);
|
||||
if (mbr_group.isMember(joiner))
|
||||
return false;
|
||||
|
||||
boolean ok_to_join = false;
|
||||
@@ -1030,7 +1032,7 @@ class CommunityImpl implements VeniceCommunity
|
||||
|
||||
if (ok_to_join)
|
||||
{ // we're OK to join this group!
|
||||
m_users.getGroup(m_member_gid).addMember(m_users.getUser(m_host_uid),joiner);
|
||||
mbr_group.addMember(m_users.getUser(m_host_uid),joiner);
|
||||
if (task!=null)
|
||||
task.run();
|
||||
return true;
|
||||
@@ -1051,6 +1053,16 @@ class CommunityImpl implements VeniceCommunity
|
||||
|
||||
} // end join
|
||||
|
||||
public void unjoin(DynamoUser unjoiner) throws DatabaseException, DynamoSecurityException
|
||||
{
|
||||
DynamoGroup mbr_group = m_users.getGroup(m_member_gid);
|
||||
if (!(mbr_group.isMember(unjoiner)))
|
||||
return; // if you're not a member, unjoining is a no-op
|
||||
testPermission(unjoiner,VeniceNamespaces.COMMUNITY_PERMS_NAMESPACE,"unjoin","auth.unjoin");
|
||||
mbr_group.removeMember(m_users.getUser(m_host_uid),unjoiner);
|
||||
|
||||
} // end unjoin
|
||||
|
||||
public boolean isAdministrator(DynamoUser user)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -33,3 +33,4 @@ join.disallowed=You are not permitted to join community "{0}."
|
||||
join.authFail=Unable to authenticate to community "{0}"; cannot join.
|
||||
svc.modname.mismatch=The name of the service module "{0}" did not match the name stored in the database.
|
||||
svc.object.badType=The service controller object {0}::{1} was of the wrong type.
|
||||
auth.unjoin=You are not permitted to unjoin community "{0}."
|
||||
|
||||
@@ -650,20 +650,52 @@ class CommunityOps_mysql extends CommunityOps
|
||||
stmt2 = conn.createStatement();
|
||||
stmt2.executeUpdate("LOCK TABLES commaccess WRITE, communities WRITE;");
|
||||
|
||||
// create the insert statement and execute it
|
||||
stmt = conn.prepareStatement("INSERT INTO commaccess (cid, ugid, is_group, single_use, auth_nsid, auth_name, "
|
||||
+ "source_data, auth_data) VALUES (?, ?, ?, ?, ?, ?, ?, ?);");
|
||||
// see if the key is already there
|
||||
stmt = conn.prepareStatement("SELECT single_use FROM commaccess WHERE cid = ? AND ugid = ? AND is_group = ?;");
|
||||
stmt.setInt(1,cid);
|
||||
stmt.setInt(2,ugid);
|
||||
stmt.setInt(3,(is_group ? 1 : 0));
|
||||
stmt.setInt(4,(single_use ? 1 : 0));
|
||||
if (auth_nsid==0)
|
||||
stmt.setNull(5,Types.INTEGER);
|
||||
rs = stmt.executeQuery();
|
||||
boolean newbie = !(rs.next());
|
||||
rs.close();
|
||||
rs = null;
|
||||
stmt.close();
|
||||
|
||||
if (newbie)
|
||||
{ // create the insert statement and execute it
|
||||
stmt = conn.prepareStatement("INSERT INTO commaccess (cid, ugid, is_group, single_use, auth_nsid, auth_name, "
|
||||
+ "source_data, auth_data) VALUES (?, ?, ?, ?, ?, ?, ?, ?);");
|
||||
stmt.setInt(1,cid);
|
||||
stmt.setInt(2,ugid);
|
||||
stmt.setInt(3,(is_group ? 1 : 0));
|
||||
stmt.setInt(4,(single_use ? 1 : 0));
|
||||
if (auth_nsid==0)
|
||||
stmt.setNull(5,Types.INTEGER);
|
||||
else
|
||||
stmt.setInt(5,auth_nsid);
|
||||
stmt.setString(6,auth_name);
|
||||
stmt.setString(7,source_data);
|
||||
stmt.setString(8,auth_data);
|
||||
|
||||
} // end if
|
||||
else
|
||||
stmt.setInt(5,auth_nsid);
|
||||
stmt.setString(6,auth_name);
|
||||
stmt.setString(7,source_data);
|
||||
stmt.setString(8,auth_data);
|
||||
{ // update the existing access information
|
||||
stmt = conn.prepareStatement("UPDATE commaccess SET single_use = ?, auth_nsid = ?, auth_name = ?, "
|
||||
+ "source_data = ?, auth_data = ? WHERE cid = ? AND ugid = ? AND is_group = ?;");
|
||||
stmt.setInt(1,(single_use ? 1 : 0));
|
||||
if (auth_nsid==0)
|
||||
stmt.setNull(2,Types.INTEGER);
|
||||
else
|
||||
stmt.setInt(2,auth_nsid);
|
||||
stmt.setString(3,auth_name);
|
||||
stmt.setString(4,source_data);
|
||||
stmt.setString(5,auth_data);
|
||||
stmt.setInt(6,cid);
|
||||
stmt.setInt(7,ugid);
|
||||
stmt.setInt(8,(is_group ? 1 : 0));
|
||||
|
||||
} // end else
|
||||
|
||||
stmt.executeUpdate();
|
||||
|
||||
// Touch the community entry.
|
||||
@@ -707,7 +739,8 @@ class CommunityOps_mysql extends CommunityOps
|
||||
stmt.setInt(1,cid);
|
||||
stmt.setInt(2,ugid);
|
||||
stmt.setInt(3,(is_group ? 1 : 0));
|
||||
stmt.executeUpdate();
|
||||
if (stmt.executeUpdate()<=0)
|
||||
return null;
|
||||
|
||||
// Touch the community entry.
|
||||
return touchCommunity(conn,cid);
|
||||
|
||||
@@ -603,6 +603,12 @@ abstract class CommunityProxy implements VeniceCommunity, DynamicWrapper
|
||||
|
||||
} // end join
|
||||
|
||||
public void unjoin(DynamoUser unjoiner) throws DatabaseException, DynamoSecurityException
|
||||
{
|
||||
getRealCommunity().unjoin(unjoiner);
|
||||
|
||||
} // end unjoin
|
||||
|
||||
public boolean isAdministrator(DynamoUser user)
|
||||
{
|
||||
return getRealCommunity().isAdministrator(user);
|
||||
|
||||
237
src/venice-base/com/silverwrist/venice/content/ConfirmBox.java
Normal file
237
src/venice-base/com/silverwrist/venice/content/ConfirmBox.java
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.content;
|
||||
|
||||
import java.util.*;
|
||||
import com.silverwrist.dynamo.except.*;
|
||||
import com.silverwrist.dynamo.iface.*;
|
||||
import com.silverwrist.dynamo.util.*;
|
||||
import com.silverwrist.venice.frame.FramedContent;
|
||||
|
||||
public class ConfirmBox implements FramedContent
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private static final long TIMEOUT = 60000; // 1 minute
|
||||
|
||||
private static Random s_rng;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private String m_title; // confirm box title
|
||||
private String m_message; // confirm box message
|
||||
private int m_confirmation_number; // confirmation number
|
||||
private String m_yes_type; // "yes" link type
|
||||
private String m_yes_url; // "yes" link URL
|
||||
private String m_no_type; // "no" link type
|
||||
private String m_no_url; // "no" link URL
|
||||
private java.util.Date m_created; // this box was created when?
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public ConfirmBox(Request r, String attr_namespace, String attr_name, String param_name, String title,
|
||||
String message, String yes_url_type, String yes_url, String no_url_type, String no_url)
|
||||
{
|
||||
// Fill in all the parameters except m_created.
|
||||
m_title = title;
|
||||
m_message = message;
|
||||
m_confirmation_number = s_rng.nextInt(0x1000000);
|
||||
m_yes_type = yes_url_type;
|
||||
m_yes_url = yes_url;
|
||||
if (m_yes_url.indexOf('?')>=0)
|
||||
m_yes_url += ("&" + param_name + "=" + m_confirmation_number);
|
||||
else
|
||||
m_yes_url += ("?" + param_name + "=" + m_confirmation_number);
|
||||
m_no_type = no_url_type;
|
||||
m_no_url = no_url;
|
||||
|
||||
// Save this object in a session attribute.
|
||||
SessionInfoProvider prov = (SessionInfoProvider)(r.queryService(SessionInfoProvider.class));
|
||||
prov.getSessionInfo().setObject(attr_namespace,attr_name,this);
|
||||
|
||||
// Now start the timer ticking...
|
||||
m_created = new java.util.Date();
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
protected boolean doConfirm(int num)
|
||||
{
|
||||
java.util.Date now = new java.util.Date();
|
||||
if ((now.getTime() - m_created.getTime())>TIMEOUT)
|
||||
return false; // confirmation has timed out
|
||||
return (num==m_confirmation_number);
|
||||
|
||||
} // end doConfirm
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface FramedContent
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the desired menu selector for this page. The <EM>menu selector</EM> is a string that specifies
|
||||
* which menu is to be displayed on the left menu bar, in addition to the "global menu." This value may
|
||||
* be <CODE>null</CODE>, in which case the current menu selector is not changed.
|
||||
*
|
||||
* @return The desired menu selector.
|
||||
*/
|
||||
public String getMenuSelector()
|
||||
{
|
||||
return null;
|
||||
|
||||
} // end getMenuSelector
|
||||
|
||||
/**
|
||||
* Returns the desired title for the page. This title is concatenated with the <EM>site title</EM> (set in
|
||||
* global properties) to form the actual page title that gets sent to the browser.
|
||||
*
|
||||
* @return The desired page title.
|
||||
*/
|
||||
public String getPageTitle()
|
||||
{
|
||||
return m_title;
|
||||
|
||||
} // end getPageTitle
|
||||
|
||||
/**
|
||||
* Returns the desired quick ID for the page. The <EM>page quick ID</EM> is a small text string which can be used
|
||||
* to "tag" the page with a unique identifier, for use with external tools such as offsite hit counters.
|
||||
* If this value is <CODE>null</CODE>, the quick ID is not used for this page.
|
||||
*
|
||||
* @return The desired page quick ID.
|
||||
*/
|
||||
public String getPageQID()
|
||||
{
|
||||
return null;
|
||||
|
||||
} // end getPageQID
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static boolean isConfirmed(Request r, String attr_namespace, String attr_name, String param_name)
|
||||
{
|
||||
// First, retrieve the confirm box out of the session data.
|
||||
ConfirmBox cb = null;
|
||||
RequestHelper rhelp = new RequestHelper(r);
|
||||
try
|
||||
{ // look up the session data and retrieve the confirmation box
|
||||
SessionInfo session = rhelp.getSession();
|
||||
cb = (ConfirmBox)(session.getObject(attr_namespace,attr_name));
|
||||
session.removeObject(attr_namespace,attr_name);
|
||||
|
||||
} // end try
|
||||
catch (NoSuchObjectException e)
|
||||
{ // there's no confirm box there
|
||||
return false;
|
||||
|
||||
} // end catch
|
||||
catch (ClassCastException cce)
|
||||
{ // there's something there but it's not a confirm box
|
||||
return false;
|
||||
|
||||
} // end catch
|
||||
|
||||
// Now get the confirmation number out of the parameters.
|
||||
int num = rhelp.getParameterInt(param_name,-1);
|
||||
if (num<0)
|
||||
return false; // there's no hope this will match
|
||||
|
||||
return cb.doConfirm(num);
|
||||
|
||||
} // end isConfirmed
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the title of the confirmation message box.
|
||||
*
|
||||
* @return The title of the confirmation message box.
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
return m_title;
|
||||
|
||||
} // end getTitle
|
||||
|
||||
/**
|
||||
* Returns the confirmation message text.
|
||||
*
|
||||
* @return The confirmation message text.
|
||||
*/
|
||||
public String getMessage()
|
||||
{
|
||||
return m_message;
|
||||
|
||||
} // end getMessage
|
||||
|
||||
public String getYesLinkType()
|
||||
{
|
||||
return m_yes_type;
|
||||
|
||||
} // end getYesLinkType
|
||||
|
||||
public String getYesLink()
|
||||
{
|
||||
return m_yes_url;
|
||||
|
||||
} // end getYesLink
|
||||
|
||||
public String getNoLinkType()
|
||||
{
|
||||
return m_no_type;
|
||||
|
||||
} // end getNoLinkType
|
||||
|
||||
public String getNoLink()
|
||||
{
|
||||
return m_no_url;
|
||||
|
||||
} // end getNoLink
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static initializer
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static
|
||||
{ // initialize the random number generator
|
||||
s_rng = new Random(System.currentTimeMillis());
|
||||
|
||||
} // end static initializer
|
||||
|
||||
} // end class ConfirmBox
|
||||
@@ -27,3 +27,4 @@ activity.never=Never
|
||||
activity.today=Today, {0}
|
||||
activity.yesterday=Yesterday, {0}
|
||||
activity.daysago={0} days ago
|
||||
render.confirmBox=Unable to render a confirmation box: {0}\nBox title was: {1}\nBox message was: {2}
|
||||
|
||||
@@ -94,6 +94,7 @@ public class StandardContentSupplier
|
||||
private String m_name = null; // name of the object
|
||||
private ObjectProvider m_blocks; // global blocks provider
|
||||
private ComponentShutdown m_shut_1; // shut down renderer
|
||||
private ComponentShutdown m_shut_1a; // shut down renderer
|
||||
private ComponentShutdown m_shut_2; // shut down Velocity object
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
@@ -177,6 +178,7 @@ public class StandardContentSupplier
|
||||
// Register this object as a renderer for some objects.
|
||||
RendererRegistration rr = (RendererRegistration)(services.queryService(RendererRegistration.class));
|
||||
m_shut_1 = rr.registerRenderer(ErrorBox.class,this);
|
||||
m_shut_1a = rr.registerRenderer(ConfirmBox.class,this);
|
||||
|
||||
// Add an object to the standard objects available to Velocity.
|
||||
VelocityRendererConfig vrcon =
|
||||
@@ -194,6 +196,8 @@ public class StandardContentSupplier
|
||||
{
|
||||
m_shut_2.shutdown();
|
||||
m_shut_2 = null;
|
||||
m_shut_1a.shutdown();
|
||||
m_shut_1a = null;
|
||||
m_shut_1.shutdown();
|
||||
m_shut_1 = null;
|
||||
m_blocks = null;
|
||||
@@ -307,6 +311,33 @@ public class StandardContentSupplier
|
||||
} // end catch
|
||||
|
||||
} // end if
|
||||
else if (obj instanceof ConfirmBox)
|
||||
{ // render a confirmation box
|
||||
ConfirmBox cbox = (ConfirmBox)obj;
|
||||
try
|
||||
{ // get the confirm box template out of the database
|
||||
ContentBlock blk = this.getContentBlock("confirm.box");
|
||||
blk.setContentParameter("title",cbox.getTitle());
|
||||
blk.setContentParameter("message",cbox.getMessage());
|
||||
blk.setContentParameter("yes_type",cbox.getYesLinkType());
|
||||
blk.setContentParameter("yes_url",cbox.getYesLink());
|
||||
blk.setContentParameter("no_type",cbox.getNoLinkType());
|
||||
blk.setContentParameter("no_url",cbox.getNoLink());
|
||||
control.renderSubObject(blk); // render the block
|
||||
|
||||
} // end try
|
||||
catch (DatabaseException e)
|
||||
{ // translate this into a rendering exception
|
||||
RenderingException re = new RenderingException(StandardContentSupplier.class,"ContentMessages",
|
||||
"render.confirmBox",e);
|
||||
re.setParameter(0,e.getMessage());
|
||||
re.setParameter(1,cbox.getTitle());
|
||||
re.setParameter(2,cbox.getMessage());
|
||||
throw re;
|
||||
|
||||
} // end catch
|
||||
|
||||
} // end else if
|
||||
|
||||
} // end render
|
||||
|
||||
|
||||
@@ -312,6 +312,8 @@ public interface VeniceCommunity extends NamedObject, SecureObjectStore
|
||||
|
||||
public boolean join(DynamoUser joiner) throws DatabaseException, DynamoSecurityException;
|
||||
|
||||
public void unjoin(DynamoUser unjoiner) throws DatabaseException, DynamoSecurityException;
|
||||
|
||||
public boolean isAdministrator(DynamoUser user);
|
||||
|
||||
public List getServices() throws DatabaseException;
|
||||
|
||||
@@ -273,6 +273,8 @@ class InlineMenuRendering implements MenuRenderObject, SelfRenderable
|
||||
if (m_showitem[i] && item.itemDefined(m_local_vars))
|
||||
{ // render this item
|
||||
String s = item.getItemType();
|
||||
if (s.equalsIgnoreCase("MARKER"))
|
||||
continue; // ignore markers
|
||||
if (s.equalsIgnoreCase("TEXT"))
|
||||
renderTextItem(tctrl,item,(i==m_selected_index));
|
||||
else if (s.equalsIgnoreCase("HEADER"))
|
||||
|
||||
@@ -266,6 +266,8 @@ class LeftMenuRendering implements MenuRenderObject, SelfRenderable
|
||||
if (m_showitem[i] && item.itemDefined(m_local_vars))
|
||||
{ // render this item
|
||||
String s = item.getItemType();
|
||||
if (s.equalsIgnoreCase("MARKER"))
|
||||
continue; // ignore markers
|
||||
if (s.equalsIgnoreCase("TEXT"))
|
||||
renderTextItem(tctrl,item,(m_selected_index==i));
|
||||
else if (s.equalsIgnoreCase("HEADER"))
|
||||
|
||||
@@ -278,6 +278,8 @@ class StandardMenuRendering implements MenuRenderObject, SelfRenderable, FramedC
|
||||
if (m_showitem[i] && item.itemDefined(m_local_vars))
|
||||
{ // render this item
|
||||
s = item.getItemType();
|
||||
if (s.equalsIgnoreCase("MARKER"))
|
||||
continue; // ignore markers
|
||||
if (s.equalsIgnoreCase("TEXT"))
|
||||
renderTextItem(tctl,item,(m_selected_index==i));
|
||||
else if (s.equalsIgnoreCase("HEADER"))
|
||||
|
||||
@@ -123,6 +123,12 @@ public class LibraryVenice
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public boolean confirmed(Request r, String attr_namespace, String attr_name, String param_name)
|
||||
{
|
||||
return ConfirmBox.isConfirmed(r,attr_namespace,attr_name,param_name);
|
||||
|
||||
} // end confirmed
|
||||
|
||||
public String dialogFrameTitle(Dialog dlg)
|
||||
{
|
||||
String s = dlg.getSubtitle();
|
||||
|
||||
Reference in New Issue
Block a user