Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/1512-and-1504 #1516

Closed
wants to merge 9 commits into from
4 changes: 4 additions & 0 deletions fuel/app/classes/materia/api/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ static public function widget_instance_update($inst_id=null, $name=null, $qset=n
// student made widgets are locked forever
if ($inst->is_student_made)
{
if ($guest_access === false)
{
return new Msg('Student-made widgets must stay in guest access mode.', 'Student Made', 'error', false);
}
$attempts = -1;
$guest_access = true;
}
Expand Down
20 changes: 19 additions & 1 deletion fuel/app/classes/materia/perm/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static public function is_super_user()
// The session caching has been removed due to issues related to the cache when the role is added or revoked
// Ideally we can still find a way to cache this and make it more performant!!
return (\Fuel::$is_cli === true && ! \Fuel::$is_test) || self::does_user_have_role([\Materia\Perm_Role::SU]);

}

/**
Expand Down Expand Up @@ -350,10 +350,28 @@ static public function remove_users_from_roles_system_only(Array $user_ids = [],
->where('role_id', self::get_role_id($role_name))
->execute();
}

if (self::is_student($user_id))
{
// Update user's instances' access modes
self::update_user_instance_access_mode($user_id);
}
}

return $success;
}

/**
* Updates access mode for all instances belonging to a user to guest mode
* @param int $user_id id of user with perms to object
*/
static public function update_user_instance_access_mode($user_id)
{
\DB::update('widget_instance')
->set(['guest_access' => Util_Validator::cast_to_bool_enum(1)])
->where('user_id', $user_id)
->execute();
}

