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

Remove old Permission Forms code and remove V2 suffix from the new one #1347

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 0 additions & 111 deletions rails/app/controllers/admin/permission_forms_controller.rb
Original file line number Diff line number Diff line change
@@ -1,121 +1,10 @@
class Admin::PermissionFormsController < ApplicationController

protected

def not_authorized_error_message
super({resource_type: 'permission form'})
end

def update_student_permissions(student_id, permission_ids)
student = Portal::Student.find(student_id)
return false unless student
permission_ids ||= []
permission_ids = [permission_ids].flatten.compact.uniq
permissions = permission_ids.map { |pid| Portal::PermissionForm.find(pid) }
student.permission_forms = permissions
student.save
return true
end


class TeacherSearchForm < Struct.new(:name, :order)

def initialize(params)
params ||= {}
self.name = params[:name]
self.order = params[:order] || "last_name"
end
def search(current_visitor)
return [] unless self.name
value = "%#{self.name}%"
where = "users.login like ? " +
"or users.first_name like ? " +
"or users.last_name like ?" +
"or users.email like ?"
order = "users.last_name"
group = "users.login"
if current_visitor.has_role?('manager', 'admin', 'researcher')
teachers = Portal::Teacher.joins(:user,:clazzes).where(where, value, value, value, value)
else
if current_visitor.is_project_admin?
ids = current_visitor.admin_for_project_teachers.map {|t| t.user_id}
elsif current_visitor.is_project_researcher?
ids = current_visitor.researcher_for_project_teachers.map {|t| t.user_id}
end
teachers = Portal::Teacher.joins(:user,:clazzes).where("users.id in (?) and (#{where})", ids, value, value, value, value)
end
teachers.order(order).group(group).limit(30).map { |t| TeacherView.new(t)}
end
end

class StudentView < Struct.new(:name, :id, :login, :perms)
def initialize(portal_student)
user = portal_student.user
self.name = user.name
self.login = user.login
self.id = portal_student.id
self.perms = portal_student.permission_forms
end
end

class ClazzView < Struct.new(:id, :name, :students, :word)
def initialize(portal_clazz)
self.name = portal_clazz.name
self.word = portal_clazz.class_word
self.id = portal_clazz.id
self.students = portal_clazz.students.joins(:user).order('users.last_name').map{ |s| StudentView.new(s)}
end
end

class TeacherView < Struct.new(:name, :email, :login, :clazzes, :id)
def initialize(teacher)
user = teacher.user
self.name = user.name
self.login = user.login
self.email = user.email
self.id = user.id
self.clazzes = teacher.clazzes.map { |c| ClazzView.new(c) }
self.clazzes = clazzes.reject { |c| c.students.size < 1}
end
end

public

def index
authorize Portal::PermissionForm
# PUNDIT_REVIEW_SCOPE
# PUNDIT_CHECK_SCOPE (did not find instance)
# @permission_forms = policy_scope(Portal::PermissionForm)
form = TeacherSearchForm.new(params[:form])
@teachers = form.search current_visitor
@projects = policy_scope(Admin::Project).order("name ASC")
@permission_forms = policy_scope(Portal::PermissionForm)
end

def update_forms
authorize Portal::PermissionForm
student_id = params['student_id']
permission_ids = params['permission_ids']
status = 400
if update_student_permissions(student_id, permission_ids)
status = 200
end
head status
end

def create
authorize Portal::PermissionForm
form_data = params['portal_permission']
if form_data && (!form_data['name'].blank?)
form = Portal::PermissionForm.create(:name => form_data['name'], :url => form_data['url'], :project_id => form_data['project_id'])
end
redirect_to action: 'index'
end

def remove_form
form = Portal::PermissionForm.find(params[:id])
authorize form, :destroy?
form.destroy
redirect_to action: 'index'
end
end
10 changes: 0 additions & 10 deletions rails/app/controllers/admin/permission_forms_v2_controller.rb

This file was deleted.

31 changes: 15 additions & 16 deletions rails/app/controllers/api/v1/permission_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@ class API::V1::PermissionFormsController < API::APIController

# GET /api/v1/permission_forms/index
def index
authorize Portal::PermissionForm, :permission_forms_v2_index?
authorize Portal::PermissionForm
permission_forms = management_policy_scope(Portal::PermissionForm)

permission_forms_with_permissions = permission_forms.map do |permission_form|
{
id: permission_form.id,
name: permission_form.name,
project_id: permission_form.project_id,
url: permission_form.url,
is_archived: permission_form.is_archived,
can_delete: Pundit.policy(current_user, permission_form).destroy?
}
permission_forms_with_permissions = permission_forms.map do |form|
permission_form_hash(form).merge(can_delete: Pundit.policy(current_user, form).destroy?)
end

render json: permission_forms_with_permissions
Expand Down Expand Up @@ -113,12 +106,8 @@ def class_permission_forms
id: student.id,
name: student.user.name,
login: student.user.login,
permission_forms: management_policy_scope(student.permission_forms).select(:id, :name, :is_archived).map do |form|
{
id: form.id,
name: form.name,
is_archived: form.is_archived
}
permission_forms: management_policy_scope(student.permission_forms).map do |form|
permission_form_hash(form)
end
}
end
Expand Down Expand Up @@ -199,6 +188,16 @@ def management_policy_scope(scope)
end
end

def permission_form_hash(permission_form)
{
id: permission_form.id,
name: permission_form.name,
project_id: permission_form.project_id,
url: permission_form.url,
is_archived: permission_form.is_archived
}
end

def permission_form_params
params.require(:permission_form).permit(:name, :project_id, :url, :is_archived)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def error_500(e)
# Returns list of report_learners matching filters, up to max size, no aggregations
#
def index
authorize Portal::PermissionForm
authorize Portal::PermissionForm, :report_learners_es_index?

if !ENV['ELASTICSEARCH_URL']
return error("Elasticsearch endpoint url not set")
Expand Down
10 changes: 4 additions & 6 deletions rails/app/policies/portal/permission_form_policy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Portal::PermissionFormPolicy < ApplicationPolicy

# User by API::V1::ReportLearnersEsController:

class Scope < Scope
def resolve
if user.has_role?('admin')
Expand All @@ -14,7 +16,7 @@ def resolve
end
end

def index?
def report_learners_es_index?
manager_or_researcher_or_project_researcher?
end

Expand All @@ -30,13 +32,9 @@ def external_report_learners_from_jwt?
manager_or_researcher_or_project_researcher?
end

def update_forms?
manager_or_researcher_or_project_researcher?
end

# API::V1::PermissionFormsController:

def permission_forms_v2_index?
def index?
user && user.can_manage_permission_forms?
end

Expand Down
31 changes: 0 additions & 31 deletions rails/app/views/admin/permission_forms/_permission_forms.html.haml

This file was deleted.

5 changes: 0 additions & 5 deletions rails/app/views/admin/permission_forms/_search_form.html.haml

This file was deleted.

14 changes: 0 additions & 14 deletions rails/app/views/admin/permission_forms/_show.html.haml

This file was deleted.

9 changes: 0 additions & 9 deletions rails/app/views/admin/permission_forms/_show_class.html.haml

This file was deleted.

24 changes: 0 additions & 24 deletions rails/app/views/admin/permission_forms/_show_student.html.haml

This file was deleted.

18 changes: 4 additions & 14 deletions rails/app/views/admin/permission_forms/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
%p
= render :partial => 'permission_forms', :locals => {:projects => @projects, :permission_forms => @permission_forms}
= render :partial => 'search_form', :locals => {:form => @form}
- unless @teachers.blank?
%h3 Teachers:
#listings.scrollable
%table#admin_teachers_table
%tr
%th Teacher
%th Classes
= render :partial => 'show', :collection => @teachers, :as => :teacher, :locals => {:permission_forms => @permission_forms}
- else
%p
search for teachers by firstname, lastname, login, or email.
#permission-forms-page

:javascript
PortalComponents.renderPermissionForms({}, 'permission-forms-page')
4 changes: 0 additions & 4 deletions rails/app/views/admin/permission_forms_v2/index.html.haml

This file was deleted.

1 change: 0 additions & 1 deletion rails/app/views/home/admin.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
%li.trail=link_to('Authoring', authoring_path)
- if can_manage_permission_forms
%li= link_to 'Permission Forms', admin_permission_forms_path
%li= link_to 'Permission Forms V2 (DEV ONLY)', admin_permission_forms_v2_index_path
- if is_admin_or_project_admin
%li= link_to 'Projects', admin_projects_path
%li= link_to 'Materials Collections', materials_collections_path
Expand Down
8 changes: 1 addition & 7 deletions rails/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,8 @@
resources :clients
resources :tools
resources :external_reports
resources :permission_forms do
member do
get :remove_form
end
end
resources :permission_forms_v2
resources :permission_forms

post 'permission_forms/update_forms' => 'permission_forms#update_forms', :as => :update_permissions_forms
resources :site_notices

get '/learner_detail/:id_or_key.:format' => 'learner_details#show', :as => :learner_detail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import css from "./index.scss";

type PermissionsTab = "manageFormsTab" | "studentsTab";

export default function PermissionFormsV2() {
export default function PermissionForms() {
// State for UI
const [openTab, setOpenTab] = useState<PermissionsTab>("studentsTab");

Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions rails/react-components/src/library/library.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { MakeTeacherEditionLinks } from "./helpers/make-teacher-edition-links";
import * as signupFunctions from "./components/signup/signup_functions";
import RecentActivity from "./components/recent-activity";
import Assignments from "./components/assigments";
import PermissionFormsV2 from "./components/permission-forms-v2";
import PermissionForms from "./components/permission-forms";
import Navigation from "./components/navigation";
import RunWithCollaborators from "./components/run-with-collaborators";
import LearnerReportForm from "./components/learner-report-form";
Expand Down Expand Up @@ -99,9 +99,9 @@ window.PortalPages = window.PortalComponents = {
CollectionsPage,
renderCollectionsPage: renderComponentFn(CollectionsPage),

PermissionFormsV2,
renderPermissionFormsV2 (options: any, id: any) {
render(createElement(PermissionFormsV2, options), id);
PermissionForms,
renderPermissionForms (options: any, id: any) {
render(createElement(PermissionForms, options), id);
},

RecentActivity,
Expand Down
Loading
Loading