How to change custom fields sql query on redmine - mysql

I use zapier to send sms to users when a new issue is created on Redmine.
I want to make it easy for users and sophisticated.
To do so; I've created a custom field on USER section which is named MOBILE. In Custom Fields menu, the user writes his/her phone number in this field.
I also created a custom field on ISSUES section. This custom field brings user list to ISSUES. User list custom field as you know is default redmine feature in ISSUES section for redmine 2.4.x.
So here is my question; I want user list custom field feature to bring user MOBILE numbers which I've created field on users accounts page. Current query brings name and surname and user to.
I checked apps-models-custom_field.rb however no luck. I couldn't find a solution.
I think inner join with custom_values table could solve my problem but I do not know how to do it, actually I don't know which file contains this queries for custom field user list.
Default user list feature of custom fields prints User firstname and lastname on ISSUES page also it just brings user id on the xml api.
So all I want to do is get user custom field content with their user id on the xml.
I hope I've made myself clear.
What are your suggestions?

You won't be able to find SQL queries in Redmine code as Redmine uses Rails' ActiveRecond framework to build SQL queries dynamically.
As I understand the query, you are looking for, should look like:
SELECT
login, firstname, lastname, value
FROM
users
LEFT JOIN
custom_values ON custom_values.customized_id = users.id
AND customized_type = 'Principal'
WHERE
custom_field_id = (SELECT id FROM custom_fields
WHERE type = 'UserCustomField'
AND name = 'MOBILE')
AND value IS NOT NULL
AND value != ''
Hope, this helps.

Related

Query MySQL database for user names with their email addresses

I'm looking for a way to query all of my users (simple enough) but i need to get specific users back in the results. I'll try explain the best i can below but in short i want to use a list of email addresses as a reference to pull all users matching those email addresses.
Brief overview
I have a wordpress website which i run events from. When people sign up for the events an account is created for them. there is also another table for attendees which links these user profiles to their registrations.
As it is right now i need to get a list of people specific to one event organiser. I thought the best way to do this would be to use their email address from the attendee info and query my wp_users table for the user names.
SELECT display_name
FROM `mydatabase`.`wp_users` WHERE `user_email` LIKE
'myemail#email.com' OR
'mysecondemail#email.com' OR
'mythirdemail#email.com';
I've removed the real email and changed the database name.
What i am trying to achieve is a query that will run through my list of users comparing their email address that i provide to the users in the table and return any of them that match.
As it is right now it returns the first result it finds and stops.
I've got the list of emails ready to go but i am struggling to get this to work.
You need to repeat the column name like this in the where clause
SELECT display_name
FROM `mydatabase`.`wp_users`
WHERE `user_email` = 'myemail#email.com'
OR `user_email` = 'mysecondemail#email.com'
OR `user_email` = 'mythirdemail#email.com'
or use IN()
SELECT display_name
FROM `mydatabase`.`wp_users`
WHERE `user_email` IN ('myemail#email.com', 'my2email#email.com', 'my3email#email.com')
And like is only used when searching with wildcards. For instance
where email like '%#mydomain.com'
so i managed to figure this out a few minutes after posting this.
I didnt fix the initial issue but i managed to find and create a relationship between the two sets of data in Power BI and get the list i needed.
Thanks though.
PhilB

SSRS - Users Table

I have done some digging but am unable to find out specific information about the Users table that is created in the ReportServer database?
Firstly I wanted to check what was the point of entry for users going into this table? In our table it looks like virtually ALL our domain logins exist in this table... Which leads me to the next question... Are these actually linked to the domain accounts at all (I presume not). I just want to make sure that if a domain account is disabled that any subscriptions 'Owned' by that user will not fail on the next run attempt.
Any help on this relatively dark area is greatly appreciated.
Regards
Chris
Before answering let me remind you that the SSRS database is not officially documented, so the following answers are only be based on my experience of the product so they can be wrong / incomplete.
what was the point of entry for users going into this table?
The GetUserIDBySid and GetUserIDByName stored procedures, called by the GetUserID stored procedure.
The GetPrincipalID stored procedure, called by the UpdatePolicyPrincipal stored procedure.
The name can be confusing, because in fact these SPs are not only getting the User ID.
If the user does not exist in the database, they insert it.
Now an additional question should come up:
When are these SPs executed?
The obvious answer is "when SSRS needs to get the User ID".
This can be, for example, when:
Creating a policy for that specific user
The user execute a report
The user schedules a subscription
If the user is part of a group that has access to a report and has never done any action needing to get his User ID, he should not be present in the Users table.
Are these actually linked to the domain accounts at all
No, if you delete the account from your AD it will stay in the Users table.
The information that you can use if you need to link them for whatever reason are:
The User Login: UserName
The Security ID: Sid
Bonus question/answer:
What information does the Users table contains?
UserID: A generated GUID (NEWID())
Sid: The Security ID, if you need to find the Security ID from the User Login, you can use the SUSER_SID function
UserType: The UserType
AuthType: The LoginType
UserName: The NT User / Group login
Here is an excerpt from an article:
Users: This table contains details about access details for users of the report server including those users running the reports and those users publishing the reports.
SSRS keeps its own table of users and groups associated with its security, so even if the user account has been deleted from your Active Directory system, it will be available for you to reference inside the ReportServer database
This query below will show you to which report each user has access to:
SELECT u.UserName, r.RoleName, c.Path, c.Name
FROM dbo.Users as u
INNER JOIN dbo.PolicyUserRole as pr ON u.UserID=pr.UserID
INNER JOIN dbo.Roles as r on pr.RoleID = r.RoleID
INNER JOIN dbo.Catalog as c on pr.PolicyID = c.PolicyID
ORDER BY u.UserName

