mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Set permission param
Ensure permssion parameter is getting set when sharing a list
This commit is contained in:
parent
2d3e985ded
commit
82272a9a29
@ -22,7 +22,7 @@ public class ListSharer implements CallHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final private String CHECK_ACCESS = "SELECT * from ListSharee WHERE listID = ? AND userID = ?;";
|
final private String CHECK_ACCESS = "SELECT * from ListSharee WHERE listID = ? AND userID = ?;";
|
||||||
final private String SHARE_LIST = "INSERT INTO ListSharee(listID, userID) VALUES(?, ?);";
|
final private String SHARE_LIST = "INSERT INTO ListSharee(listID, userID, permissionLevel) VALUES(?, ?, ?);";
|
||||||
|
|
||||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||||
PreparedStatement checkAccess = connection.prepareStatement(CHECK_ACCESS);
|
PreparedStatement checkAccess = connection.prepareStatement(CHECK_ACCESS);
|
||||||
@ -52,15 +52,17 @@ public class ListSharer implements CallHandler {
|
|||||||
throw new InputMismatchException("Could not find specified user to share with");
|
throw new InputMismatchException("Could not find specified user to share with");
|
||||||
}
|
}
|
||||||
String shareWithSub = new String(invokeResult.getPayload().array()).replace("\"", "");
|
String shareWithSub = new String(invokeResult.getPayload().array()).replace("\"", "");
|
||||||
checkAccess.setString(2, shareWithSub);
|
// checkAccess.setString(2, shareWithSub);
|
||||||
checkAccessRS = checkAccess.executeQuery();
|
// checkAccessRS = checkAccess.executeQuery();
|
||||||
if (checkAccessRS.next()) {
|
// if (checkAccessRS.next()) {
|
||||||
throw new InputMismatchException("The specified user already has access");
|
// throw new InputMismatchException("The specified user already has access");
|
||||||
}
|
// }
|
||||||
|
|
||||||
PreparedStatement shareList = connection.prepareStatement(SHARE_LIST);
|
PreparedStatement shareList = connection.prepareStatement(SHARE_LIST);
|
||||||
shareList.setInt(1, listID);
|
shareList.setInt(1, listID);
|
||||||
shareList.setString(2, shareWithSub);
|
shareList.setString(2, shareWithSub);
|
||||||
|
Integer permissionLevel = Integer.parseInt(bodyMap.get("permissionLevel").toString());
|
||||||
|
shareList.setInt(3, permissionLevel);
|
||||||
shareList.executeUpdate();
|
shareList.executeUpdate();
|
||||||
connection.commit();
|
connection.commit();
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -5,23 +5,14 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.*;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.example.listify.data.*;
|
||||||
import com.example.listify.data.Chain;
|
import org.json.JSONException;
|
||||||
import com.example.listify.data.Item;
|
|
||||||
import com.example.listify.data.List;
|
|
||||||
import com.example.listify.data.ListEntry;
|
|
||||||
import com.example.listify.data.ListShare;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
@ -30,8 +21,6 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import static com.example.listify.MainActivity.am;
|
import static com.example.listify.MainActivity.am;
|
||||||
|
|
||||||
public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||||
@ -125,7 +114,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail);
|
EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail);
|
||||||
String sharedEmail = sharedEmailText.getText().toString();
|
String sharedEmail = sharedEmailText.getText().toString();
|
||||||
ListShare listShare = new ListShare(listID, sharedEmail);
|
ListShare listShare = new ListShare(listID, sharedEmail, "Read, Edit, Delete");
|
||||||
try {
|
try {
|
||||||
requestor.postObject(listShare);
|
requestor.postObject(listShare);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -129,7 +129,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
|
|||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail);
|
EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail);
|
||||||
String sharedEmail = sharedEmailText.getText().toString();
|
String sharedEmail = sharedEmailText.getText().toString();
|
||||||
ListShare listShare = new ListShare(curList.getItemID(), sharedEmail);
|
ListShare listShare = new ListShare(curList.getItemID(), sharedEmail, "Read, Edit, Delete");
|
||||||
try {
|
try {
|
||||||
requestor.postObject(listShare);
|
requestor.postObject(listShare);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,65 @@
|
|||||||
package com.example.listify.data;
|
package com.example.listify.data;
|
||||||
|
|
||||||
|
import com.example.listify.BuildConfig;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class ListShare {
|
public class ListShare {
|
||||||
Integer listID;
|
Integer listID;
|
||||||
String shareWithEmail;
|
String shareWithEmail;
|
||||||
|
Integer permissionLevel;
|
||||||
|
|
||||||
public ListShare(Integer listID, String shareWithEmail) {
|
private static final Map<Integer, String> keysToPerms;
|
||||||
|
static {
|
||||||
|
//All keys should be a prime number > 1
|
||||||
|
HashMap<Integer, String> keysToPermsTemp = new HashMap<>();
|
||||||
|
keysToPermsTemp.put(2, "Read");
|
||||||
|
keysToPermsTemp.put(3, "Edit");
|
||||||
|
keysToPermsTemp.put(5, "Delete");
|
||||||
|
keysToPerms = Collections.unmodifiableMap(keysToPermsTemp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListShare(Integer listID, String shareWithEmail, Integer permissionLevel) {
|
||||||
this.listID = listID;
|
this.listID = listID;
|
||||||
this.shareWithEmail = shareWithEmail;
|
this.shareWithEmail = shareWithEmail;
|
||||||
|
this.permissionLevel = permissionLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListShare(Integer listID, String shareWithEmail, String permissions) {
|
||||||
|
this.listID = listID;
|
||||||
|
this.shareWithEmail = shareWithEmail;
|
||||||
|
permissionLevel = 1;
|
||||||
|
for (Map.Entry<Integer, String> keytoPermEntry: keysToPerms.entrySet()) {
|
||||||
|
if (permissions.contains(keytoPermEntry.getValue())) {
|
||||||
|
permissionLevel *= keytoPermEntry.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder toReturn = new StringBuilder("ListShare{" +
|
||||||
|
"listID=" + listID +
|
||||||
|
", shareWithEmail='" + shareWithEmail + '\'' +
|
||||||
|
", permissionLevel=" + permissionLevel +
|
||||||
|
" [Permissions: ");
|
||||||
|
|
||||||
|
int permissionLevelCopy = permissionLevel;
|
||||||
|
for (Object permissionObject : keysToPerms.keySet().stream().sorted(Comparator.reverseOrder()).toArray()) {
|
||||||
|
Integer permissionInteger = (Integer) permissionObject;
|
||||||
|
if (permissionLevelCopy % permissionInteger == 0) {
|
||||||
|
permissionLevelCopy /= permissionInteger;
|
||||||
|
toReturn.append(keysToPerms.get(permissionInteger)).append(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (BuildConfig.DEBUG && permissionLevelCopy != 1) {
|
||||||
|
throw new AssertionError("Assertion failed");
|
||||||
|
}
|
||||||
|
toReturn.append("]}");
|
||||||
|
return toReturn.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getListID() {
|
public Integer getListID() {
|
||||||
@ -24,4 +77,13 @@ public class ListShare {
|
|||||||
public void setShareWithEmail(String shareWithEmail) {
|
public void setShareWithEmail(String shareWithEmail) {
|
||||||
this.shareWithEmail = shareWithEmail;
|
this.shareWithEmail = shareWithEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getPermissionLevel() {
|
||||||
|
return permissionLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissionLevel(Integer permissionLevel) {
|
||||||
|
this.permissionLevel = permissionLevel;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user