Skip to content
Open
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
6 changes: 6 additions & 0 deletions app/api/chemotion/admin_user_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class AdminUserAPI < Grape::API
desc: 'enable or disable ketcherails template moderation'
optional :molecule_editor, type: Boolean, desc: 'enable or disable molecule moderation'
optional :converter_admin, type: Boolean, desc: 'converter profile'
optional :global_text_template_editor, type: Boolean, desc: 'enable editing global text templates'
optional :auth_generic_admin, type: Hash do
optional :elements, type: Boolean, desc: 'un-authorize the user as generic elements admin'
optional :segments, type: Boolean, desc: 'un-authorize the user as generic segments admin'
Expand All @@ -225,6 +226,11 @@ class AdminUserAPI < Grape::API
pdata = pdata.merge('molecule_editor' => params[:molecule_editor])
end

case params[:global_text_template_editor]
when true, false
pdata = pdata.merge('global_text_template_editor' => params[:global_text_template_editor])
end

if params[:auth_generic_admin].present?
pdata = pdata.deep_merge('generic_admin' => params[:auth_generic_admin])
end
Expand Down
67 changes: 62 additions & 5 deletions app/api/chemotion/text_template_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class TextTemplateAPI < Grape::API
end

delete :by_name do
error!('401 Unauthorized', 401) unless Admin.exists?(id: current_user.id)
unless Admin.exists?(id: current_user.id) || current_user.global_text_template_editor
error!('401 Unauthorized', 401)
end

template = PredefinedTextTemplate.where(name: params['name']).first
error!('404 Not found', 404) if template.nil?
Expand All @@ -63,12 +65,14 @@ class TextTemplateAPI < Grape::API
optional :data, type: Hash, desc: "Text template details"
end
put :predefined_text_template do
error!('401 Unauthorized', 401) unless Admin.exists?(id: current_user.id)
unless Admin.exists?(id: current_user.id) || current_user.global_text_template_editor
error!('401 Unauthorized', 401)
end

template = PredefinedTextTemplate.find_by(id: params["id"])
error!('404 Not found', 404) if template.nil?

