mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-05 03:14:43 +08:00
fixes per @duco 's request
This commit is contained in:
parent
52e5cf7be8
commit
b106545d31
4 changed files with 13 additions and 10 deletions
|
@ -2,7 +2,7 @@ module ClientApi
|
|||
class PermissionsController < ApplicationController
|
||||
before_action :generate_permissions_object, only: :state
|
||||
|
||||
def state
|
||||
def status
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: @permissions, status: :ok
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
> Permissions.connect(MyComponent, ["can_update_team?", "can_read_team?"], "Team");
|
||||
>
|
||||
|
||||
Now you can access to your permissions through component params. The permissions
|
||||
Now you can access your permissions through component params. The permissions
|
||||
you required have 3 states [true, false, null]. Null is when you are waiting for server response.
|
||||
You can use methods params.can_uspdate_team? or whatever permissions you declare
|
||||
You can use methods params.can_update_team? or whatever permissions you declare
|
||||
*/
|
||||
import * as React from "react";
|
||||
import { getPermissionStatus } from "../api/permissions_api";
|
||||
|
@ -22,6 +22,9 @@ type State = {
|
|||
permissions: any
|
||||
};
|
||||
|
||||
type PermissionsObject = {
|
||||
[string]: boolean
|
||||
}
|
||||
/*
|
||||
This function accepts 3 arguments which are REQUIRED
|
||||
1.) WrappedComponent: Component that you want to have permissions
|
||||
|
@ -34,15 +37,15 @@ export function connect<Props: {}>(
|
|||
requiredPermissions: Array<string> = [],
|
||||
resource: string
|
||||
) {
|
||||
let parsedPermission = {};
|
||||
const parsedPermissions: PermissionsObject = {};
|
||||
requiredPermissions.forEach(el => {
|
||||
parsedPermission[el] = null;
|
||||
parsedPermissions[el] = null;
|
||||
});
|
||||
|
||||
return class extends React.Component<*, State, *> {
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
this.state = { permissions: parsedPermission };
|
||||
this.state = { permissions: parsedPermissions };
|
||||
}
|
||||
|
||||
componentDidMount(): void {
|
||||
|
@ -51,7 +54,7 @@ export function connect<Props: {}>(
|
|||
this.setState({ permissions: data });
|
||||
})
|
||||
.catch(() => {
|
||||
let permissions = {};
|
||||
const permissions: PermissionsObject = {};
|
||||
requiredPermissions.forEach(el => {
|
||||
permissions[el] = false;
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@ Rails.application.routes.draw do
|
|||
get '/settings/*all', to: 'client_api/settings#index'
|
||||
|
||||
namespace :client_api, defaults: { format: 'json' } do
|
||||
post '/premissions', to: 'permissions#state'
|
||||
post '/premissions', to: 'permissions#status'
|
||||
%i(activities teams notifications users configurations).each do |path|
|
||||
draw path
|
||||
end
|
||||
|
|
|
@ -3,11 +3,11 @@ require 'rails_helper'
|
|||
describe ClientApi::PermissionsController, type: :controller do
|
||||
login_user
|
||||
|
||||
describe '#state' do
|
||||
describe '#status' do
|
||||
let(:params) do
|
||||
{ parsePermission: ['can_view_team'], resource: 'UserTeam' }
|
||||
end
|
||||
let(:subject) { post :state, format: :json, params: params }
|
||||
let(:subject) { post :status, format: :json, params: params }
|
||||
it { is_expected.to be_success }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue