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 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 {
|
||||
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");
|
||||
}
|
||||
String shareWithSub = new String(invokeResult.getPayload().array()).replace("\"", "");
|
||||
checkAccess.setString(2, shareWithSub);
|
||||
checkAccessRS = checkAccess.executeQuery();
|
||||
if (checkAccessRS.next()) {
|
||||
throw new InputMismatchException("The specified user already has access");
|
||||
}
|
||||
// checkAccess.setString(2, shareWithSub);
|
||||
// checkAccessRS = checkAccess.executeQuery();
|
||||
// if (checkAccessRS.next()) {
|
||||
// throw new InputMismatchException("The specified user already has access");
|
||||
// }
|
||||
|
||||
PreparedStatement shareList = connection.prepareStatement(SHARE_LIST);
|
||||
shareList.setInt(1, listID);
|
||||
shareList.setString(2, shareWithSub);
|
||||
Integer permissionLevel = Integer.parseInt(bodyMap.get("permissionLevel").toString());
|
||||
shareList.setInt(3, permissionLevel);
|
||||
shareList.executeUpdate();
|
||||
connection.commit();
|
||||
return null;
|
||||
|
||||
@ -5,23 +5,14 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import com.example.listify.data.Chain;
|
||||
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 com.example.listify.data.*;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
@ -30,8 +21,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import static com.example.listify.MainActivity.am;
|
||||
|
||||
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) {
|
||||
EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail);
|
||||
String sharedEmail = sharedEmailText.getText().toString();
|
||||
ListShare listShare = new ListShare(listID, sharedEmail);
|
||||
ListShare listShare = new ListShare(listID, sharedEmail, "Read, Edit, Delete");
|
||||
try {
|
||||
requestor.postObject(listShare);
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail);
|
||||
String sharedEmail = sharedEmailText.getText().toString();
|
||||
ListShare listShare = new ListShare(curList.getItemID(), sharedEmail);
|
||||
ListShare listShare = new ListShare(curList.getItemID(), sharedEmail, "Read, Edit, Delete");
|
||||
try {
|
||||
requestor.postObject(listShare);
|
||||
}
|
||||
|
||||
@ -1,12 +1,65 @@
|
||||
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 {
|
||||
Integer listID;
|
||||
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.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() {
|
||||
@ -24,4 +77,13 @@ public class ListShare {
|
||||
public void setShareWithEmail(String 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