template.update!(
error!(template.errors.full_messages.join(', '), 422) unless template.update(
name: params["name"] || "",
data: params["data"] || {}
)
Expand All @@ -81,16 +85,69 @@ class TextTemplateAPI < Grape::API
optional :data, type: Hash, desc: "Text template details"
end
post :predefined_text_template do
error!('401 Unauthorized', 401) unless Admin.exists?(current_user.id)
unless Admin.exists?(id: current_user.id) || current_user.global_text_template_editor
error!('401 Unauthorized', 401)
end

template = PredefinedTextTemplate.create(
template = PredefinedTextTemplate.new(
name: params["name"],
user_id: current_user.id,
data: params["data"] || {}
)
error!(template.errors.full_messages.join(', '), 422) unless template.save

present template, with: Entities::TextTemplateEntity
end

# Personal text templates
resource :personal do
desc 'Get all personal templates for current user'
get do
templates = PersonalTextTemplate.where(user_id: current_user.id).order(id: :desc)
present templates, with: Entities::TextTemplateEntity, root: :text_templates
end

desc 'Create a personal text template'
params do
requires :name, type: String, desc: 'Template name'
optional :data, type: Hash, desc: 'Template data'
end
post do
template = PersonalTextTemplate.new(
user_id: current_user.id,
name: params[:name],
data: params[:data] || {},
)
error!(template.errors.full_messages.join(', '), 422) unless template.save
present template, with: Entities::TextTemplateEntity
end

desc 'Update a personal text template'
params do
requires :id, type: Integer, desc: 'Template ID'
requires :name, type: String, desc: 'Template name'
optional :data, type: Hash, desc: 'Template data'
end
put ':id' do
template = PersonalTextTemplate.find_by(id: params[:id], user_id: current_user.id)
error!('404 Not found', 404) if template.nil?

error!(template.errors.full_messages.join(', '), 422) unless template.update(
name: params[:name],
data: params[:data] || template.data,
)
present template, with: Entities::TextTemplateEntity
end

desc 'Delete a personal text template'
delete ':id' do
template = PersonalTextTemplate.find_by(id: params[:id], user_id: current_user.id)
error!('404 Not found', 404) if template.nil?

template.destroy
present template, with: Entities::TextTemplateEntity
end
end
end
end
end
1 change: 1 addition & 0 deletions app/api/entities/user_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class UserEntity < Grape::Entity
expose :is_templates_moderator, documentation: { type: 'Boolean', desc: 'ketcherails template administrator' }
expose :molecule_editor, documentation: { type: 'Boolean', desc: 'molecule administrator' }
expose :converter_admin, documentation: { type: 'Boolean', desc: 'converter administrator' }
expose :global_text_template_editor, documentation: { type: 'Boolean', desc: 'global text template editor' }
expose :account_active, documentation: { type: 'Boolean', desc: 'User Account Active or Inactive' }
expose :matrix, documentation: { type: 'Integer', desc: "User's matrix" }
expose :counters
Expand Down
1 change: 1 addition & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var ScifinderCredential = require('src/apps/scifinderCredential');
var StructureEditorUserSetting = require('src/components/structureEditor/UserSetting');
var LoginOptions = require('src/apps/omniauthCredential/LoginOptions');
var ConverterAdmin = require('src/apps/converter/ConverterAdmin');
var MyTemplates = require('src/apps/myTemplates');
var GenericElementsAdmin = require('src/apps/generic/GenericElementsAdmin');
var GenericSegmentsAdmin = require('src/apps/generic/GenericSegmentsAdmin');
var GenericDatasetsAdmin = require('src/apps/generic/GenericDatasetsAdmin');
Expand Down
10 changes: 5 additions & 5 deletions app/javascript/src/apps/admin/AdminHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import GroupsDevices from 'src/apps/admin/GroupsDevices';
import MessagePublish from 'src/apps/admin/MessagePublish';
import OlsTerms from 'src/apps/admin/OlsTerms';
import MatrixManagement from 'src/apps/admin/MatrixManagement';
import TextTemplateContainer from 'src/apps/admin/textTemplates/TextTemplateContainer';
// import TextTemplateContainer from 'src/apps/admin/textTemplates/TextTemplateContainer';
import DelayedJobs from 'src/apps/admin/DelayedJobs';
import ChemSpectraLayouts from 'src/apps/admin/ChemSpectraLayouts';
import DevicesList from 'src/apps/admin/devices/DevicesList';
Expand All @@ -17,7 +17,7 @@ import ThirdPartyApp from 'src/apps/admin/ThirdPartyApp';

class AdminHome extends React.Component {
constructor(props) {
super();
super(props); // eslint-disable-line no-useless-constructor
this.state = {
pageIndex: 0,
};
Expand All @@ -39,7 +39,7 @@ class AdminHome extends React.Component {
case 4: return <GroupsDevices />;
case 5: return <OlsTerms />;
case 7: return <MatrixManagement />;
case 8: return <TextTemplateContainer />;
// case 8: return <TextTemplateContainer />; // Moved to My Templates page — accessible via navigation menu for all users
case 9: return <DevicesList />;
// case 12: return <TemplateManagement />;
case 13: return <DelayedJobs />;
Expand Down Expand Up @@ -69,9 +69,9 @@ class AdminHome extends React.Component {
<NavItem>
<Nav.Link eventKey={7}>UI features</Nav.Link>
</NavItem>
<NavItem>
{/* <NavItem>
<Nav.Link eventKey={8}>Text Templates</Nav.Link>
</NavItem>
</NavItem> */}{/* Moved to My Templates page — accessible via navigation menu for all users */}
<NavItem>
<Nav.Link eventKey={2}>Message Publish</Nav.Link>
</NavItem>
Expand Down
25 changes: 25 additions & 0 deletions app/javascript/src/apps/admin/UserManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ const moleculeModeratorDisableTooltip = (
Disable editing the representation of the global molecules for this user (currently enabled)
</Tooltip>
);
const globalTextTemplateEditorEnableTooltip = (
<Tooltip id="assign_button">
Enable editing global text templates for this user (currently disabled)
</Tooltip>
);
const globalTextTemplateEditorDisableTooltip = (
<Tooltip id="assign_button">
Disable editing global text templates for this user (currently enabled)
</Tooltip>
);
const accountActiveTooltip = (
<Tooltip id="assign_button">
This user account is deactivated, click to [activate]
Expand Down Expand Up @@ -340,6 +350,11 @@ export default class UserManagement extends React.Component {
this.updateProfile({ user_id: id, molecule_editor: !isMoleculesEditor }, message);
}

handleGlobalTextTemplateEditor(id, isGlobalTextTemplateEditor) {
const message = `Global text template editing has been ${isGlobalTextTemplateEditor === true ? 'dis' : 'en'}abled for user ${id}`;
this.updateProfile({ user_id: id, global_text_template_editor: !isGlobalTextTemplateEditor }, message);
}

handleActiveInActiveAccount(id, isActive) {
const message = `User ${id} account has been ${isActive === true ? 'de-' : ''}activated!`;
this.updateUser({ id, account_active: !isActive }, message);
Expand Down Expand Up @@ -1581,6 +1596,16 @@ export default class UserManagement extends React.Component {
<i className="icon-sample" aria-hidden="true" />
</Button>
</OverlayTrigger>
<OverlayTrigger placement="bottom" overlay={(g.global_text_template_editor === null || g.global_text_template_editor === false) ? globalTextTemplateEditorEnableTooltip : globalTextTemplateEditorDisableTooltip}>
<Button
size="sm"
variant={(g.global_text_template_editor === null || g.global_text_template_editor === false) ? 'light' : 'success'}
onClick={() => this.handleGlobalTextTemplateEditor(g.id, g.global_text_template_editor)}
className="me-1"
>
<i className="fa fa-file-text" aria-hidden="true" />
</Button>
</OverlayTrigger>
<OverlayTrigger
placement="bottom"
overlay={<Tooltip id="generic_tooltip">Grant/Revoke Generic Designer</Tooltip>}
Expand Down
Loading
Loading