Skip to content

Commit

Permalink
Fixed permission problems for action plans
Browse files Browse the repository at this point in the history
  • Loading branch information
DougLau committed Nov 22, 2024
1 parent c366539 commit 2250a0a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
9 changes: 2 additions & 7 deletions honeybee/src/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,7 @@ fn required_patch_operate(res: Res, att: &str) -> bool {
/// Check if Manage access is required to PATCH a resource/attribute
fn required_patch_manage(res: Res, att: &str) -> bool {
match (res, att) {
(Res::ActionPlan, "notes")
| (Res::ActionPlan, "sync_actions")
| (Res::ActionPlan, "sticky")
| (Res::ActionPlan, "ignore_auto_fail")
| (Res::ActionPlan, "active")
| (Res::ActionPlan, "default_phase")
(Res::ActionPlan, _)
| (Res::Alarm, "description")
| (Res::Beacon, "message")
| (Res::Beacon, "notes")
Expand Down Expand Up @@ -178,7 +173,7 @@ fn required_post_operate(res: Res) -> bool {
fn required_post_manage(res: Res) -> bool {
use Res::*;
match res {
MsgPattern | MsgLine => true,
ActionPlan | MsgPattern | MsgLine => true,
_ => false,
}
}
44 changes: 29 additions & 15 deletions src/us/mn/state/dot/sonar/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public String getAttributeName() {

/** Write/create/delete access exceptions for MANAGE level */
static final String[] TYPE_MANAGE = {
"msg_pattern", "msg_line"
"action_plan", "device_action", "msg_pattern", "msg_line",
"time_action"
};

/** Write access exceptions for OPERATE level */
Expand Down Expand Up @@ -157,12 +158,6 @@ public String getAttributeName() {

/** Write access exceptions for MANAGE level */
static final String[][] WRITE_MANAGE = {
{ "action_plan", "notes" },
{ "action_plan", "syncActions" },
{ "action_plan", "sticky" },
{ "action_plan", "ignoreAutoFail" },
{ "action_plan", "active" },
{ "action_plan", "defaultPhase" },
{ "alarm", "description" },
{ "beacon", "message" },
{ "beacon", "notes" },
Expand Down Expand Up @@ -209,26 +204,45 @@ public String getAttributeName() {

/** Get access level required to write object/attribute */
public int accessWrite() {
if (canWriteOperate())
return AccessLevel.OPERATE.ordinal();
else if (canWriteManage())
return AccessLevel.MANAGE.ordinal();
else
return AccessLevel.CONFIGURE.ordinal();
}

/** Check for write access at OPERATE level */
private boolean canWriteOperate() {
String typ = getTypePart();
for (String acc: TYPE_OPERATE) {
if (acc.equals(typ))
return AccessLevel.OPERATE.ordinal();
}
for (String acc: TYPE_MANAGE) {
if (acc.equals(typ))
return AccessLevel.MANAGE.ordinal();
return true;
}
if (isAttribute()) {
String att = getAttributePart();
for (String[] acc: WRITE_OPERATE) {
if (acc[0].equals(typ) && acc[1].equals(att))
return AccessLevel.OPERATE.ordinal();
return true;
}
}
return false;
}

/** Check for write access at MANAGE level */
private boolean canWriteManage() {
String typ = getTypePart();
for (String acc: TYPE_MANAGE) {
if (acc.equals(typ))
return true;
}
if (isAttribute()) {
String att = getAttributePart();
for (String[] acc: WRITE_MANAGE) {
if (acc[0].equals(typ) && acc[1].equals(att))
return AccessLevel.MANAGE.ordinal();
return true;
}
}
return AccessLevel.CONFIGURE.ordinal();
return false;
}
}

0 comments on commit 2250a0a

Please sign in to comment.