/*
********************** User to Object Rights ***************************************
Expand Down
1 change: 1 addition & 0 deletions fuel/app/tests/api/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ public function test_widget_instance_update_as_student()
$qset = $this->create_new_qset($question, $answer);

$output = Api_V1::widget_instance_new($widget->id, $title, $qset, true);
$this->assert_is_widget_instance($output);

// EDIT DRAFT
$title = 'Around The World!';
Expand Down
6 changes: 5 additions & 1 deletion src/components/hooks/useSupportUpdateWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export default function useSupportUpdateWidget() {
apiUpdateWidget,
{
onSuccess: (data, variables) => {
if (!data || (data.type == 'error'))
{
return variables.errorFunc(data.msg)
}
variables.successFunc()

// Refresh widgets
Expand All @@ -20,7 +24,7 @@ export default function useSupportUpdateWidget() {
},
onError: (err, newWidget, context) => {
queryClient.setQueryData('widgets', context.previousValue)

variables.errorFunc()
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/hooks/useUpdateWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default function useUpdateWidget() {
return { widgetList }
},
onSuccess: (updatedInst, variables) => {

// update successful - insert new values into our local copy of widgetList
for (const page of widgetList?.pages) {
for (const inst of page?.pagination) {
Expand All @@ -33,7 +32,7 @@ export default function useUpdateWidget() {
}
}
}


// update query cache for widgets. This does NOT invalidate the cache, forcing a re-fetch!!
queryClient.setQueryData('widgets', widgetList)
Expand Down
6 changes: 6 additions & 0 deletions src/components/my-widgets-collaborate-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ const MyWidgetsCollaborateDialog = ({onClose, inst, myPerms, otherUserPerms, set
return <div key={userId}></div>
}

if (user.id == inst.user_id) {
user.is_owner = true;
} else {
user.is_owner = false;
}

return <CollaborateUserRow
key={user.id}
user={user}
Expand Down
17 changes: 13 additions & 4 deletions src/components/my-widgets-collaborate-dialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
position: relative;
text-align: left;
display: block;

font-weight: bold;
}

Expand Down Expand Up @@ -72,10 +72,10 @@
width: 447px;
padding-bottom: 5px;
overflow: auto;

background-color: #ffffff;
border: #bfbfbf 1px solid;

text-align: left;

.collab-search-match {
Expand All @@ -101,7 +101,7 @@
margin: 5px 0 0 5px;
font-size: 14px;
text-align: left;

font-family: 'Lucida Grande', sans-serif;
}
}
Expand Down Expand Up @@ -295,6 +295,15 @@
font-size: 11px;
color: gray;
}

&.user-match-owner:after {
content: 'Owner';
position: absolute;
top: -12px;
left: 0;
font-size: 11px;
color: gray;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/my-widgets-collaborate-user-row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const CollaborateUserRow = ({user, perms, myPerms, isCurrentUser, onChange, read
<div className='about'>
<img className='avatar' src={user.avatar} />

<span className={`name ${user.is_student ? 'user-match-student' : ''}`}>
<span className={`name ${user.is_owner ? 'user-match-owner' : user.is_student ? 'user-match-student' : ''}`}>
{`${user.first} ${user.last}`}
</span>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/my-widgets-settings-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,11 @@ const MyWidgetsSettingsDialog = ({ onClose, inst, currentUser, otherUserPerms, o
</div>
</li>
<li id='embedded-only'
className={`embed-only ${inst.is_embedded ? 'show' : ''}`}>
className={`embed-only ${inst.is_embedded && !inst.is_student_made ? 'show' : ''}`}>
<input type='radio'
id='embed-radio'
value='embed'
disabled={currentUser.is_student || inst.is_student_made}
checked={state.formData.changes.access === 'embed'}
onChange={() => {accessChange('embed')}}
/>
Expand Down
15 changes: 6 additions & 9 deletions src/components/my-widgets-settings-dialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
display: flex;
flex-direction: column;
width: 680px;
max-height: 675px;
max-height: 720px;
padding: 10px 10px 0 10px;

.top-bar {
Expand Down Expand Up @@ -278,7 +278,7 @@

&.limited-because-student {

li.normal.show, li.guest-mode {
li.normal.show, li.guest-mode, li.embed-only {
filter: blur(3px);
user-select: none;
pointer-events: none;
Expand All @@ -301,7 +301,7 @@
font-size: 13px;
}

.normal {
.normal, .embed-only {
display: none;

&.show {
Expand All @@ -317,17 +317,14 @@
margin-left: 5px;
}

.guest-mode {
&.disabled {
label {
color: #b5b3b3;
}
.disabled {
label {
color: #b5b3b3;
}
}
}

#embedded-only {
display: none;

&.show {
display: block;
Expand Down
4 changes: 2 additions & 2 deletions src/components/support-selected-instance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ const SupportSelectedInstance = ({inst, currentUser, embed = false}) => {
setSuccessText('Success!')
setErrorText('')
},
errorFunc: () => {
setErrorText('Error: Update Unsuccessful')
errorFunc: (msg) => {
setErrorText('Error: ' + msg)
setSuccessText('')
}
})
Expand Down
8 changes: 4 additions & 4 deletions src/components/widget-admin-list-card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const WidgetListCard = ({widget = null}) => {
event.persist()
setState(prevState => ({...prevState, widget: {...prevState.widget, meta_data: {...prevState.widget.meta_data, demo: event.target.value}}}))
}

const handleAboutChange = event => {
event.persist()
setState(prevState => ({...prevState, widget: {...prevState.widget, meta_data: {...prevState.widget.meta_data, about: event.target.value}}}))
Expand Down Expand Up @@ -81,7 +81,7 @@ const WidgetListCard = ({widget = null}) => {
excerpt: state.widget.meta_data.excerpt,
demo: state.widget.meta_data.demo,
}

apiUpdateWidgetAdmin(update).then(response => {
let errorMessage = []
let success = false
Expand Down Expand Up @@ -136,7 +136,7 @@ const WidgetListCard = ({widget = null}) => {
</span>
<span className="title">{state.widget.name}</span>
</div>
{ ! state.widget.expanded ? <></> :
{ ! state.widget.expanded ? <></> :
<div className="widget-info">
{ widgetErrorsRender }
{ widgetSuccessRender }
Expand Down Expand Up @@ -201,7 +201,7 @@ const WidgetListCard = ({widget = null}) => {
<div>
<span>
<label htmlFor="demo">Demo:</label>
<input value={state.widget.meta_data.demo}
<input value={state.widget.meta_data.demo}
onChange={handleDemoChange} type='text' id="demo"/>
</span>
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/util/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@ export const apiCanEditWidgets = arrayOfWidgetIds => {
*/
export const apiUpdateWidget = ({ args }) => {
return fetch('/api/json/widget_instance_update', fetchOptions({ body: `data=${formatFetchBody(args)}` }))
.then(res => res.json())
.then(resp => {
if (resp.status === 204 || resp.status === 502) return []
return resp.json()
})
.then(widget => widget)
}

Expand Down
Loading