Use current logged on user's information in query

I have a form (using formmaker plugin) that I record information to display to the user at a later time.
I'd like to be able to record/insert the current logged in user's id (call it user_login) so I can have something like WHERE wpuser_login = user_login as part of a query.
I was thinking that I could join the wp_users table and query using a 'view' but I'm not sure how I could do that. In the meantime I think I'm just oging to add a field for the user to input their user id themselves then join wp_users using the above WHERE clause. The only problem with that is that the user would have to have the correct username, otherwise display will not work.
How can I do this?

how to validate a private message recipient when a user atempt to send message to another user or users

I'm developing an application in which users can send private message to each other.
Assume that a user want to send a message to users David , jack, John. Something that is clear I must validate this recipients and check if they exist in the users table.
but I don't have a clear scenario to do this job.
Should I prepare a query like:
select user form users where user_name=David OR user_name=Jack OR user_name=John
Then if row count was 3 let the user send his message and if not drop the action?
This is pretty basic as far as SQL questions go, so you really need to get a better reference for that sort of thing.
The type of query you're looking for is:
SELECT id, user_name FROM users WHERE user_name IN ('David','Jack','John')
Presumably you have an id column of some kind.
Remember to have an INDEX on the user_name field if you're making queries on it.

how to set up different levels of access in a vb.net application based on an SQL table of Usernames?

I want to make different levels of access for a vb.net program i'm writing.
I have a database called "stratocast". I want to show a specific form for entries in this table with "IsManager" checked and another specific form for those with "IsAdmin" checked.
Im using MySql server and visual basic 2010 express
EDIT:
To clear up any misconceptions about my post, ill explain further:
In my vb.net application i have a login form with two textboxes; One for the username and one for password. I also have three other forms, one is called "frmAdmin", another called "frmManager" and another one called "frmEmployee".
On my database i have a table called "employee" with columns called "name", "title", "IsManager", "IsAdmin", "Username" and "Password".
IsManager and IsAdmin are both Boolean columns
This means that their values can only be 0 or 1 and the result is displayed as a checkbox.
When the employee logs into this applcation i want it to check whether or not the employee is a manager, an administrator, or just a regular employee with no additional rights. If the employee is a manager, i want to show "frmManager". If the employee is an Administrator i want to show "frmAdmin". And if the employee has no additional rights then i want to show "frmEmployee".
I'd like to keep the configuration for access level checking confined to the one table but if it's better to have separate tables for each level of access (ie: tables called Admin,Manager, and Employee) then ill consider that too.
thanks!
Quick Update:
http://www.vbmysql.com/articles/vbnet-mysql-tutorials/the-vbnet-mysql-tutorial-part-1
It seems you need a bit more information on how to work with databases, and how to ensure data integrity in a database. The above link is a 6 part series on working with Vb.NET and MySQL. I would suggest giving it a look over - it will answer most / all of your questions.
I'm a bit lost on what exactly you're trying to produce as an end result.
What I can see is you want to display a different form depending on if the employee is a manager or admin, and you probably want to display both of those forms if the employee is an Admin AND a manager.
So you have your SQL Query result. You don't need any logical if/then for that part as you're returning the data based on an employee ID (Please say you have a PK ID Field).
What I would do is have a group of controls that are hidden / visible depending on the permission of that employee.
Database Design;
Table: Employee
EmployeeID, int PK, not null
Name, varchar, null
Password, varchar, null
Title, varchar, null
IsManager, bit, null
IsAdmin, bit, null
**Are you using a Salt for your passwords / or any encryption? based on the pseudo code below I will do it as there is no encryption on the passwords, and let you deal with that.
You're databaes will have many employees in it. What you want to do is when one logs in is to check the username and the password field against your database.
Select EmployeeID, Name, Title, IsManager, IsAdmin FROM employee Where Name = 'UserName' and Password = 'Password
Where 'Username','Password' are your variables that need to be passed in.
example:
Select EmployeeID, Name, Title, IsManager, IsAdmin FROM employee Where Name = 'Ryan.Ternier' and Password = 'Trogdor'
This will return a user to you, with your IsAdmin and IsManager flags. If you have an Employee class, instantiate it, populate it, and return it to your presentation so it can do the forms (example below).
Public Sub SetForms(ByVal emp As Employee)
If emp.IsManager Then
Dim frm As New ManagerForm
frm.Show()
End If
If emp.IsAdmin Then
Dim frm As New AdminForm
frm.Show()
End If
Dim frm As New EmployeeForm
frm.Show()
End Sub
I would recommend getting that path done.
Login Form passes UserName/Password to your Login method, which returns an Employee.
If Employee is not null/nothing great, if it's null/nothing then the credentials are wrong.
Based on your answers i'd rather recommend learning basic concepts of Visual Basic,SQL,Logins and such.
Here's one of a the books which is quite good for learning for beginners on these concepts.
You'll get an overall image of how things are done.
The Book